Page 1 of 1

The total number of pages in the document, docx to pdf

PostPosted: Sat May 28, 2011 10:28 am
by alonsoair
I'm using docx4j to convert docx files to PDFs.

Page numbers in the footer are not being rendered correctly. I have the form: Page 'a' of 'b'.

Suppose I have a document with more than one page the result I get is:
[*]Page 1 of 1
[*]Page 2 of 2
[*]Page 3 of 3
but I want to display:
[*]Page 1 of 3
[*]Page 2 of 3
[*]Page 3 of 3

I'm using the org.docx4j.convert.out.pdf.viaXSLFO.Conversion converter
and the org.docx4j.samples.CreatePdf for test.

I suppose what happens is that Docx4j supports
<w:instrText xml:space="preserve"> PAGE \* Arabic </w:instrText>
but does not support
<w:instrText xml:space="preserve"> NUMPAGES \* Arabic </w:instrText>

Can you help me with this please?

Thanks

This is the footer xml:

Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<w:ftr mc:Ignorable="w14 wp14" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office"
       xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml"
       xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word"
       xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
       xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
       xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
       xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
       xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
       xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
       xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
  <w:p w:rsidP="007F459B" w:rsidR="007F459B" w:rsidRDefault="007F459B">
    <w:pPr>
      <w:pStyle w:val="Footer"/>
      <w:jc w:val="right"/>
    </w:pPr>
    <w:r>
      <w:rPr>
        <w:lang w:val="es-ES"/>
      </w:rPr>
      <w:t xml:space="preserve">Página </w:t>
    </w:r>
    <w:r w:rsidR="00C40CF5">
      <w:rPr>
        <w:lang w:val="es-ES"/>
      </w:rPr>
      <w:fldChar w:fldCharType="begin"/>
    </w:r>
    <w:r w:rsidR="00C40CF5">
      <w:rPr>
        <w:lang w:val="es-ES"/>
      </w:rPr>
      <w:instrText xml:space="preserve"> PAGE  \* Arabic </w:instrText>
    </w:r>
    <w:r w:rsidR="00C40CF5">
      <w:rPr>
        <w:lang w:val="es-ES"/>
      </w:rPr>
      <w:fldChar w:fldCharType="separate"/>
    </w:r>
    <w:r w:rsidR="00216BAA">
      <w:rPr>
        <w:noProof/>
        <w:lang w:val="es-ES"/>
      </w:rPr>
      <w:t>1</w:t>
    </w:r>
    <w:r w:rsidR="00C40CF5">
      <w:rPr>
        <w:lang w:val="es-ES"/>
      </w:rPr>
      <w:fldChar w:fldCharType="end"/>
    </w:r>
    <w:r>
      <w:rPr>
        <w:lang w:val="es-ES"/>
      </w:rPr>
      <w:t xml:space="preserve"> de </w:t>
    </w:r>
    <w:r w:rsidR="00C40CF5">
      <w:rPr>
        <w:lang w:val="es-ES"/>
      </w:rPr>
      <w:fldChar w:fldCharType="begin"/>
    </w:r>
    <w:r w:rsidR="00C40CF5">
      <w:rPr>
        <w:lang w:val="es-ES"/>
      </w:rPr>
      <w:instrText xml:space="preserve"> NUMPAGES  \* Arabic </w:instrText>
    </w:r>
    <w:r w:rsidR="00C40CF5">
      <w:rPr>
        <w:lang w:val="es-ES"/>
      </w:rPr>
      <w:fldChar w:fldCharType="separate"/>
    </w:r>
    <w:r w:rsidR="00216BAA">
      <w:rPr>
        <w:noProof/>
        <w:lang w:val="es-ES"/>
      </w:rPr>
      <w:t>1</w:t>
    </w:r>
    <w:r w:rsidR="00C40CF5">
      <w:rPr>
        <w:lang w:val="es-ES"/>
      </w:rPr>
      <w:fldChar w:fldCharType="end"/>
    </w:r>
  </w:p>
  <w:p w:rsidP="007E4D43" w:rsidR="007E4D43" w:rsidRDefault="007E4D43">
    <w:pPr>
      <w:pStyle w:val="Footer"/>
      <w:jc w:val="right"/>
    </w:pPr>
  </w:p>
</w:ftr>

Re: The total number of pages in the document, docx to pdf

PostPosted: Mon May 30, 2011 2:08 am
by jason
Right, we need to add support for NUMPAGES. The relevant place is in org.docx4j.convert.out.pdf.viaXSLFO.Conversion, methods createBlockForFldSimple and handleField.

See http://xmlgraphics.apache.org/fop/fo.ht ... otal-pages for the required XSL FO.

Fairly straightforward, I think. If you'd like to have a crack at doing this, I'd be happy to add it to docx4j :-)

cheers .. Jason

Re: The total number of pages in the document, docx to pdf

PostPosted: Tue May 31, 2011 4:57 am
by alonsoair
Thank you very much for quick response.

I will check the reference, when I get the expected result will be glad to share for the project.

Greetings.

Re: The total number of pages in the document, docx to pdf

PostPosted: Sat Nov 17, 2012 12:29 am
by jdallapi
Hello,

I encountered the same problem. Did you develop a fix for this issue?

Thanks.

Re: The total number of pages in the document, docx to pdf

PostPosted: Tue Nov 20, 2012 8:48 pm
by jdallapi
Hello,

Is someone can help me to correct this problem? I understand what to add in the XSL, but I don't find how to correct the problem in org.docx4j.convert.out.pdf.viaXSLFO.Conversion.

Thank you for your help.

Julien