Page 1 of 1

sizeRelH and sizeRelV Word 2007 compatibility

PostPosted: Thu Apr 27, 2017 2:42 am
by roded
Hi,
We're using docx4j 3.3.1 which introduced support for wp14:sizeRelH, wp14:sizeRelV.
These tags are apparently causing us issues with Word 2007 compatibility.
Is there a way to suppress these (and other Word 2010+) tags automatically?
Thanks

Re: sizeRelH and sizeRelV Word 2007 compatibility

PostPosted: Mon May 01, 2017 6:13 pm
by jason
mc:Ignorable is what you want to set. Its a comma separated list of namespace prefixes. For example:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<w:document mc:Ignorable="w14 w15 w16se wp14" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" >
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


Docx4j will/should ensure that each namespace in mc:Ignorable is properly declared (as it needs to be in order for Office to open the file), but if you add mc:Ignorable content, it is still generally up to you to set the mc:Ignorable attribute correctly. Exceptions are DocumentSettingsPart, where docx4j tries to set it correctly for you, and pptx where currently "v" is assumed.

What code is inserting wp14:sizeRelH, wp14:sizeRelV?

As a first test, assuming the issue is in your MainDocumentPart, try:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
getContents().setIgnorable("w14 w15 w16se wp14");
 
Parsed in 0.014 seconds, using GeSHi 1.0.8.4

Re: sizeRelH and sizeRelV Word 2007 compatibility

PostPosted: Sun May 07, 2017 9:45 pm
by roded
Hi Jason, thanks for your reply.
Regarding mc:Ignorable, I actually need to set this for the header and footer parts as well as the MainDocumentPart. And it seems like setMceIgnorable is not implemented in all parts?
In the mean time I set these properties' values to null which prevents docx4j from outputting them.
The sizeRelH/V attributes are added to a w:drawing's wp:anchor tag.

Re: sizeRelH and sizeRelV Word 2007 compatibility

PostPosted: Mon May 08, 2017 12:36 pm
by jason
In JaxbXmlPart, the methods which marshal to a Node and to an OutputStream both invoke setMceIgnorable.

That method needs to be suitably overridden in subclasses.

See further comments at https://github.com/plutext/docx4j/blob/ ... .java#L775

MainDocumentPart, HeaderPart and FooterPart all do this.

You still need to set the actual value in object corresponding to underlying XML. The setMceIgnorable method will then ensure the relevant namespace declarations are present.

roded wrote:The sizeRelH/V attributes are added to a w:drawing's wp:anchor tag.


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
                org.docx4j.dml.wordprocessingDrawing.ObjectFactory factory = new org.docx4j.dml.wordprocessingDrawing.ObjectFactory();
                System.out.println(XmlUtils.marshaltoString(factory.createAnchor(new Anchor())));
 
Parsed in 0.014 seconds, using GeSHi 1.0.8.4


gives:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<wp:anchor relativeHeight="0" behindDoc="false" locked="false" layoutInCell="false" allowOverlap="false" />
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


so creating an Anchor object is not enough to introduce the wp14 attributes.

And if you are reading a docx into docx4j which contains them, that should be ok.

Are you adding them perhaps by unmarshalling XML snippets which contain wp14 attributes?