Thanks. The document was created with the Simple API. So what are the implications? Bug in Simple API, ODFDOM, or the java I wrote that called the Simple API?
Joseph D. Wagner -- Sent from my Android device. -------- Original Message -------- From: Svante Schubert <svante.schub...@gmail.com> Sent: January 13, 2018 2:37:21 AM PST To: "Joseph D. Wagner" <j...@josephdwagner.info> Cc: odf-dev@incubator.apache.org Subject: Re: Trouble with Footer Font Size - Adding Page X of Y to Footer Hello Joseph, first step is usually to check for validation problems. There is a free online validator from The Document Foundation, which is using our Apache ODF Toolkit project (incubating) Validator with their own logo (which is fine, as they are paying the server bill). You 'broken' document - you had called "works in libreoffice - not in word.odt" document is also invalid at various points, (the working one has 'only' the common version attribute problem, which is a known and long story). The broken document shows the following errors works in libreoffice - not in word.odt/styles.xml[2,3901]: Error: element "style:text-properties" was found where no element may occur ties fo:country="US" fo:language="en"/></style:default-style><style:default-sty ----^ works in libreoffice - not in word.odt/styles.xml[2,4079]: Error: element "style:text-properties" was found where no element may occur ties fo:country="US" fo:language="en"/></style:default-style><style:style style ----^ works in libreoffice - not in word.odt/styles.xml[2,90333]: Error: tag name "style:header" is not allowed. Possible tag names are: <a>,<animate>,<animateColor>,<animateMotion>,<animateTransform>,<audio>,<caption>,<circle>,<command>,<connector>,<control>,<custom-shape>,<ellipse>,<footer-left>,<forms>,<frame>,<g>,<iterate>,<layer-set>,<line>,<measure>,<notes>,<page-thumbnail>,<par>,<path>,<polygon>,<polyline>,<rect>,<regular-polygon>,<scene>,<seq>,<set>,<transitionFilter> t:section></style:footer><style:header><text:section text:display="true" text:n ----^ works in libreoffice - not in word.odt/styles.xml: Info: 3 errors, no warnings As this is not very helpful as everything is in a single 2nd line, I have loaded the document into JEdit opening the styles.xml using the JEdit archive extension and doing an indent using the Jedit XML extension and saving the new file into the ZIP with Jedit back again. Now it is easier to find within a text editor: works in libreoffice - not in word.odt/styles.xml[25,61]: Error: element "style:text-properties" was found where no element may occur <style:text-properties fo:country="US" fo:language="en"/> ----^ works in libreoffice - not in word.odt/styles.xml[29,61]: Error: element "style:text-properties" was found where no element may occur <style:text-properties fo:country="US" fo:language="en"/> ----^ works in libreoffice - not in word.odt/styles.xml[1082,18]: Error: tag name "style:header" is not allowed. Possible tag names are: <a>,<animate>,<animateColor>,<animateMotion>,<animateTransform>,<audio>,<caption>,<circle>,<command>,<connector>,<control>,<custom-shape>,<ellipse>,<footer-left>,<forms>,<frame>,<g>,<iterate>,<layer-set>,<line>,<measure>,<notes>,<page-thumbnail>,<par>,<path>,<polygon>,<polyline>,<rect>,<regular-polygon>,<scene>,<seq>,<set>,<transitionFilter> The first two problem is only about text properties within a table and paragraph style, where they are not allowed. What application created this document? We should file an issue. :) To check if kind of problem, you may look into the specification <http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html> or the ODF XML grammar <http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-schema.rng>. You may find all required specification files among http://docs.oasis-open.org/office/v1.2/os/ The third is the problem interesting to us, see http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#element-style_master-page Unfortunately, the spec does not show the order of elements, therefore you need to look into the ODF XML RelaxNG grammar. Within http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-schema.rng you search for the element name (with ending quotation as there are some longer names with this as prefix) style:master-page" and find: <define name="style-master-page"> <element name="style:master-page"> <ref name="style-master-page-attlist"/> <optional> <ref name="style-header"/> <optional> <ref name="style-header-left"/> </optional> </optional> <optional> <ref name="style-footer"/> <optional> <ref name="style-footer-left"/> </optional> </optional> Voila, first the header than the footer in strict order. See relaxng.org/tutorial.html In the file is it the other way around. Switch the elements and you may succeed! :) Have a nice week-end, Svante ᐧ 2018-01-13 3:49 GMT+01:00 Joseph D. Wagner <j...@josephdwagner.info>: > Thank you for your generous offer to help. > > The "works in libreoffice - not in word" file is the direct output from > your library. > > The "works in both libreoffice and word" file is the output of when I take > that file, fix it in word, and then save it again. (Oddly, word does > something with the footer margin, and reopening this file in libreoffice > reveals that the last line of the main area is cutoff by the footer. > However, I'm hoping to ignore this.) > > I am using Word 2016. > > Thanks for all your time and effort. > > Joseph D. Wagner > > > -----Original Message----- > From: Svante Schubert [mailto:svante.schub...@gmail.com] > Sent: Tuesday, January 9, 2018 1:50 AM > To: odf-dev@incubator.apache.org > Subject: Re: Trouble with Footer Font Size - Adding Page X of Y to Footer > > Hello Joeseph, > > the first interesting thing to mention from ODF perspective is that the > text of a footer and header is part of the page style within the styles.xml. > Therefore any automatic styles being used for header and footer are not > within the content.xml, but styles.xml - and only those. > Let us not discuss the pro and con of this design, let me simply state, > that I am not a fan of it of the overall result :) > > In your example, it seems that the LibreOffice styles are not connecting > to each other, ie. a32e835 at the paragraph and a2b0e5e at the paragraph > style should be the same string, but this might be as well a copy paste > error from different files. > To alter the ODF styles, you might want to go a level deeper into the > ODFDOM project <http://incubator.apache.org/odftoolkit/odfdom/ > ProjectOverview.html>. > Again take a look at the regression tests, where to find the desired > elements. > > In general, every XML element has a generated DOM class with the prefix > local name and either Attribute or Element suffix, for instance, > TextSpanElement class. > > Hope it helps! > > Cheers, > Svante > ᐧ > > 2018-01-09 3:32 GMT+01:00 Joseph D. Wagner <j...@josephdwagner.info>: > > > 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("Pa > > ge\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="Tahom a" > > 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"/> o f > > </text:span><text:span><text:page-count style:num-format=""/></text:sp > > an></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 > > > > >