You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Siddharth Naik <si...@softaid.in> on 2018/03/22 14:07:54 UTC
Null Pointer Exception for (PdfBox) on
pdfStripper.getText(document)
Hello,
I am using PDFBox v2.0.8
I am getting java.lang.NullPointerException for few PDF documents, when I
use ' pdfStripper.getText(document)'. But this works well for few PDF
documents.
Please find below the related code for reference.
/*Code*/
File file = new File("E:/Temcat.pdf");
PDDocument document = PDDocument.load(file);
PDFTextStripper pdfStripper = new PDFTextStripper();
int pages = document.getNumberOfPages();
for(int i=1; i<=pages; i++){
pdfStripper.setStartPage(i);
pdfStripper.setEndPage(i);
try {
text = pdfStripper.getText(document);
System.out.println(text);
} catch (Exception e) {
e.printStackTrace();
}
}
Also, please find attached the Stack Trace.
Kindly let me know where this is going wrong.
Help will be appreciated.
Thanks,
Siddharth Naik
Re: Null Pointer Exception for (PdfBox) on pdfStripper.getText(document)
Posted by Attila Kiss <ki...@gmail.com>.
Hi,
Try this:
for(int i=0; i<pages; i++){
As I know, the page indicies starts from zero like an array.
Hope it helps!
Attila
2018-03-22 15:07 GMT+01:00 Siddharth Naik <si...@softaid.in>:
> Hello,
>
> I am using PDFBox v2.0.8
> I am getting java.lang.NullPointerException for few PDF documents, when I
> use ' pdfStripper.getText(document)'. But this works well for few PDF
> documents.
>
> Please find below the related code for reference.
>
> /*Code*/
> File file = new File("E:/Temcat.pdf");
> PDDocument document = PDDocument.load(file);
> PDFTextStripper pdfStripper = new PDFTextStripper();
> int pages = document.getNumberOfPages();
> for(int i=1; i<=pages; i++){
> pdfStripper.setStartPage(i);
> pdfStripper.setEndPage(i);
> try {
> text = pdfStripper.getText(document);
> System.out.println(text);
> } catch (Exception e) {
> e.printStackTrace();
> }
> }
>
> Also, please find attached the Stack Trace.
>
> Kindly let me know where this is going wrong.
> Help will be appreciated.
>
> Thanks,
> Siddharth Naik
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>