You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by sp...@gmx.eu on 2011/01/05 15:15:35 UTC
convertToImage -> OutOfMemoryError
Hello,
I convert bigger PDF files (100 pages, each page is a TIFF G4, 6 MB total)
into png-Files:
PDDocument doc = PDDocument.load(new File("big.pdf"));
PDDocumentCatalog catalog = doc.getDocumentCatalog();
List pages = catalog.getAllPages();
for(Object o : pages){
PDPage page = (PDPage)o;
BufferedImage image = page.convertToImage();//<= OOME
ImageIO.write(image, "png", file);
}
Do we have a bug here in PDFBox or is my code the problem?
Thank you!
P.S. I can comment out the line ImageIO.write(image, "png", file); doesn't
matter.
java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:41)
at java.awt.image.Raster.createPackedRaster(Raster.java:458)
at
java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorMo
del.java:1015)
at java.awt.image.BufferedImage.<init>(BufferedImage.java:321)
at
sun.java2d.loops.GraphicsPrimitive.convertFrom(GraphicsPrimitive.java:537)
at
sun.java2d.loops.GraphicsPrimitive.convertFrom(GraphicsPrimitive.java:521)
at sun.java2d.loops.MaskBlit$General.MaskBlit(MaskBlit.java:171)
at sun.java2d.loops.Blit$GeneralMaskBlit.Blit(Blit.java:186)
at sun.java2d.pipe.DrawImage.blitSurfaceData(DrawImage.java:927)
at sun.java2d.pipe.DrawImage.renderImageCopy(DrawImage.java:550)
at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:54)
at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:982)
at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:168)
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2988)
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2973)
at sun.java2d.pipe.DrawImage.makeBufferedImage(DrawImage.java:317)
at sun.java2d.pipe.DrawImage.renderImageXform(DrawImage.java:372)
at sun.java2d.pipe.DrawImage.transformImage(DrawImage.java:199)
at sun.java2d.pipe.DrawImage.transformImage(DrawImage.java:1053)
at
sun.java2d.pipe.ValidatePipe.transformImage(ValidatePipe.java:212)
at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:3110)
at
org.apache.pdfbox.pdfviewer.PageDrawer.drawImage(PageDrawer.java:385)
at
org.apache.pdfbox.util.operator.pagedrawer.Invoke.process(Invoke.java:117)
at
org.apache.pdfbox.util.PDFStreamEngine.processOperator(PDFStreamEngine.java:
529)
at
org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java
:274)
at
org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java
:251)
at
org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:22
5)
at
org.apache.pdfbox.pdfviewer.PageDrawer.drawPage(PageDrawer.java:107)
at org.apache.pdfbox.pdmodel.PDPage.convertToImage(PDPage.java:722)
at org.apache.pdfbox.pdmodel.PDPage.convertToImage(PDPage.java:693)
RE: convertToImage -> OutOfMemoryError
Posted by sp...@gmx.eu.
> >> PDDocument doc = PDDocument.load(new File("big.pdf"));
> >> PDDocumentCatalog catalog = doc.getDocumentCatalog();
> >> List pages = catalog.getAllPages();
> >> for(Object o : pages){
> >> PDPage page = (PDPage)o;
> >> BufferedImage image = page.convertToImage();//<= OOME
> >> ImageIO.write(image, "png", file);
> >> }
> >
> > OK, I got it. When the page is to big (e.g. really large
> images) then an
> > OMME is thrown.
> > Is there any possiblity to find out the approx. size of the
> page without
> > converting it into an image and catching the OOME?
> The final image size depends on the page size and the given
> resolution.
The Problem is that width and height seems to be always A4 (about 600x900
pixel) for any page in the document (via getWidth(), getHeight()).
The resolution is always 300 dpi.
But in real some images are 7000x10000 pixels.
> I guess the origin size of the tiffs is probably the show stopper.
Maybe, but how can I determine this size?
> If you are just interested in the images, try to extract them using
> ExtractImages, see [1] for further information.
No, not only images, text too.
Re: convertToImage -> OutOfMemoryError
Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,
Am 05.01.2011 18:25, schrieb spring@gmx.eu:
>> PDDocument doc = PDDocument.load(new File("big.pdf"));
>> PDDocumentCatalog catalog = doc.getDocumentCatalog();
>> List pages = catalog.getAllPages();
>> for(Object o : pages){
>> PDPage page = (PDPage)o;
>> BufferedImage image = page.convertToImage();//<= OOME
>> ImageIO.write(image, "png", file);
>> }
>
> OK, I got it. When the page is to big (e.g. really large images) then an
> OMME is thrown.
> Is there any possiblity to find out the approx. size of the page without
> converting it into an image and catching the OOME?
The final image size depends on the page size and the given resolution. I guess
the origin size of the tiffs is probably the show stopper.
If you are just interested in the images, try to extract them using
ExtractImages, see [1] for further information.
BR
Andreas Lehmkühler
http://svn.apache.org/repos/asf//pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/ExtractImages.java
RE: convertToImage -> OutOfMemoryError
Posted by sp...@gmx.eu.
> PDDocument doc = PDDocument.load(new File("big.pdf"));
> PDDocumentCatalog catalog = doc.getDocumentCatalog();
> List pages = catalog.getAllPages();
> for(Object o : pages){
> PDPage page = (PDPage)o;
> BufferedImage image = page.convertToImage();//<= OOME
> ImageIO.write(image, "png", file);
> }
OK, I got it. When the page is to big (e.g. really large images) then an
OMME is thrown.
Is there any possiblity to find out the approx. size of the page without
converting it into an image and catching the OOME?
Thank you