Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0.26
-
None
-
Ubuntu 20.04.4 LTS
Java OpenJDK 11.0.12-open
Description
I use the PDFRenderer in my application and noticed that the renderImageWithDPI method throws an EOFException with certain PDF files like the one in the attachment.
My code:
private void pdfToImage(final Path pdfFile, final Path destImageFile) throws IOException, UnrecoverableConversionErrorException { try (final PDDocument document = PDDocument.load(pdfFile.toFile(), MemoryUsageSetting.setupTempFileOnly())) { disableImageCache(document); final PDFRenderer pdfRenderer = new PDFRenderer(document); final BufferedImage bim = pdfRenderer.renderImageWithDPI(0, 300, ImageType.RGB); ImageIOUtil.writeImage(bim, destImageFile.toAbsolutePath().toString(), 300); } catch (final RasterFormatException | NegativeArraySizeException e) { throw new UnrecoverableConversionErrorException(e); } }
Exception thrown:
java.io.EOFException
at org.apache.fontbox.ttf.MemoryTTFDataStream.readUnsignedShort(MemoryTTFDataStream.java:120)
at org.apache.fontbox.ttf.TTFDataStream.readUnsignedShortArray(TTFDataStream.java:192)
at org.apache.fontbox.ttf.GlyfSimpleDescript.<init>(GlyfSimpleDescript.java:78)
at org.apache.fontbox.ttf.GlyphData.initData(GlyphData.java:60)
at org.apache.fontbox.ttf.GlyphTable.getGlyphData(GlyphTable.java:212)
at org.apache.fontbox.ttf.GlyphTable.getGlyph(GlyphTable.java:191)
at org.apache.pdfbox.pdmodel.font.PDCIDFontType2.getPath(PDCIDFontType2.java:421)
at org.apache.pdfbox.pdmodel.font.PDType0Font.getPath(PDType0Font.java:625)
at org.apache.pdfbox.rendering.TTFGlyph2D.getPathForGID(TTFGlyph2D.java:144)
at org.apache.pdfbox.rendering.TTFGlyph2D.getPathForCharacterCode(TTFGlyph2D.java:93)
at org.apache.pdfbox.rendering.PageDrawer.drawGlyph2D(PageDrawer.java:511)
at org.apache.pdfbox.rendering.PageDrawer.showFontGlyph(PageDrawer.java:492)
at org.apache.pdfbox.contentstream.PDFStreamEngine.showGlyph(PDFStreamEngine.java:820)
at org.apache.pdfbox.contentstream.PDFStreamEngine.showGlyph(PDFStreamEngine.java:838)
at org.apache.pdfbox.contentstream.PDFStreamEngine.showText(PDFStreamEngine.java:776)
at org.apache.pdfbox.contentstream.PDFStreamEngine.showTextString(PDFStreamEngine.java:635)
at org.apache.pdfbox.contentstream.operator.text.ShowText.process(ShowText.java:56)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:966)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:541)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:516)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:155)
at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:279)
at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:355)
at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:272)
at org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:258)
at com.converter.PdfConverter.pdfToImage(PdfConverter.java:41)