0

im trying to get the first and last page label of my pdf file. but im currently having an issue when accessing a PDF File that starts with a page label of "1" it always returns a null pointer exception

pdfDocument = PDDocument.load(pdfFilePath);
        pageLabels = pdfDocument.getDocumentCatalog().getPageLabels();

        pdfl = pdfDocument.getDocumentCatalog().getPageLabels();
setfPage(Double.parseDouble(pdfl.getLabelsByPageIndices()[0]));
setlPage(Double.parseDouble(pdfl.getLabelsByPageIndices()pdfDocument.getNumberOfPages() - 1]));

it works fine on other pdf files that doesn't start with "1" as page label.

mj_nunez
  • 45
  • 1
  • 8
  • store the value of `pdfDocument.getNumberOfPages()` in a variable and try to debug the code to look what it return. – Vikrant Kashyap Apr 18 '16 at 08:34
  • @VikrantKashyap yes i did that by doing, System.out.println(pdfDocument.getNumberOfPages());... it returns the correct number of pages. – mj_nunez Apr 18 '16 at 08:41
  • which line gives you null pointer ? please check your line number in stackTrace. – Vikrant Kashyap Apr 18 '16 at 08:43
  • i did a work around where i manually set the page numbering style of the 1st page to NONE, and just manually set the fpage as 1. – mj_nunez Apr 18 '16 at 08:47
  • @VikrantKashyap this line gives the null pointer setfPage(Double.parseDouble(pdfl.getLabelsByPageIndices()[0])); – mj_nunez Apr 18 '16 at 08:49
  • it means `pdfl.getLabelsByPageIndices()` method reflects a null as a String Array `String[]`. – Vikrant Kashyap Apr 18 '16 at 08:53
  • @VikrantKashyap i know, but it shouldn't i defined the page labels correctly, but when i change the 1st page numbering style to NONE, it gives me an Array String[] but the index 0 is empty, thats why i just manually set its value to 1. – mj_nunez Apr 18 '16 at 09:02

0 Answers0