Question
Verizon
IN
Last activity: 23 Sep 2019 8:41 EDT
PDFBox getNumberOfPages always returns 0
Hi All,
I'm trying to get the total number of pages on the PDF using the PDFBox API(PDDocument). But, on using this method(getNumberOfPages), it always returns 0. Can anyone help me on this issue?. Thanks in advance.
Please find the below code snippet that I'm using.
try{
org.apache.pdfbox.pdmodel.PDDocument doc = new org.apache.pdfbox.pdmodel.PDDocument();
java.io.InputStream instream=new java.io.ByteArrayInputStream( new com.pega.pegarules.pub.util.Base64Util().decodeToByteArray(FileContent));
doc.load(instream);
oLog.error("No. of pages in document"+ doc.getNumberOfPages());
}catch(Exception e){
}
Hi,
Could you please try the below code snippet in your java step and see whether you are getting the desired count:
Hi,
Could you please try the below code snippet in your java step and see whether you are getting the desired count:
byte[] byteArray=(byte[])tools.getParameterPage().getParameterValue("PDFDocument");
java.io.ByteArrayInputStream bis=null;
bis = new java.io.ByteArrayInputStream(byteArray);
try {
com.pega.apache.pdfbox.pdmodel.PDDocument doc=com.pega.apache.pdfbox.pdmodel.PDDocument.load( bis );
oLog.infoForced( "Page Count:" + doc.getNumberOfPages() );
}
catch(Exception e) { throw new PRRuntimeException(e);}
}
Thanks