1
votes

I am using Apache PDFBox for rendering thumbnails of PDF documents. Therefore I load the PDF and use the first page as thumbnail. The problem is, that for a particular document, it seems, it is not loaded correctly. For all other docs, it works like expected.

ByteArrayInputStream is = new ByteArrayInputStream(pdfData);

PDDocument pdf = PDDocument.load(is, true);

List<PDPage> pages = pdf.getDocumentCatalog().getAllPages(); //pages is empty here

The pdf file has 238 pages and is around 6,5 MB of size.

1
try loadNonSeq(is,null) - does it work then? - Tilman Hausherr
thanks, loadNonSeq works. As I didn't find any documentation, do you know, if there is a significant performance impact, if loadNonSeq is used instead of load? - Wolfgang Herr
Could be. issues.apache.org/jira/browse/PDFBOX-2860 However the nonSeq parser is the correct one. The old one no longer exists in the 2.0 version. However the most time is spent in rendering, not parsing (depending on the size of images). - Tilman Hausherr
OK, thanks, then I will go with loadNonSeq and observe the performance. - Wolfgang Herr
I've added an answer so that the question isn't an orphan. - Tilman Hausherr

1 Answers

0
votes

Assuming that you're using an 1.8.* version, please use the non sequential parser:

PDDocument pdf = PDDocument.loadNonSeq(is, null);

The non sequential parser is successful in certain cases where the old parser fails, e.g. for PDFs that have had revisions (example). Another advantage is that no extra code is needed for "protected" PDFs that are encrypted with the empty password.