I am trying to add a "Page X of Y" footer to the bottom of a text document.  I got everything working *EXCEPT* the font size.

I wrote this code:

        // Adds Page X of Y to the footer
        Font fontsmaller = new Font("Arial", StyleTypeDefinitions.FontStyle.REGULAR, 8);
        Footer footer = doc.getFooter();
        Section footersection = footer.appendSection("Page Numbers");
        Paragraph footerparagraph = footersection.addParagraph("Page\u00A0");
        footerparagraph.setFont(fontsmaller); // Doesn't work here either
Fields.createCurrentPageNumberField(footerparagraph.getOdfElement());
        footerparagraph.appendTextContent("\u00A0of\u00A0");
Fields.createPageCountField(footerparagraph.getOdfElement());
        footerparagraph.setFont(fontsmaller); // Doesn't work here either

It seems to work EXCEPT the part of changing the font size.  In Word, the font ends up being the default size of 12.  (Works as expected in LibreOffice.)

Interesting, counterexample.  It works when I set the font larger, like 16, but it doesn't work when I set the font smaller, like 10 or 8.

I performed a diff comparison on the output form odftoolkit(-) and the output from Word(+).  It seems the key difference is lines like these in styles.xml:

-    <style:style style:family="paragraph" style:name="a2b0e5e">
-      <style:paragraph-properties fo:text-align="center" style:line-break="strict" style:punctuation-wrap="hanging" style:text-autospace="ideograph-alpha" style:writing-mode="page"/> -      <style:text-properties fo:color="#000000" fo:country="US" fo:font-size="10.0pt" fo:language="en" style:font-name="Courier New" style:font-name-asian="Lucida Sans Unicode" style:font-name-complex="Tahoma"
style:font-size-asian="12pt" style:font-size-complex="12pt"/>
+    <style:style style:name="P2" style:parent-style-name="Normal" style:family="paragraph">
+      <style:paragraph-properties fo:text-align="center"/>
+      <style:text-properties style:font-name="Courier New"/>
+    </style:style>
+    <style:style style:name="T3" style:parent-style-name="DefaultParagraphFont" style:family="text"> +      <style:text-properties style:font-name="Courier New" fo:color="#FF0000" fo:font-size="8pt" style:font-size-asian="8pt" style:font-size-complex="8pt"/>
+    </style:style>
+    <style:style style:name="T4" style:parent-style-name="DefaultParagraphFont" style:family="text"> +      <style:text-properties style:font-name="Courier New" fo:color="#FF0000" fo:font-size="8pt" style:font-size-asian="8pt" style:font-size-complex="8pt"/>
+    </style:style>
+    <style:style style:name="T5" style:parent-style-name="DefaultParagraphFont" style:family="text"> +      <style:text-properties style:font-name="Courier New" fo:color="#FF0000" fo:font-size="8pt" style:font-size-asian="8pt" style:font-size-complex="8pt"/>
+    </style:style>
+    <style:style style:name="T6" style:parent-style-name="DefaultParagraphFont" style:family="text"> +      <style:text-properties style:font-name="Courier New" fo:color="#FF0000" fo:font-size="8pt" style:font-size-asian="8pt" style:font-size-complex="8pt"/>
     </style:style>


-      <style:footer>
-        <text:section text:display="true" text:name="Page Numbers" text:style-name="aec74e3"> -          <text:p text:style-name="a32e835">Page <text:span><text:page-number style:num-format="" text:select-page="current"/> of </text:span><text:span><text:page-count style:num-format=""/></text:span></text:p>
-        </text:section>
-      </style:footer>

+      <style:footer>
+        <text:p text:style-name="Normal">
+          <text:span text:style-name="T3">Page </text:span>
+          <text:span text:style-name="T4">
+            <text:page-number text:fixed="false">1</text:page-number>
+          </text:span>
+          <text:span text:style-name="T5"> of </text:span>
+          <text:span text:style-name="T6">
+            <text:page-count>14</text:page-count>
+          </text:span>
+        </text:p>
+      </style:footer>

Unfortunately, I don't know what code I should write to force odftoolkit to generate appropriate styles and text properties fields.

Could someone please help me figure this one out?

Thanks.

Joseph D. Wagner

Reply via email to