Hi,
I am working on a web application. we have a scenario where we need to display thumbnails of pdf documents.
Here is the code:
Document pdfDocument = new Document(url);
// Create stream object to save the output image
ByteArrayOutputStream imageOutputStream = new ByteArrayOutputStream();
// Create Resolution object
Resolution resolution = new Resolution(10);
// Create BmpDevice object with particular resolution
BmpDevice bmpDevice = new BmpDevice(resolution);
// Convert a particular page and save the image to stream
bmpDevice.process(pdfDocument.getPages().get_Item(pageNo+1), imageOutputStream);
byte[] pageImage = imageOutputStream.toByteArray();
String pageImageBase64String = Base64.getEncoder().encodeToString(pageImage);
// Close the stream
imageOutputStream.close();
imageOutputStream.flush();
pdfDocument.close();
pdfDocument.dispose();
this returns base64 string to UI.
I am getting out of memory, java heap out of memory exception every time I deal with this particular service. it doesn’t matter what pdf I use it gives OOM. I need to generate thumbnails on fly. please suggest some API to generate Thumbnails without having OOM issues.