Page 1 of 1

PDF is Not Generated Proper

PostPosted: Wed Aug 15, 2012 1:46 am
by Hardik
Hello i am using docx4j 2.8.0 and converting docx file into pdf file using following code in java
public static void test() throws Exception
{
String docxFile = "E://testData_20120814194757666.docx";
WordprocessingMLPackage pkg = WordprocessingMLPackage.load(new File(docxFile));
pkg.setFontMapper(new IdentityPlusMapper());
org.docx4j.convert.out.pdf.PdfConversion c = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(pkg);
String pdfFile = changeExtensionToPdf(docxFile);
OutputStream os = new FileOutputStream(pdfFile);
c.output(os,new PdfSettings());
os.close();
}
public 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();
}
}
it will work fine when i create docx file from word2007 having formated text as well as having image
but when i create my docx file using my service(we are using .net services) it will not me allow to create proper pdf file it will discard the formatted text part

Re: PDF is Not Generated Proper

PostPosted: Wed Aug 22, 2012 10:42 pm
by jason
The dropped content is invalid content (w:p inside w:p)

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting

        <w:p w:rsidR="00BD5635" w:rsidP="006D0DCA" w:rsidRDefault="006D0DCA">
          :
          <w:r>
            :
          </w:r>
          <w:p>
            <w:r>
              <w:rPr>
                <w:highlight w:val="yellow" />
              </w:rPr>
              <w:t xml:space="preserve">This is Sample Text</w:t>
            </w:r>
          </w:p>
        </w:p>

 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


so JAXB drops it, as per the ERROR message:

Code: Select all
WARN org.docx4j.jaxb.JaxbValidationEventHandler .handleEvent line 90 - [ERROR] : unexpected element (uri:"http://schemas.openxmlformats.org/wordprocessingml/2006/main", local:"p"). Expected elements ar
INFO org.docx4j.jaxb.JaxbValidationEventHandler .handleEvent line 106 - continuing (with possible element/attribute loss)