Page 1 of 1

How to get total number of generated pages?

PostPosted: Wed Feb 26, 2020 8:27 pm
by hatdo45
I am adding some text, tables, images dynamically and generating a docx, how can find the total number of pages of that generated docx as i need to mention in the first page.

Re: How to get total number of generated pages?

PostPosted: Wed Feb 26, 2020 9:38 pm
by hatdo45
I found it out myself.
docx.getDocPropsExtendedPart().getJaxbElement().getPages();

Re: How to get total number of generated pages?

PostPosted: Thu Feb 27, 2020 6:42 am
by jason
That value is not automatically/dynamically updated.

But if the docx will be opened in Word, you could use the NUMPAGES field: http://webapp.docx4java.org/OnlineDemo/ ... PAGES.html

Re: How to get total number of generated pages?

PostPosted: Fri Feb 28, 2020 9:15 pm
by hatdo45
jason wrote:That value is not automatically/dynamically updated.

But if the docx will be opened in Word, you could use the NUMPAGES field: http://webapp.docx4java.org/OnlineDemo/ ... PAGES.html


You are right, page number is not updated for dynamically generated docx.
Yes, that generated docx will be opened in Word only, but how can i programmatically get this NUMPAGES field to read the updated/final total page number?