You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by popoviciu mariana <ma...@yahoo.com> on 2011/05/23 16:38:55 UTC
PDFBOX- NullPointerException
Hi,
I am using pdf box for parsing pdf documents and lately I used the newest version of your jar file 1.5.0.
Here is my code snippet:
public static byte[] parsePDF (byte[] document) throws IOException
PDDocument doc = null;
try {
doc = PDDocument.load(new ByteArrayInputStream(document));
if (doc == null) {
throw new IllegalStateException("Cannot load the pdf document!");
}
PDDocumentCatalog catalog = doc.getDocumentCatalog();
if (catalog == null) {
return document;
}
...
} finally {
if (doc != null) {
doc.close();
}
}
.....
}
and I got this exception on the call doc.getDocumentCatalog() :
java.lang.NullPointerException
at org.apache.pdfbox.pdmodel.PDDocument.getDocumentCatalog(PDDocument.java:419)
I have attached also the pdf that is creating problems!
Do you have any idea which is the problem?
Thank you,
Mariana Didu
Re: PDFBOX- NullPointerException
Posted by Andreas Lehmkuehler <an...@lehmi.de>.
Hi,
Am 23.05.2011 16:38, schrieb popoviciu mariana:
> Hi,
>
> I am using pdf box for parsing pdf documents and lately I used the newest version of your jar file 1.5.0.
> Here is my code snippet:
>
> public static byte[] parsePDF (byte[] document) throws IOException
>
> PDDocument doc = null;
>
> try {
> doc = PDDocument.load(new ByteArrayInputStream(document));
> if (doc == null) {
> throw new IllegalStateException("Cannot load the pdf document!");
> }
>
> PDDocumentCatalog catalog = doc.getDocumentCatalog();
> if (catalog == null) {
> return document;
> }
>
> ...
>
>
> } finally {
> if (doc != null) {
> doc.close();
> }
> }
>
> .....
>
> }
>
> and I got this exception on the call doc.getDocumentCatalog() :
>
>
> java.lang.NullPointerException
> at org.apache.pdfbox.pdmodel.PDDocument.getDocumentCatalog(PDDocument.java:419)
>
> I have attached also the pdf that is creating problems!
> Do you have any idea which is the problem?
Your attachment didn't make it due to some restrictions to the mailing list. So,
without having a hand on the pdf I can only guess what's possibly wrong.
Maybe the document is encrypted and you have to decrypt it at first.
Check PDDocument#isEncrypted and if the pdf is encrypted use PDDocument#decrypt
to decrypt the document.
> Thank you,
> Mariana Didu
BR
Andreas Lehmkühler