I am using docx4j api to export PDF file from DOCX file via XSLFO. A simple text that i typed in my docx file , working perfectly but when i use CTAltChunk to create styled docx and export it to PDF its giving FOP ISSUES, FO FLOW IS MISSING. please help to sort out this stuck.
Generated docx Code is here(working):--
Using java Syntax Highlighting
WordprocessingMLPackage wordMLPackage1 = WordprocessingMLPackage.createPackage();
AlternativeFormatInputPart afiPart1 = new AlternativeFormatInputPart(new PartName("/hw.html"));
afiPart1.setBinaryData(content2.getBytes());
afiPart1.setContentType(new ContentType("text/html"));
Relationship altChunkRel1 = wordMLPackage1.getMainDocumentPart().addTargetPart(afiPart1);
CTAltChunk ac1 = Context.getWmlObjectFactory().createCTAltChunk();
ac1.setId(altChunkRel1.getId() );
wordMLPackage1.getMainDocumentPart().addObject(ac1);
wordMLPackage1.getContentTypeManager().addDefaultContentType("html", "text/html");
wordMLPackage1.save(new java.io.File(new StringResourceModel("upload.path", new Model<String>()).getString()+"/ComparedDFA" + "/updatedContent.docx"));
AlternativeFormatInputPart afiPart1 = new AlternativeFormatInputPart(new PartName("/hw.html"));
afiPart1.setBinaryData(content2.getBytes());
afiPart1.setContentType(new ContentType("text/html"));
Relationship altChunkRel1 = wordMLPackage1.getMainDocumentPart().addTargetPart(afiPart1);
CTAltChunk ac1 = Context.getWmlObjectFactory().createCTAltChunk();
ac1.setId(altChunkRel1.getId() );
wordMLPackage1.getMainDocumentPart().addObject(ac1);
wordMLPackage1.getContentTypeManager().addDefaultContentType("html", "text/html");
wordMLPackage1.save(new java.io.File(new StringResourceModel("upload.path", new Model<String>()).getString()+"/ComparedDFA" + "/updatedContent.docx"));
Parsed in 0.017 seconds, using GeSHi 1.0.8.4
Stucked part is here:---
Using java Syntax Highlighting
Body newerBody = ((Document)newerPackage.getMainDocumentPart().getJaxbElement()).getBody();
Body olderBody = ((Document)olderPackage.getMainDocumentPart().getJaxbElement()).getBody();
java.io.StringWriter sw = new java.io.StringWriter();
javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(sw);
Calendar changeDate = null;
Differencer pd = new Differencer();
pd.diff(newerBody, olderBody, result, "eFile", changeDate,
newerPackage.getMainDocumentPart().getRelationshipsPart(),
olderPackage.getMainDocumentPart().getRelationshipsPart());
String contentStr = sw.toString();
Body newBody = (Body) org.docx4j.XmlUtils.unmarshalString(contentStr);
((Document)newerPackage.getMainDocumentPart().getJaxbElement()).setBody(newBody);
RelationshipsPart rp = newerPackage.getMainDocumentPart().getRelationshipsPart();
handleRels(pd, rp);
newerPackage.setFontMapper(new IdentityPlusMapper());
org.docx4j.convert.out.pdf.PdfConversion c = new org.docx4j.convert.out.pdf.<span style="font-weight: bold">viaXSLFO</span>.Conversion(newerPackage);
Body olderBody = ((Document)olderPackage.getMainDocumentPart().getJaxbElement()).getBody();
java.io.StringWriter sw = new java.io.StringWriter();
javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(sw);
Calendar changeDate = null;
Differencer pd = new Differencer();
pd.diff(newerBody, olderBody, result, "eFile", changeDate,
newerPackage.getMainDocumentPart().getRelationshipsPart(),
olderPackage.getMainDocumentPart().getRelationshipsPart());
String contentStr = sw.toString();
Body newBody = (Body) org.docx4j.XmlUtils.unmarshalString(contentStr);
((Document)newerPackage.getMainDocumentPart().getJaxbElement()).setBody(newBody);
RelationshipsPart rp = newerPackage.getMainDocumentPart().getRelationshipsPart();
handleRels(pd, rp);
newerPackage.setFontMapper(new IdentityPlusMapper());
org.docx4j.convert.out.pdf.PdfConversion c = new org.docx4j.convert.out.pdf.<span style="font-weight: bold">viaXSLFO</span>.Conversion(newerPackage);
Parsed in 0.015 seconds, using GeSHi 1.0.8.4
when the control comes at VIAXSLFO, i got the FOP issue.
ERROR----------:
org.docx4j.openpackaging.exceptions.Docx4JException: FOP issues
at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:372)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Cannot perform the transformation
at org.docx4j.XmlUtils.transform(XmlUtils.java:832)
at org.docx4j.XmlUtils.transform(XmlUtils.java:723)
at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:363)
... 55 more
Caused by: javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: Error(Unknown location): fo:flow is missing child elements.
Required Content Model: marker* (%block;)+
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1410)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:393)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:176)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:393)
at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:176)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2281)
at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1367)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1284)
at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1262)
at org.docx4j.XmlUtils.transform(XmlUtils.java:830)
... 57 more
Caused by: org.apache.fop.fo.ValidationException: Error(Unknown location): fo:flow is missing child elements.
Required Content Model: marker* (%block;)+
at org.apache.fop.fo.FONode.missingChildElementError(FONode.java:407)
at org.apache.fop.fo.pagination.Flow.endOfNode(Flow.java:90)
at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:378)
at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:194)
at org.apache.xml.serializer.ToXMLSAXHandler.endElement(ToXMLSAXHandler.java:261)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1399)
... 72 more