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 <[email protected]>:

> 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: [email protected]
> For additional commands, e-mail: [email protected]
>

Reply via email to