We are using docx4j 3.3.3 updated with the following correction
https://github.com/plutext/docx4j/blob/ ... olver.java
We have a docx (see attached file CustomPropertyUpdateProblemTmp2.docx) which contains the following custom property
<_SUPPLIER_DATA_ELEMENT_15.10.2008 (parametr long long long long long long long/>
with value "long parameter name";
we need to convert this docx into pdf using the following code
public static void main(String[] args) throws Exception {
String regex = null;
PhysicalFonts.setRegex(regex);
String inputfilepath = System.getProperty("user.dir") + "/pdf/CustomPropertyUpdateProblemTmp2.docx";
String outputfilepath = System.getProperty("user.dir") + "/pdf/CustomPropertyUpdateProblemTmp2.pdf";
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(inputfilepath));
// Refresh the values of DOCPROPERTY fields
FieldUpdater updater = new FieldUpdater(wordMLPackage);
updater.update(true);
// All methods write to an output stream
OutputStream os = new java.io.FileOutputStream(outputfilepath);
System.out.println("Attempting to use XSL FO");
Mapper fontMapper = new IdentityPlusMapper();
wordMLPackage.setFontMapper(fontMapper);
PhysicalFont font = PhysicalFonts.get("Arial Unicode MS");
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setFoDumpFile(new File(inputfilepath + ".fo"));
foSettings.setWmlPackage(wordMLPackage);
Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
System.out.println("Saved: " + outputfilepath);
}
but when is executed the statement
updater.update(true);
we have the following exception
Exception in thread "main" org.docx4j.model.fields.FieldValueException: No value found for DOCPROPERTY "<_SUPPLIER_DATA_ELEMENT_15.10.2008 (parametr long long long long long long long/>"
at org.docx4j.model.fields.docproperty.DocPropertyResolver.getValue(DocPropertyResolver.java:74)
at org.docx4j.model.fields.FieldUpdater.updateComplex(FieldUpdater.java:224)
at org.docx4j.model.fields.FieldUpdater.updatePart(FieldUpdater.java:85)
at org.docx4j.model.fields.FieldUpdater.update(FieldUpdater.java:56)
at carlo.pdf.DocxToPdfTmp.main(DocxToPdfTmp.java:35)
The reason of the exception is that in DocPropertyResolver.java the statement
value = docPropsCustomPart.getProperty(key);
search for the key <_SUPPLIER_DATA_ELEMENT_15.10.2008 (parametr long long long long long long long/> but the called method returns null.
The problem seems to be that the value of string key passed to getProperty is
"<_SUPPLIER_DATA_ELEMENT_15.10.2008 (parametr long long long long long long long/>"
(between starting and anding ") and this doesn't match with the original property name.
Does anyone know if it is correct the syntax of the name of the property and if it is possible to correct this wrong behavior ?
Thanks