Question

Docx4j version 2.8.1.3

The docx is a very simple one with just some text, it doesn't seem to work for any docx though.

May be easier to view source/exception at docx4j forums. http://www.docx4java.org/forums/pdf-output-f27/docx4j-to-pdf-fop-issues-cannot-perform-the-transformation-t1652.html

If answered at one place I will update both with answer

Here is the exception

fourseasons.general.conversionservice.converter.AbstractConverter FOP issues 
org.docx4j.openpackaging.exceptions.Docx4JException: FOP issues

  Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Cannot perform the transformation
     at org.docx4j.XmlUtils.transform(XmlUtils.java:911)
     at org.docx4j.XmlUtils.transform(XmlUtils.java:802)
     at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:349)
     ... 230 more
  Caused by: javax.xml.transform.TransformerException: java.lang.NullPointerException
     at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2405)
     at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1376)
     at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
     at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
     at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
     at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2270)
     at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1356)
     at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
     at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1273)
     at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1251)
     at org.docx4j.XmlUtils.transform(XmlUtils.java:909)
     ... 232 more
  Caused by: java.lang.NullPointerException
     at org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:282)
     at org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:248)
     at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
     at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
     at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)

Code to create the bytes:

     Mapper fontMapper = new IdentityPlusMapper();
     wordmlPackage.setFontMapper(fontMapper);

     org.docx4j.convert.out.pdf.viaXSLFO.Conversion c = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(
           wordmlPackage);

     ByteArrayOutputStream os = new ByteArrayOutputStream();
     c.output(os, new PdfSettings());

     os.close();
     binarypdf = os.toByteArray();
Was it helpful?

Solution

I had this same issue. Ctrl + A to highlight all page elements and find the element that can't be transformed.

OTHER TIPS

I have no idea what causes this issue, but I narrowed it down to formatting that can't be handled. I simply started deleting pages from a copy of the erring document, one by one. Then when I finally got to where the doc would transform (to PDF) I knew I had found the page with the issue.

From there it was simply a matter of cutting the page's contents from Word, pasting it into another app (Pages in my case) then back into Word and redo my formatting for that page. Pasted the preceding pages back and voila. Bug gone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top