Hi,
I am using Aspose 9.3.0 and I have seen a lot of Memory issues with Aspose. If my output pdf file is more than 100 MB, I get heap space errors. Currently I have configured 1 gb memory for jvm. In my application I can have files as big as 1 GB. I wanted to confirm if Aspose can even support that. below is the code which takes the maximum memory and time.
All the above code is called in a loop since we have a map of bytearrays, and each of these byte array has mutiple pdf pages.
ByteArrayInputStream dataStream = new ByteArrayInputStream(bytes);
//This gives me the pdf pages in the bytearray which will be merged in one document.
com.aspose.pdf.Document dc = new com.aspose.pdf.Document(dataStream);
//If the bytearray has 1000 pdf pages the below line of code takes a long time
finalDocument.getPages().add(dc.getPages());
//After this we use the following code to add Header and Footer
for(int i=startingIndex; i<= finalDocument.getPages().size(); i++)
{
double yIntend = finalDocument.getPages().get_Item(i).getPageRect(false).getHeight()-20;
//Create Header
com.aspose.pdf.TextBuilder textHeaderBuilder = new com.aspose.pdf.TextBuilder(finalDocument.getPages().get_Item(i));
// append the text fragment to the PDF page.Yintend is for positioning in the pdf page.
textHeaderBuilder.appendText(createPageHeader(“Header text”, yIntend));
//Create Footer
com.aspose.pdf.TextBuilder textBuilder = new com.aspose.pdf.TextBuilder(finalDocument.getPages().get_Item(i));
// append the text fragment to the PDF page
textBuilder.appendText(createPageFooter(“Footer Text”, i));
}
}
//After this we call the code for adding Bookmarks and create TOC at the end. Even if I do not add TOC the above code takes upto 1 GB for a 50MB file.
Can you please guide me if I am doing something wrong or is there a w ay to lower the memory consumption. Earlier we were using itext, we have just migrated to Aspose and we are facing this huge memory issue.
Regards,
Rajeev Mathur
Hi Rajeev,
…<o:p></o:p>
…<o:p></o:p>
pdfDocument.close();<o:p></o:p>
textAbsorber = null;<o:p></o:p>
com.aspose.pdf.MemoryCleaner.clear();<o:p></o:p>
System.gc();<o:p></o:p>
Please feel free to contact us for any further assistance.
Best Regards,
Hi,
By adding com.aspose.pdf.memoryCleaner.clear() statement to the existing code, it slows down 4 times the original time. If it takes 30 seconds to save a 50MB file, after adding the code it takes more than 4 minutes.
Adding the MemoryCleaner does not help when the output file is more than 200 MB, it throws Heap Space error. Does loading a com.aspose.pdf.Document object from bytearray much slower than loading it from file system. Please let mme know if the flow of the above code is wrong and if that is causing huge memory consumption. Since I will need to generate files more than 1GB.
Regards,
Rajeev Mathur
Hi Rajeev,
com.aspose.pdf.Document finalDocument = new com.aspose.pdf.Document(“c:/pdftest/TExtFile_TexttoPDF.pdf”);<o:p></o:p>
// ByteArrayInputStream dataStream = new ByteArrayInputStream(bytes);
//This gives me the pdf pages in the bytearray which will be merged in one document.
com.aspose.pdf.Document dc = new com.aspose.pdf.Document("c:/pdftest/XPSConversionTest.pdf");
//If the bytearray has 1000 pdf pages the below line of code takes a long time
finalDocument.getPages().add(dc.getPages());
com.aspose.pdf.MemoryCleaner.clear();
//After this we use the following code to add Header and Footer
for (int i = 1; i <= finalDocument.getPages().size(); i++)
{
double yIntend = finalDocument.getPages().get_Item(i).getPageRect(false).getHeight() - 20;
//Create Header
com.aspose.pdf.TextBuilder textHeaderBuilder = new com.aspose.pdf.TextBuilder(finalDocument.getPages().get_Item(i));
// append the text fragment to the PDF page.Yintend is for positioning in the pdf page.
textHeaderBuilder.appendText(new com.aspose.pdf.TextFragment("Header text"));
//Create Footer
com.aspose.pdf.TextBuilder textBuilder = new com.aspose.pdf.TextBuilder(finalDocument.getPages().get_Item(i));
// append the text fragment to the PDF page
textBuilder.appendText(new com.aspose.pdf.TextFragment("Header text"));
}
finalDocument.save(“c:/pdftest/TextStampIssue.pdf”);