For few PDF’s our application which converts PDF’s to JPEGs is throwing the Java Out Of Memory issue.When we investigated these PDF’s are of size 14-15 MB and some pages are very rich graphics/colors.
Our application just get stuck during conversion with below exception -
java.lang.OutOfMemoryError: Java heap space
Is there any outstanding issue or limitation of ASPOSE. ( Any existing issue ).
Please suggest, how we can resolve and avoid this issue.
@chandrakant.bagewadi,
Please, can you attach one of those PDFs, the code snippet you are using for conversion too?
So far, I don’t think there is a limitation that I know of,
Maybe there is a bug. That’s why I am asking for all the information I can get to replicate the problem.
If that happens, I will create a ticket for the dev team.
Thanks in advance for taking the time to answer my questions.
Hi ,
-
Attached is the PDF Sample file and it is failing at Page#11.
-
Below is Code Snippet which we use for conversion, We are using DPI flow.
private void applyPDFConversion(Document pdfDocument, String[] requestData, int pageCount,
String asposeResultFileName) throws IOException {
OutputStream imageStream = new FileOutputStream(asposeResultFileName);
// Create Resolution object
Resolution resolution;
// Create JpegDevice object with particular resolution
JpegDevice jpegDevice;
// Get aspose conversion flow
AsposeConversionMode resolutionMode = AsposeConversionMode.valueOf(config.getAsposeConversionMode());
// ******* Use DPI flow *******
if (resolutionMode == AsposeConversionMode.DPI) {
resolution = new Resolution(config.getAsposeDpiValue());
jpegDevice = new JpegDevice(resolution);
} else if (resolutionMode == AsposeConversionMode.DIMENSION) {
// ******* Use DIMENSION Flow *******
int fixedWidth = config.getAsposeFixedWidth();
int heightCalculated = calculateHeight(fixedWidth,
Double.parseDouble(requestData[4]),
Double.parseDouble(requestData[5]));
resolution = new Resolution(fixedWidth, heightCalculated);
jpegDevice = new JpegDevice(fixedWidth, heightCalculated, resolution);
} else {
jpegDevice = new JpegDevice();
}
// Convert a particular page and save the image to stream
jpegDevice.process(pdfDocument.getPages().get_Item(pageCount), imageStream);
// Close the stream
imageStream.close();
log.info("iteration {}, ASPOSE conversion process for image \"{}\" completed. Starting resizing flow.",
pageCount, asposeResultFileName);
}
Hi As file size is 14.7 MB unable to attach, could you please share your Email ID, I will share the file.
Hi Carlos Molina,
Unable to attach the large file to the Topic, Please refer the attached
Thanks
Chandrakant
4117313-q1_2023_peak_session_37.pdf.zip (11 MB)
@chandrakant.bagewadi,
Same answer as the other post. You need to include everything used in the code in order for me to try to replicate.
I used the same code I used in the other post. The one from the documentation and it worked fine.
The issue may be in your functions that are calling because if we just loop all the pages and convert them using a JpgDevice, there seems to be not problem.
Also it may be something you are not disposing correctly. I see you have methods outside the the snippet that are been called. For me those are blackboxes so I removed them. And the conversion works. Try to do the same. Then add your code little by little and you will probably find something is getting referenced outside of the snippet presented here that is preventing the objects to be properly disposed.