HTML2PDF not releasing file lock

108 views
Skip to first unread message

Caleb Hanson

unread,
May 28, 2014, 4:50:02 PM5/28/14
to pdfne...@googlegroups.com
I'm attempting to use the HMTL2PDF component to convert a HTML page to a PDF document. My issue happens when I have already created the PDF document and then attempt to save over it or even delete the file and save a new copy.

This is what I have right now. I am guessing I am missing a Close() or Dispose() or something but I can't figure it out.


Dim strFile As String = ConfigurationManager.AppSettings("PDFStorage") & Session("DistrictID").ToString() & "\" & "PDF" & Request.QueryString("DataID") & ".pdf"
Try
Try

If File.Exists(strFile) Then
File.Delete(strFile)
End If
Catch ex As Exception

End Try
PDFNet.Initialize(ConfigurationManager.AppSettings("PDFNetKey"))

Dim url As String = Request.Url.ToString.Replace("Saved", "GeneratePDF")

Using doc As PDFDoc = New PDFDoc()

Try
HTML2PDF.SetModulePath(ConfigurationManager.AppSettings("PDFStorage"))
If (HTML2PDF.Convert(doc, url & "&DistrictID=" & Session("DistrictID").ToString() & "")) Then
doc.Save(strFile, SDFDoc.SaveOptions.e_linearized)

End If

Catch ex As Exception

Finally
doc.Unlock()
doc.Close()
doc.Dispose()
End Try
End Using
PDFNet.Terminate()
Catch ex As Exception

End Try

Ryan

unread,
May 28, 2014, 7:45:47 PM5/28/14
to pdfne...@googlegroups.com
Hi Caleb,

I don't see anything wrong with the code.

You are saying that
doc.Save(strFile, SDFDoc.SaveOptions.e_linearized)
fails on the second, plus, call to this code? Are the subsequent calls during the same process lifetime?

Can you reproduce the issue by modifying the HTML2PDFTest vb sample?

Since you are using the static HTML2PDF::Convert method then all objects related to HTML2PDF conversion have already been released.

You can contact support at pdftron.com and attach any files.

thanks,
Ryan

Caleb Hanson

unread,
May 29, 2014, 11:09:49 AM5/29/14
to pdfne...@googlegroups.com
Same process lifetime. Specifically if you submit a page, the PDF is generated, the person hits the back button, and submits again.

Caleb Hanson

unread,
May 29, 2014, 11:46:35 AM5/29/14
to pdfne...@googlegroups.com
Ah, it wasn't the HTML2PDF component! It was related to attaching the file to a MailMessage further down the page.

On Wednesday, May 28, 2014 6:45:47 PM UTC-5, Ryan wrote:
Reply all
Reply to author
Forward
0 new messages