We are planning on using the Merger product to take AcroForms, fill them in with data from our database, and then present these forms to our user via a WWW servlet.
What is the best way to ensure that memory is properly cleaned up? Given that some of our PDFs are very large, if there is a way to give a hint to the DynamicPDF code to let it know that it can release memory (ala; file.close() we'd like to use that.
Thanks for any help!
Nate
Resource cleanup
Re: Resource cleanup
Support · Oct 2, 2007Hello Nate,
You can load the PDF document in FileInputStream object and then store the stream into the byte array. Close the stream and pass the byte array to the PdfDocument object. Then pass the PdfDocument object to the MergeDocument object. Then you can perform the form filling.
Following is the sample Java code:
File f = new File("DocumentA.pdf");
int filesize = (int) f.length(); // Figure out the file size
buffer = new byte[filesize]; // Create an array that is big enough
// Create a stream to read the file
DataInputStream in = new DataInputStream(new FileInputStream(f));
in.readFully(buffer); // Read file contents into array
in.close();
PdfDocument pDoc = new PdfDocument(buffer);
MergeDocument document = new MergeDocument(pDoc);
document.getForm().getFields().getFormField("Test").setValue("Hello world");
document.draw("AcroFormFiller.pdf");
Thanks,
ceTe Software Support Team
Re: Resource cleanup
Forum member · Oct 2, 2007We're actually doing something very similar (using input streams) already, so in this case we're doing well. Is there any additional method calls we need to do once the PDF has been streamed out after using draw to allow the system to GC the memory.
Nate
ps. It appears that I posted to the wrong group, thanks for catching that and realizing I'm using the Java product. ;-)
Re: Resource cleanup
Support · Oct 2, 2007Hello Nate,
There are no additional methods to be called in order to perform GC. The resources are released by our product immediately after the PDF document is merged and drawn.
Thanks,
ceTe Software Support Team.