How to get Total page count from a Word Document

Hi,

Do we have any Pega activity to find out total page count in Word document uploaded without converting into PDF document.

Hi

There does not seem to be an OOTB activity. But you can definitely customize.

Have a look at the below discussion:

Regards

Bhavya

Please find the below article which might be helpful.

https://collaborate.pega.com/question/page-count-word-document

Hi Bhavya,

Thanks for your reply. Looks like, its given as we need to convert into PDF. which we dont required to convert to get only page count. I am looking for any java code on this.

Thanks,

Haripriya

Hi Pavan,

Thanks for your reply. Looks like, its given as we need to convert into PDF. which we dont required to convert to get only page count. I am looking for any java code on this.

Thanks,

Haripriya

I figured out the Java code. Here is the code:

String attachStream = tools.getParamValue(“Base64Stream”);
java.io.ByteArrayInputStream Infile = new java.io.ByteArrayInputStream(Base64Util.decodeToByteArray(attachStream));

try{
org.apache.poi.xwpf.usermodel.XWPFDocument doc= new org.apache.poi.xwpf.usermodel.XWPFDocument(Infile);

int pages = doc.getProperties().getExtendedProperties().getUnderlyingProperties().getPages();
tools.putParamValue(“PageCount”, pages);
}
catch(Exception ex){
oLog.error(ex);

}