Error when converting from docx to pdf using docx4j

Nov 10, 2010 at 5:09 AM

Hi,

Following is my code:

import java.io.File;import java.io.FileOutputStream;import java.io.OutputStream;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;

public class DocxToPdfTest {
public static void test() throws Exception {String docxFile = System.getProperty("user.dir") + "/WordTemplate.docx";
WordprocessingMLPackage pkg = WordprocessingMLPackage.load(new File(docxFile));org.docx4j.convert.out.pdf.PdfConversion c = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(pkg);// = new org.docx4j.convert.out.pdf.viaIText.Conversion(pkg);
String pdfFile = changeExtensionToPdf(docxFile);OutputStream os = new FileOutputStream(pdfFile);c.output(os);os.close();
System.out.println("Finished");}
private static String changeExtensionToPdf(String path) {int markerIndex = path.lastIndexOf(".docx");String pdfFile = path.substring(0, markerIndex) + ".pdf";return pdfFile;}
public static void main(String[] args) {try {DocxToPdfTest.test();} catch (Exception e) {e.printStackTrace();}}}

I get following error when executing,


org.docx4j.openpackaging.exceptions.Docx4JException: FOP issues at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:341) at org.docx4j.DocxToPdfTest.test(DocxToPdfTest.java:22) at org.docx4j.DocxToPdfTest.main(DocxToPdfTest.java:36)Caused by: javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: "fo:table-row" is missing child elements.Required content model: (table-cell+) (See position 315:272) at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:501) at org.docx4j.convert.out.pdf.viaXSLFO.Conversion.output(Conversion.java:333) ... 2 moreCaused by: org.apache.fop.fo.ValidationException: "fo:table-row" is missing child elements.Required content model: (table-cell+) (See position 315:272) at org.apache.fop.events.ValidationExceptionFactory.createException(ValidationExceptionFactory.java:38) at org.apache.fop.events.EventExceptionManager.throwException(EventExceptionManager.java:54) at org.apache.fop.events.DefaultEventBroadcaster$1.invoke(DefaultEventBroadcaster.java:152) at $Proxy38.missingChildElement(Unknown Source) at org.apache.fop.fo.FONode.missingChildElementError(FONode.java:550) at org.apache.fop.fo.flow.table.TableRow.finalizeNode(TableRow.java:115) at org.apache.fop.fo.FONode.endOfNode(FONode.java:329) at org.apache.fop.fo.flow.table.TableRow.endOfNode(TableRow.java:108) at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilder.java:348) at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:177) at org.apache.xalan.transformer.TransformerIdentityImpl.endElement(TransformerIdentityImpl.java:1101) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:601) at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:180) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:377) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205) at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484) ... 3 more

Please do needful to fix the error...