The stack trace is as follows:
- Code: Select all
Caused by: javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: For "fo:root", "fo:layout-master-set" must be declared before "fo:page-sequence"! (No context info available)
at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1325)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
at org.apache.xalan.templates.ElemIf.execute(ElemIf.java:162)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:128)
at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2400)
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.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:815)
... 3 more
Just in case, here is my code.
- Code: Select all
package test.quickTasks;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.xml.bind.JAXBElement;
import org.docx4j.convert.out.pdf.PdfConversion;
import org.docx4j.convert.out.pdf.viaXSLFO.Conversion;
import org.docx4j.convert.out.pdf.viaXSLFO.PdfSettings;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.Part;
import org.docx4j.openpackaging.parts.PartName;
import org.docx4j.openpackaging.parts.WordprocessingML.FooterPart;
import org.docx4j.openpackaging.parts.WordprocessingML.HeaderPart;
import org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart;
import org.docx4j.vml.CTShape;
import org.docx4j.vml.CTTextbox;
import org.docx4j.wml.ContentAccessor;
import org.docx4j.wml.Document;
import org.docx4j.wml.Ftr;
import org.docx4j.wml.Hdr;
import org.docx4j.wml.Pict;
import org.docx4j.wml.Tbl;
import org.docx4j.wml.Tc;
import org.docx4j.wml.Text;
public class ExportWordDocument{
public static void main(String[] args){
String directory = System.getProperty("user.dir");
String templatePath = directory + "/wad_cover.docx";
try{
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(new File(templatePath));
// convert to PDF
PdfConversion converter = new Conversion(wordMLPackage);
// save the file
OutputStream os = new FileOutputStream(directory + "/wad.pdf");
converter.output(os, null);
}
catch(Exception e){
e.printStackTrace();
}
}
Extra added information: I did try to google around for a solution and saw something that mentioned about having a bigger heap space. My heap is already set to 150m, so I did not think that I needed any more.