I have numerous PDF files that cause OOM exceptions. I am trying to generate images from the PDF using the following code:
public static void main( String[] args ) {
String fileName = "test.pdf";
if ( args.length > 0 ) {
fileName = args[0];
}
File pdfFile = new File( fileName );
Document doc = null;
InputStream in = null;
try {
in = new FileInputStream( pdfFile );
doc = new Document( in );
com.aspose.pdf.facades.PdfConverter converter = new com.aspose.pdf.facades.PdfConverter();
converter.bindPdf( doc );
converter.setStartPage( 1 );
//converter.setEndPage( doc.getPages().size() );
int pageNum = 1;
while ( converter.hasNextImage() ) {
System.out.println( "Generating slides for page " + pageNum );
Page page = doc.getPages().get_Item( pageNum );
System.out.println( "Got Page element for page " + pageNum );
String fullFileName = "full_" + pageNum + ".png";
OutputStream fullStream = new FileOutputStream( fullFileName );
System.out.println( "Calling getNextImage" );
converter.getNextImage( fullStream, ImageType.getPng() ); //jpg", ImageType.getJpeg() , 100, 150, 100);
System.out.println( "Returned from calling getNextImage" );
pageNum++;
}
} catch ( FileNotFoundException e ) {
e.printStackTrace();
}
}
Java version is 1.8. Environment is Linux/64 and Windows Server 2016. I have tried changing the Xmx setting to 6GB which helped in some cases, but not enough.
Strangely, I have a mac where this runs without any additional settings and is able to convert the pdfs. Also 1.8.