Page 1 of 1

HTML altChunk and PDF export

PostPosted: Wed Dec 21, 2011 1:31 am
by santoshkumar
Dear all ,
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):--

Syntax: [ Download ] [ Hide ]
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"));
Parsed in 0.016 seconds, using GeSHi 1.0.8.4
.


Stucked part is here:---

Syntax: [ Download ] [ Hide ]
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);
Parsed in 0.016 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

HTML altChunk and PDF export

PostPosted: Wed Dec 21, 2011 9:44 am
by jason
The next version of docx4j will include XHTML importing, including from an altChunk. You can expect a nightly with this in early January.

(At present trunk tip includes XHTML importing, but tables are not yet supported, and you'd need to write a bit of glue to parse the altChunk. I guess there'll be a callback to tidy HTML to XHTML)

Once that is implemented, this problem should go away.

Re: HTML altChunk and PDF export

PostPosted: Fri Dec 23, 2011 12:21 am
by santoshkumar
jason wrote:The next version of docx4j will include XHTML importing, including from an altChunk. You can expect a nightly with this in early January.

(At present trunk tip includes XHTML importing, but tables are not yet supported, and you'd need to write a bit of glue to parse the altChunk. I guess there'll be a callback to tidy HTML to XHTML)

Once that is implemented, this problem should go away.


Dear jason thankx for updating me about this, i will wait for january,
meanwhile, can you guide me, where to find some expmple to play with altChunk (glue code example) so that i can export the PDF. I gone through some example that has been
posted on plutext but got confused to call and process.