[
https://issues.apache.org/jira/browse/PDFBOX-1748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13803982#comment-13803982
]
Andreas Lehmkühler commented on PDFBOX-1748:
--------------------------------------------
First of all pages are not COSDocuments and they don't close the scratchfile.
Your change simply drops the "problematic" code and therefore doesn't qualify
as workaround.
Kurts comment and the output messages lead to the following conclusions
- close is called more than once
- as the "closed" value is still "false", something went wrong when closing the
COSDocument the first time
- if the behaviour depends on the environment, than most likely PDFBox isn't
the problem
So the question is, do you swallow some exceptions when closing the PDDocument
instance?
> PDPage.convertToImage fails with IndexOutOfBoundsException: Index: 0, Size: 0
> -----------------------------------------------------------------------------
>
> Key: PDFBOX-1748
> URL: https://issues.apache.org/jira/browse/PDFBOX-1748
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 1.7.1, 1.8.2
> Reporter: Kurt M
> Attachments: PDFTest.java
>
>
> I am trying to create jpg images from pages in a pdf document. The following
> code works in most environments, but we recently installed on a new system
> and are experiencing a high rate of failure there. The same files that fail
> there work in other environments.
> Here is my code:
> PDDocument doc;
> try {
> RandomAccess scratchFile = new RandomAccessBuffer();
> doc = PDDocument.loadNonSeq( pdfFile, scratchFile );
> int pageNum = 0;
> int fullRes = 96;
> List<PDPage> pages = doc.getDocumentCatalog().getAllPages();
> BufferedImage fullImg;
> for( PDPage page : pages ) {
> pageNum++;
> fullImg = page.convertToImage( BufferedImage.TYPE_INT_RGB,
> fullRes );
> and here is the stack trace (this is from the 1.7.1 version I think):
> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
> at java.util.ArrayList.get(ArrayList.java:352)
> at
> org.apache.pdfbox.io.RandomAccessBuffer.seek(RandomAccessBuffer.java:84)
> at
> org.apache.pdfbox.io.RandomAccessFileInputStream.read(RandomAccessFileInputStream.java:96)
> at java.io.BufferedInputStream.read1(BufferedInputStream.java:267)
> at java.io.BufferedInputStream.read(BufferedInputStream.java:328)
> at java.io.BufferedInputStream.fill(BufferedInputStream.java:229)
> at java.io.BufferedInputStream.read(BufferedInputStream.java:248)
> at java.io.FilterInputStream.read(FilterInputStream.java:77)
> at java.io.PushbackInputStream.read(PushbackInputStream.java:133)
> at
> org.apache.pdfbox.io.PushBackInputStream.read(PushBackInputStream.java:91)
> at
> org.apache.pdfbox.pdfparser.BaseParser.skipSpaces(BaseParser.java:1547)
> at
> org.apache.pdfbox.pdfparser.PDFStreamParser.parseNextToken(PDFStreamParser.java:230)
> at
> org.apache.pdfbox.pdfparser.PDFStreamParser.access$000(PDFStreamParser.java:46)
> at
> org.apache.pdfbox.pdfparser.PDFStreamParser$1.tryNext(PDFStreamParser.java:182)
> at
> org.apache.pdfbox.pdfparser.PDFStreamParser$1.hasNext(PDFStreamParser.java:194)
> at
> org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:257)
> at
> org.apache.pdfbox.util.PDFStreamEngine.processSubStream(PDFStreamEngine.java:237)
> at
> org.apache.pdfbox.util.PDFStreamEngine.processStream(PDFStreamEngine.java:217)
> at org.apache.pdfbox.pdfviewer.PageDrawer.drawPage(PageDrawer.java:119)
> at org.apache.pdfbox.pdmodel.PDPage.convertToImage(PDPage.java:730)
> at generateSlideImages(PDFUtils.java:213) <-- my code
--
This message was sent by Atlassian JIRA
(v6.1#6144)