[
https://issues.apache.org/jira/browse/PDFBOX-1748?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13803484#comment-13803484
]
Kurt M commented on PDFBOX-1748:
--------------------------------
We call close on PDdocument when we're through with it and I do not think that
this is the problem. On the contrary, I think that there may be an overzealous
use of close here. Correct me if I'm wrong, but the pages themselves are
COSDocument objects which have a reference to the PDDocument's scratchfile
object and they close this in when their finalizer is called.
I changed the finalizer in COSDocument line #582 to be if( false ) instead of
if ( !closed ) and this resolved the problem. I monitored the file handles of
my process and did not see any signs of leaks. I am using the 1.8.3 trunk.
> 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)