Question
Tata Consultancy Services
US
Last activity: 29 Sep 2017 3:30 EDT
How to find the number of pages in a pdf file from pyEForm object
Hi,
I have a requirement in which I need to determine the number of pages in the pdf document generated. We generate a pdf file and store it in pyEForm property and from this Object I need to find the number of pages in that pdf file. Is it possible to find the number of pages using pyEForm Object(using java code if needed)?
***Updated by moderator: Lochan to add Categories***
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Pegasystems Inc.
GB
Mahesh already linked the original Mesh Post describing one way of doing this (loading the ByteArray of the PDF into 'PDFBox' and using the API to get the page count).
I'll link the migrated version of the same here: https://collaborate.pega.com/question/pdf-page-count
Cheers !
John
Pegasystems Inc.
US
Hi Aravinth,
I dont think you can find the page count of the pdf file from the byte array which is stored in pyEForm property, but you need to find the Page count at the time of the PDF generation.
You can look into this discussion to find the Page count over here.
Hope this might be helpful to you.
Regards
Mahesh
Pegasystems Inc.
US
Hi Aravinth,
Also i found another way to get the count of the pages during the PDF generation.
- While calling the HTMLToPDF activity you can pass the non-autogenerated section name in pyPDFHeaderHTMLTemplate or pyPDFFooterHTMLTemplate.
- This non-autogenerated section will be called for each page during the generation of PDF file.
- Now you can write the java code to store the count by incrementing the count for each call to this section and store it in temporary page.
- Finally you can read the total count from this temporary page property.
Hope this approach might help you in achieving your requirement if above discussion couldn't help you.
Regards
Mahesh
Tata Consultancy Services
US
Actually we are not generating the pdf document. It was generated by entirely different team, hence why I asked a question on how to generate from pyEForm object itself. But your other reply helped me fix the issue, thanks
Pegasystems Inc.
US
Good to hear that your issue has been resolved with my earlier comment and thank you John for sharing the migrated version of the link.
Virtusa
US
Hi Mahesh ,
I have a requirement to add some text on PDF header which depends on the page number of the PDF, which are generated dynamically , Is there a way to capture page number/first page/last page of PDF as getNumberOfPages() of PDFbox will only get total no of pages
Pegasystems Inc.
US
Hello,
Based on the PDDocument engine api i have a suggestion for you to get the first and last pages of the PDF as follows:
Step1: Get the total pages count using the getNumberOfPages() method in PDDocument and store it in total
Step2: Now to get the first page use below code
PDPage firstPage = pdDoc.getPage(1);
Step3: Now to get the last page use below code,
PDPage firstPage = pdDoc.getPage(total);
May be you can try this way, fyi i had not tested this code and it is my idea to get the information of your requirement.
Kindly cross check the api code over here and make sure the page index starts from 0 or 1.
Hope this might help you to proceed further.
Regards
Mahesh
Virtusa
US
Thank You Mahesh , according to my requirement I have to add text in PDF header according to Page No, Where as using PDDocument api I have to extend Java code in HTML TO PDF, but I need to set before it get Processed via HTMLTO PDF (pyPDFHeaderHTMLTemplate -Param(Passing HTML Stream))
Pegasystems Inc.
IN
Hello
Trying passing : Param.footer as "Page ${page} in the activity HTMLtoPDF
You can refer this article as well :
https://pdn.pega.com/community/pega-product-support/question/need-page-numbers-pdf
@John any thoughts ?
Accepted Solution
Pegasystems Inc.
GB
Mahesh already linked the original Mesh Post describing one way of doing this (loading the ByteArray of the PDF into 'PDFBox' and using the API to get the page count).
I'll link the migrated version of the same here: https://collaborate.pega.com/question/pdf-page-count
Cheers !
John
Tata Consultancy Services
US
This actually fixed the issue. The link is what I exactly needed.
-
ALVIN JAISON