I wanted to know how can I convert by docx4j a displayed doc property into "simple text". My document schema is as the following:
Full Name: [DOCPROPERTY] [DOCPROPERTY]
Date and Place of Birth: [DOCPROPERTY] [DOCPROPERTY]
The main issue is that when I convert my document into PDF, I loose the above information. Here's the code:
String inputfilepath = "...somePath"
String outputfilepathWord = "...anotherPath"
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new java.io.File(inputfilepath));
wordMLPackage.save(new File(outputfilepathWord));
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wordMLPackage);
OutputStream os = new java.io.FileOutputStream(outputfilepath);
Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
and in the pdf converted I have the following structure:
Full Name:
Date and Place of Birth:
Thanks in advance!
Edit:
Use of FieldUpdater
FieldUpdater updater = new FieldUpdater(wordMLPackage);
updater.update(true);
catches the following exception:
java.util.NoSuchElementException
at java.util.LinkedList.removeFirst(LinkedList.java:268)
at java.util.LinkedList.pop(LinkedList.java:799)
at org.docx4j.model.fields.FieldsPreprocessor.inParentResult(FieldsPreprocessor.java:214)
at org.docx4j.model.fields.FieldsPreprocessor.handleRun(FieldsPreprocessor.java:346)
at org.docx4j.model.fields.FieldsPreprocessor.handleContent(FieldsPreprocessor.java:180)
at org.docx4j.model.fields.FieldsPreprocessor.canonicaliseInstance(FieldsPreprocessor.java:142)
at org.docx4j.model.fields.FieldsPreprocessor.canonicalise(FieldsPreprocessor.java:128)
here:
else if (p.getParent() instanceof java.util.List) {
// This does happen!
index = ((java.util.List)p.getParent()).indexOf(p);
P newP = FieldsPreprocessor.canonicalise(p, fieldRefs); //<<--EXCEPTION
//log.debug("NewP length: " + newP.getContent().size() );
((java.util.List)p.getParent()).set(index, newP);