pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Troy Smith <troydsm...@gmail.com>
Subject Re: PDF pages to PNG files getting out of heap space
Date Sun, 13 Sep 2015 02:54:07 GMT
>
> 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?
>
> 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);
> }
> }
> }
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message