Pregunta

I got a word file and I want to count how many pages are in it.

The file has been created with Docx4Java.

Anyone did this before?

Thanks!

¿Fue útil?

Solución

docx4j doesn't have a page layout model, so it can't tell you a page count.

You can get an approximate page count by using FOP's page layout model. docx4j's PDF output now supports a "2 pass" generation:

  • first pass calculates the page count(s)
  • second pass generates the pdf

See https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/convert/out/fo/AbstractPlaceholderLookup.java and https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/convert/out/fo/ApacheFORenderer.java

So doing the first pass would give you (approximately) what you want. This uses org.apache.fop.apps.FormattingResults which records the number of pages in a page sequence, or in the document as a whole.

An alternative approach might be to use LibreOffice/OpenOffice (or Microsoft Word, for that matter).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top