Page 1 of 1

read correct number of pages of docx

PostPosted: Tue Feb 03, 2009 2:40 pm
by fiorenzo
Hi to all,
is it possible to read the number of pages for a generated docx document?

When I use a template to generate docx, the number of pages is written in docProps/app.xml
( ie: <Pages>4</Pages> )

But I think it doesn't get updated if I attach new content to the document.

Is it possible to update this information in the generated docx??

Thank's in advance

Fiorenzo

Re: read correct number of pages of docx

PostPosted: Wed Feb 04, 2009 2:26 am
by jason
Hello Fiorenzo

It is possible to read and write that value.

org/docx4j/samples/DocProps.java shows how to manipulate the properties.

However, docx4j can't tell you what the value should be; to do so would require it to have a model of how words/images are rendered on a page, which it doesn't have. Maybe the easiest way to get an approximation would be to create a PDF (which docx4j can do), and then ask how long the PDF is. I haven't looked to see how easily pdf-renderer for example could tell you this.

cheers

Jason

Re: read correct number of pages of docx

PostPosted: Wed Feb 04, 2009 3:50 pm
by fiorenzo
Hi Jason,
for my application, i must to transform docx to pdf .
With Itext it' s simple to count number of pages:
Code: Select all
PdfReader reader = new PdfReader(pdf[f]);
                    reader.consolidateNamedDestinations();
                    // we retrieve the total number of pages
                    int n = reader.getNumberOfPages();


I tested your example for transform docx to pdf: the result is not very good.
The generated PDF document doesn't resemble the original DOCX one
I'm finding a solution more precise...i tested http://www.batchwork.com/en/doc2pdf/index.htm (only for windows..but the final result is good!! at limit with wine...)

bye bye

Fiorenzo

Re: read correct number of pages of docx

PostPosted: Thu Feb 05, 2009 9:29 am
by jason
I tested your example for transform docx to pdf: the result is not very good.
The generated PDF document doesn't resemble the original DOCX one


Hi Fiorenzo

What are the problems with the result? (Could you send me your docx so I can see?)

The PDF output is currently generated from HTML output. Hence its quality depends on the quality of the HTML.

I take it you are using docx4j 2.1.0 or later? In 2.1.0, the HTML output is created using the XSLT from the OpenXMLViewer project.

I would like it if docx4j could also generate PDF using iText directly, but haven't gotten around to doing this. Contributions welcome...

cheers

Jason

Re: read correct number of pages of docx

PostPosted: Thu Feb 05, 2009 11:33 am
by fiorenzo
Hi Jason,

I take it you are using docx4j 2.1.0 or later? In 2.1.0, the HTML output is created using the XSLT from the OpenXMLViewer project.

I compiled svn code! I'm going to test pdf conversion with new docx version.

The PDF output is currently generated from HTML output


I'm testing html to pdf with https://xhtmlrenderer.dev.java.net.
If the converter inside docx4j converts correctly, the game is over...

Contributions welcome...

I'm ready... I can share my code (jsf/ejb3 for docx generation) and if you want I can support you.. It could be my first collaboration to an open project..

bye bye

Fiorenzo

Re: read correct number of pages of docx

PostPosted: Fri Feb 06, 2009 11:19 pm
by jason
I'm ready... I can share my code (jsf/ejb3 for docx generation) and if you want I can support you.. It could be my first collaboration to an open project..


Hello Fiorenzo

Sounds very interesting; would you mind explaining a little more fully what your code does?

cheers

Jason