Page 1 of 1

Having problems exporting a PDF file...

PostPosted: Sat May 11, 2013 7:32 am
by Arialle
I am not sure what is wrong with my document. I even selected the entire document and pressed the delete key to see if a blank page would export, which it did not. Any help is extremely appreciated. I have been using library for a bit less than a month and I am enjoying what I am seeing. Thanks in advance~!

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.

Re: Having problems exporting a PDF file...

PostPosted: Tue May 14, 2013 9:19 am
by Arialle
Just in case, I am currently using docx4j-2.8.1 jar file. I have tried docx4j-2.8.3 and still got the same problem.

Re: Having problems exporting a PDF file...

PostPosted: Tue May 14, 2013 1:47 pm
by jason
Hi, I tested your docx at http://webapp.docx4java.org/OnlineDemo/ ... f_fop.html
which uses current docx4j nightly and FOP post 1.1 nightly, and it works fine.

I looked at the intermediate XSLFO output using http://webapp.docx4java.org/OnlineDemo/ ... sl_fo.html

The layout-master-set is there, then after that:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
    <fo:flow flow-name="xsl-region-body">

      <fo:table border-bottom-color="#000000" border-bottom-style="none" border-bottom-width="0pt" border-collapse="collapse" border-left-color="#000000" border-left-style="none" border-left-width="0pt" border-right-color="#000000" border-right-style="none" border-right-width="0pt" border-top-color="#000000" border-top-style="none" border-top-width="0pt" display-align="before" start-indent="0in" table-layout="fixed" width="8.16in">
        <fo:table-column column-number="1" column-width="8.16in"/>
        <fo:table-body>
          <fo:table-row>
            <fo:table-cell border-bottom-color="#000000" border-bottom-style="solid" border-bottom-width="0.5pt" border-left-color="#000000" border-left-style="none" border-left-width="0pt" border-right-color="#000000" border-right-style="none" border-right-width="0pt" border-top-color="#000000" border-top-style="none" border-top-width="0pt" padding-bottom="1.27mm" padding-left="2.03mm" padding-right="2.03mm" padding-top="1.27mm">

              <block xmlns="http://www.w3.org/1999/XSL/Format" font-size="20.0pt" line-height="115%" space-after="4mm" text-align="center">
 
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


There may be an issue in the version of FOP you are using where the document starts with a table; or it could be that 2.8.1 is omitting "fo:layout-master-set" in some edge case.

For the second possibility, try docx4j current nightly.

For the first possibility, if you are using FOP 1.0, try FOP 1.1.

Alternatively, try inserting a paragraph at the top of the first page containing some whitespace.

If neither of those work, then a current nightly, plus FOP from SVN (available in our downloads) will be necessary.

Re: Having problems exporting a PDF file...

PostPosted: Thu May 16, 2013 11:03 am
by Arialle
Thank you for the help. I am still in the process of discovering a solution to my problems. The link that you gave is extremely helpful. Using the .FO file did not generate a good enough representation of the PDF file, which tells me that even if I did got the nightlies, the resulting PDF would not be good enough.