Closed maddin79 closed 2 months ago
w:label is not supported in https://github.com/plutext/docx4j/blob/VERSION_11_4_12/docx4j-openxml-objects/src/main/java/org/docx4j/wml/SdtPr.java
You could add it in there manually, and in https://github.com/plutext/docx4j/blob/VERSION_11_4_12/docx4j-openxml-objects/src/main/java/org/docx4j/wml/ObjectFactory.java
(Normally we'd do that by providing for it in the xsd, then regenerating the code using xjc, but manually editing works fine as well)
Or if w:label serves no purpose, you could remove it from your document using https://github.com/plutext/docx4j/blob/VERSION_11_4_12/docx4j-samples-resources/src/main/resources/custom-preprocessor.xslt
docx4j uses ECMA-376, first edition (as opposed to 2ed, which was not then available) plus various amendments. It seems that label is defined in §17.5.2.19 of [ISO/IEC 29500-1 1st Edition] according to https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.sdtproperties?view=openxml-3.0.1 but afaik Microsoft Word doesn't write it.
Hello @plutext,
thank you very much for the hints. The label field has indeed no purpose for me. I don't know why OnlyOffice adds it. I create the fields with an plugin and the API of OnlyOffice. The weird thing is, if I add a field into a table, the label is not there, but the code for the field is the same.
I check out the preprocessor. Looks promising.
I added in src/main/java/resources the docx4j.properties and the custom-preprocessor.xslt in my maven project. But I looks like they are not taken into account. I also can not find documentation about this feature nor how to customize the preprocessor. How does it work and how do I remove the field from the document?
Do you have a line like https://github.com/plutext/docx4j/blob/VERSION_11_4_12/docx4j-core/pom.xml#L192 in your pom.xml
To your custom-preprocessor.xslt you need to add the line:
<xsl:template match="w:label" />
If the mechanism is working, it will be invoked from https://github.com/plutext/docx4j/blob/VERSION_11_4_12/docx4j-core/src/main/java/org/docx4j/openpackaging/parts/JaxbXmlPartXPathAware.java#L574
Hi @plutext,
I added the resource line and I also had the w:label in the xslt. But the ouput does not change. I run this with Intellij and also build an executable jar with all dependencies. The xslt is not taking into account at all. No idea what I'm doing wrong.
Seems like you have logging configured; so you have some resources being read? Configure it for INFO level logging; do you see the log at line 574 above? If you still can't get it working, you could create a small test case maven project and I will look at it for you.
Sorry for the late reply. I did some debugging and found the setting
String transformParts = Docx4jProperties.getProperty("docx4j.jaxb.preprocess.always");
boolean transformFirst = (transformParts!=null
&& transformParts.contains(this.getClass().getSimpleName()));
and put
docx4j.jaxb.preprocess.always=MainDocumentPart
in the docx4j.properties. Works perfectly. I did not find the root cause why the xslt is not taken into account, when the unmarshaling fails.
Thanks for the help. For me it is fixed. I think to preprocess the file always is in my case better anyway. The documents will always come from OnlyOffice.
Hello everyone,
I hope someone can help me with this issue. I can not find any solution to it.
OnlyOffice version: 8.1.0.169 Java version: JDK 21.0.2 docx4j-JAXB-MOXy version: 11.4.11 (The error is the same with other docx4j jaxb implementations)
I'm creating a docx document with OnlyOffice that contains content control field. Here is a simple example of the document.xml:
The problematic line is
<w:label w:val="0" />
in<w:sdtPr>
.The java code looks like:
The error happens on the last line with the follow stack trace:
According to the documentation about open xml format, the label is allowed on that position. How can I fix this issue? I quite new to docx4j.
Best Martin