Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
2.0.32, 3.0.3 PDFBox
Description
When rendering page one of the attached PDF the image does not render.
In the logs, I see the following:
2024-09-24 13:25:56:924 [main] WARN COSParser - The end of the stream doesn't point to the correct offset, using workaround to read the stream, stream start position: 196, length: 0, expected end position: 196 2024-09-24 13:25:56:930 [main] WARN PDFStreamEngine - Image stream is empty java.io.IOException: Image stream is empty at org.apache.pdfbox.pdmodel.graphics.image.SampledImageReader.getRGBImage(SampledImageReader.java:182) at org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.getImage(PDImageXObject.java:477) at org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.getImage(PDImageXObject.java:438) at org.apache.pdfbox.rendering.PageDrawer.drawImage(PageDrawer.java:1107)
I assume this is a bad PDF, but Acrobat, Chrome, etc., display it without an issue.
Here's the render code used:
File out = File.createTempFile("test-", ".png"); PDDocument pdDocument = Loader.loadPDF(pdf); final PDFRenderer pdfRenderer = new PDFRenderer(pdDocument); ImageIO.write(pdfRenderer.renderImageWithDPI(0, 300), "png", out);