HTML2PDF not releasing file lock

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

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

Same process lifetime. Specifically if you submit a page, the PDF is generated, the person hits the back button, and submits again.

Ah, it wasn’t the HTML2PDF component! It was related to attaching the file to a MailMessage further down the page.