Dmitri Russu created PDFBOX-3574: ------------------------------------ Summary: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space Key: PDFBOX-3574 URL: https://issues.apache.org/jira/browse/PDFBOX-3574 Project: PDFBox Issue Type: Bug Components: Parsing, Utilities Affects Versions: 2.0.3 Environment: Ubuntu 15.10 Reporter: Dmitri Russu Fix For: 2.0.4
Code I run is public static void testExtractImages() throws Exception { File resource = new File("test/t1_edited.pdf"); PDDocument document = PDDocument.load(resource); int page = 1; for (final PDPage pdPage : document.getPages()) { final int currentPage = page; PDFGraphicsStreamEngine pdfGraphicsStreamEngine = new PDFGraphicsStreamEngine(pdPage) { int index = 0; @Override public void drawImage(PDImage pdImage) throws IOException { if (pdImage instanceof PDImageXObject) { PDImageXObject image = (PDImageXObject)pdImage; File file = new File("test/", String.format("10948-new-engine-%s-%s.%s", currentPage, index, image.getSuffix())); ImageIOUtil.writeImage(image.getImage(), image.getSuffix(), new FileOutputStream(file)); index++; } } @Override public void appendRectangle(Point2D p0, Point2D p1, Point2D p2, Point2D p3) throws IOException { } @Override public void clip(int windingRule) throws IOException { } @Override public void moveTo(float x, float y) throws IOException { } @Override public void lineTo(float x, float y) throws IOException { } @Override public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) throws IOException { } @Override public Point2D getCurrentPoint() throws IOException { return null; } @Override public void closePath() throws IOException { } @Override public void endPath() throws IOException { } @Override public void strokePath() throws IOException { } @Override public void fillPath(int windingRule) throws IOException { } @Override public void fillAndStrokePath(int windingRule) throws IOException { } @Override public void shadingFill(COSName shadingName) throws IOException { } }; pdfGraphicsStreamEngine.processPage(pdPage); page++; } } Error received: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:3230) at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:113) at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93) at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:140) at org.apache.pdfbox.filter.FlateFilter.decompress(FlateFilter.java:125) at org.apache.pdfbox.filter.FlateFilter.decode(FlateFilter.java:64) at org.apache.pdfbox.cos.COSInputStream.create(COSInputStream.java:69) at org.apache.pdfbox.cos.COSStream.createInputStream(COSStream.java:162) at org.apache.pdfbox.pdmodel.common.PDStream.createInputStream(PDStream.java:235) at org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.<init>(PDImageXObject.java:147) at org.apache.pdfbox.pdmodel.graphics.PDXObject.createXObject(PDXObject.java:70) at org.apache.pdfbox.pdmodel.PDResources.getXObject(PDResources.java:409) at org.apache.pdfbox.contentstream.operator.graphics.DrawObject.process(DrawObject.java:53) at org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:815) at org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:472) at org.apache.pdfbox.contentstream.PDFStreamEngine.processTransparencyGroup(PDFStreamEngine.java:213) at org.apache.pdfbox.contentstream.PDFStreamEngine.showTransparencyGroup(PDFStreamEngine.java:162) at org.apache.pdfbox.contentstream.operator.graphics.DrawObject.process(DrawObject.java:66) at org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:815) at org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:472) at org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:446) at org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:149) at org.natemiller.pdfextractor.Application.testExtractImages(Application.java:118) at org.natemiller.pdfextractor.Application.main(Application.java:34) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) -- This message was sent by Atlassian JIRA (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org