Page 1 of 1

"fo:block-container" is missing child when converting docx

PostPosted: Fri Apr 21, 2017 10:35 pm
by jeremy
Hi,
using docx4j 3.3.1 and docx4j-export-fo 3.3.0,
when I try to convert a docx (see attached file) to a pdf using

Code: Select all
Docx4J.toFO(foSettings, dest, Docx4J.FLAG_EXPORT_PREFER_XSL);


I get :

Code: Select all
org.docx4j.openpackaging.exceptions.Docx4JException: Exception writing Document to OutputStream: org.apache.fop.fo.ValidationException: "fo:block-container" is missing child elements. Required content model: marker* (%block;)+ (See position 1:6270)
   at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:50)
   at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:14)
   at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:209)
   at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:159)
   at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:168)
   at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:47)
   at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:82)
   at org.docx4j.Docx4J.toFO(Docx4J.java:568)


I tried to deactivate strict validation with the FOSettings but I still get the same exception...

Code: Select all

WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(source);
FOSettings foSettings = Docx4J.createFOSettings();
foSettings.setWmlPackage(wordMLPackage);
foSettings.setApacheFopConfiguration("<fop version=\"2.1\"><strict-validation>false</strict-validation></fop>");


I'm struggling to find a solution, If someone can give me a hand...

Thanks !
Jeremy.

Employment.Verification.docx
(77.13 KiB) Downloaded 323 times

Re: "fo:block-container" is missing child when converting do

PostPosted: Sun Jun 11, 2017 4:13 pm
by Vikram
Hi. I'm having exactly the same problem. Did you find a solution to this?

Thanks.

-- Vikram

Re: "fo:block-container" is missing child when converting do

PostPosted: Wed Jun 14, 2017 9:29 am
by Vikram
Hi.

I've been struggling to find a fix for this.

I create a document using docx4j (see anonymized attachment). If I convert using Docx4J.toFO(foSettings, targetStream, Docx4J.FLAG_EXPORT_PREFER_XSL), I get the following exception:

Code: Select all
org.docx4j.openpackaging.exceptions.Docx4JException: Exception writing Document to OutputStream: org.apache.fop.fo.ValidationException: "fo:static-content" is missing child elements. Required content model: (%block;)+ (See position 1:987)
   at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:50)
   at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:14)
   at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:209)
   at org.docx4j.convert.out.fo.renderers.FORendererApacheFOP.render(FORendererApacheFOP.java:159)
   at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:168)
   at org.docx4j.convert.out.fo.AbstractFOExporter.postprocess(AbstractFOExporter.java:47)
   at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:82)
   ... 27 more
Caused by: javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: "fo:static-content" is missing child elements. Required content model: (%block;)+ (See position 1:987)
   at org.docx4j.org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:506)
   at org.docx4j.utils.XmlSerializerUtil.serialize(XmlSerializerUtil.java:47)
   ... 33 more
Caused by: org.apache.fop.fo.ValidationException: "fo:static-content" is missing child elements. Required content model: (%block;)+ (See position 1:987)
   at org.apache.fop.events.ValidationExceptionFactory.createException(ValidationExceptionFactory.java:38)
   at org.apache.fop.events.EventExceptionManager.throwException(EventExceptionManager.java:58)
   at org.apache.fop.events.DefaultEventBroadcaster$1.invoke(DefaultEventBroadcaster.java:175)
   at com.sun.proxy.$Proxy39.missingChildElement(Unknown Source)
   at org.apache.fop.fo.FONode.missingChildElementError(FONode.java:588)
   at org.apache.fop.fo.pagination.StaticContent.endOfNode(StaticContent.java:57)
   at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:360)
   at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:190)
   at org.docx4j.org.apache.xalan.transformer.TransformerIdentityImpl.endElement(TransformerIdentityImpl.java:1106)
   at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609)
   at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:183)
   at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:357)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2787)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
   at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:118)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
   at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
   at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
   at org.docx4j.org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:489)
   ... 34 more


If I use foSettings.setApacheFopConfiguration("<fop version=\"2.1\"><strict-validation>false</strict-validation></fop>"), the exception goes away, but the exported PDF looks really strange, with large chunks of space between paragraphs.

If I export using Docx4J.toPDF(wordprocessingMLPackage, targetStream) with Plutext's commercial converter, I get a perfect-looking exported PDF.

Any help would be greatly appreciated.

Thanks.

Vikram

Re: "fo:block-container" is missing child when converting do

PostPosted: Sun Jun 18, 2017 10:46 am
by Vikram
In case anybody else gets this error -- it was caused by me creating headers and footers correctly, but leaving them empty (without putting in a paragraph). Word opens such a file just fine, but FO export in strict mode apparently needs content inside any header or footer to proceed. Putting in an empty paragraph solved the problem.