pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tilman Hausherr <THaush...@t-online.de>
Subject Re: PDF pages to PNG files getting out of heap space
Date Sun, 13 Sep 2015 06:29:32 GMT
Am 13.09.2015 um 04:54 schrieb Troy Smith:
>> Hi,
>>
>> I'm trying to create an image for each page of a pdf.  I'm getting an out
>> of heap space error, usually when creating the image of the second page.
>> The code I'm using is below.  I may be doing something braindead, but I'm
>> not seeing it.  Any advice or thoughts?

I'm able to display it with -Xmx4g option in PDFDebugger. Your code may 
require even more, because you're also creating a 300dpi image.

Page 2 is huge. It has an image that has a size of almost 5MB compressed.

Tilman

>>
>> A link to a .pdf that produces this problem:
> https://www.dropbox.com/s/osw235wyvqp0kxi/test.pdf?dl=0
>
>
>> I'm using pdfbox-app-2.0.0-20150911.224202-1643.jar.
>>
>> Best regards,
>> Troy
>>
>>
>>
>> import java.awt.image.BufferedImage;
>> import java.io.File;
>> import java.util.ArrayList;
>> import java.util.List;
>>
>> import javax.imageio.ImageIO;
>>
>> import org.apache.pdfbox.pdmodel.PDDocument;
>> import org.apache.pdfbox.pdmodel.PDPage;
>> import org.apache.pdfbox.rendering.PDFRenderer;
>> import org.apache.pdfbox.rendering.ImageType;
>>
>>
>> public class ImageTest{
>> public static void main( String [] args ) throws Exception{
>>
>> String pdfFile = args[0];
>> PDDocument doc;
>> String imageDocPrefix = pdfFile.substring(0,pdfFile.length()-4);
>> File pdfF = new File(pdfFile);
>> BufferedImage bim;
>> String name;
>> File out;
>> try{
>> doc = PDDocument.load(pdfF);
>> PDFRenderer pdfRenderer = new PDFRenderer(doc);
>> for (int page = 0; page < doc.getNumberOfPages(); ++page){
>>
>> System.out.println("Testing..." + page);
>>     bim = pdfRenderer.renderImageWithDPI(page, 300, ImageType.RGB);
>> name = imageDocPrefix +"_"+ String.format("%04d",page) +".png";
>> out = new File(name);
>> ImageIO.write(bim, "PNG", out);
>>              }
>> doc.close();
>> }
>> catch(Exception e){
>> System.err.println("error writing images from pdf:" + pdfFile + ":" + e);
>> }
>> }
>> }
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message