File Locks on change merge document

File Locks on change merge document

Forum member · Feb 15, 2013
This code works (VB.NET): Dim NewPDFDoc As MergeDocument = New MergeDocument(source) NewPDFDoc.Draw(dest) This code creates file lock on the source file: Dim NewPDFDoc As MergeDocument = New MergeDocument(source) NewPDFDoc.FormFlattening = FormFlatteningOptions.Default NewPDFDoc.Draw(Dest) Anytime I make a change to NewPDFDoc object it creates a lock on the file. Any suggestions?

Re: File Locks on change merge document

Support · Feb 18, 2013
Hello, You can read the input PDF document in the form of stream and close the stream by reading all the PDF data into byte array. You can use overloaded PdfDocument class constructor which takes PDF byte array as argument and then merge the PdfDocument object using MergeDocument class. This will work for you. Below is the sample code for it. Dim streamData As New FileStream("C:\fw9AcroForm_03.pdf", FileMode.Open) Dim byteData As Byte() = New Byte(streamData.Length) {} streamData.Read(byteData, 0, CInt(streamData.Length)) streamData.Close() Dim pdf As New PdfDocument(byteData) Dim document As New MergeDocument(pdf) document.Form.Fields("f1-1").Value = "DynamicPDF" document.FormFlattening = FormFlatteningOptions.Default document.Draw("C:\Output.pdf") Thanks, ceTe Software Support Team.

Re: File Locks on change merge document

Forum member · Feb 19, 2013
Sorry, this method did not work. There is still a file lock on the source file.

Re: File Locks on change merge document

Support · Feb 19, 2013
Hello, The DynamicPDF API releases all the resources once it is drawn to disk. The above code which we posted will release the file once the stream object is closed and our API takes and uses the PDF byte data and there is nothing in our API which is locking the source file. Please make sure that any other process in your system is using this file and making this is file to be locked for the further process. If you continue getting the similar behavior then please send over sample project to our [^a|mailto:support@cete.com|opennewwindow|support ^] team using which they can recreate the behavior. Please note that it is difficult to troubleshoot the behavior until it is recreated on our end. Thanks, ceTe Software Support Team.

Re: File Locks on change merge document

Forum member · Feb 26, 2013
I am seeing a similar situation. We have a situation where we generate PDFs from multiple sources. For example, a user can request a department phone book (that comes from a query) be combined with a course catalog PDF that the user provides. Our code creates the new PDF document and adds the various pieces. After creation, we email the new PDF to the user. That part all works fine. After the new PDF is emailed, we clean up...which includes deleting the user provided PDF's. When we try to delete them, it generates an exception that says the file is still being used by another process. I get a similar error if I try to manually delete the file in windows explorer. I can delete the new PDF...but not the one that was imported. If multiple PDF's were imported, they are all locked until the entire application terminates. I don't think it's relevant, but I should mention that this is a console application. The code in question was working fine under version 5 of Dynamic PDF. This problem only started when I upgraded to version 7.

Re: File Locks on change merge document

Support · Feb 26, 2013
Hello, We have tested the scenario you have described using v7 dll and we are able to delete the source files after they are imported and before the console application is terminated. Please email the test application (along with it source code) in which you are able to reproduce this scenario to us at [^a|mailto:support@cete.com|opennewwindow|support@cete.com^] so we can run the test application and recreate the issue. Thanks, ceTe Software Support Team.

Re: File Locks on change merge document

Forum member · Feb 26, 2013
I have an update for the issue I had posted. It appears that, if the import takes place within a class, and the class maintains a reference to the page object that was imported using the ImportedPage constructor...then the lock on the file is maintained as long as the object reference is maintained. Apparently, that was not the case with version 5. Changing the code to import from a document that was loaded using the PDFDocument constructor has resolved the issue. And it's probably more efficient as it won't need to access the file for each page.

Re: File Locks on change merge document

Support · Feb 26, 2013
Hello, Yes, using PdfDocument object is recommended when importing existing PDF for merging and/or further modification. The PdfDocument object is built to handle the resources in an efficient manner. Thanks, ceTe Software Support Team.