Save As and Close PDF

Hi,
I'm using Essential PDF 6.2.0.32, ASP.NET and VB.

I am tying to open an existing PDF, "stamp" it with text, then save the document to disk as a new document. I almost have this working but the starting document won't close properly. I have to wait several minutes before trying to repeat the process.

Here is my simplified VB:
Dim filename As String = Server.MapPath("certs/cert_template.pdf")
Dim ldoc As PdfLoadedDocument = New PdfLoadedDocument(filename)
Dim output As String = Server.MapPath("certs/unique_name.pdf")
ldoc.Save(output)
ldoc.Close()

This works fine the first time. If I fire the code a second time I receive the error "The process cannot access the file '......\cert_template.pdf' because it is being used by another process."

It appears that ldoc.Close() is not working properly.

Any idea how to fully close the PDF?
Thanks


4 Replies

JH Joe Hakooz April 24, 2008 08:00 PM UTC

Ok, I found a hacktastic solution. I'd still appreciate a reply from the pros since my solution can't possibly be best practice... and it appears that "pdfLoadedDocument.close()" doesn't work.

Instead of loading a file string, I'm loading a Stream. Then I use ASP.NET code to close the Stream when done. Here is my updated code:

Dim filename As Stream = New FileStream(Server.MapPath("certs/cert_template.pdf"), FileMode.Open)
Dim ldoc As PdfLoadedDocument = New PdfLoadedDocument(filename)
Dim output As String = Server.MapPath("certs/unique_name.pdf")
ldoc.Save(output)
ldoc.Close() ' Not sure that this does anything
filename.Close() ' This one works

Hope this helps



BP Bhuvaneswari P Syncfusion Team April 25, 2008 07:14 AM UTC

Hi Joe,

Thank you for your interest in Syncfusion products.

I can able to reproduce the issue. The issue mentioned here is suspected to be a defect and we have sent this to our development team for more analysis. We will update you once we get back from our development team.

Untill the issue fixed, please use the stream option.

Thank you for your patience.

Regards,
Bhuvana



BP Bhuvaneswari P Syncfusion Team April 28, 2008 09:18 AM UTC

Hi Joe,

Use the below overload which will release all the objects.

ldoc.Close(true);

Please let me know if you need any further assistance.

Regards,
Bhuvana



JH Joe Hakooz April 28, 2008 03:49 PM UTC

Hmmm... Thought I tried that but guess not.
It works!

Thanks for your help.


Loader.
Up arrow icon