feristhia / xdocreport

Automatically exported from code.google.com/p/xdocreport
0 stars 0 forks source link

NullPointerException when converting a sample docx to pdf file #359

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Code:
public class Docx2Pdf {

    public static void main(String[] args) throws IOException {
        long start = System.currentTimeMillis();

        InputStream is = new FileInputStream(new File("/Users/chengliang/docs/unmarshallFromTemplateExample.docx"));
        XWPFDocument document = new XWPFDocument(is);
        PdfOptions options = PdfOptions.create();
        OutputStream out = new FileOutputStream(new File("/Users/chengliang/out/test.pdf"));
        PdfConverter.getInstance().convert(document, out, options);

        System.err.println("Generate pdf with " + (System.currentTimeMillis() - start) + "ms");
    }
}
2. I was using 
      <dependency>
          <groupId>org.apache.pdfbox</groupId>
          <artifactId>pdfbox</artifactId>
        <version>1.8.3</version>
      </dependency>

      <dependency>
          <groupId>fr.opensagres.xdocreport</groupId>
          <artifactId>fr.opensagres.xdocreport.document.docx</artifactId>
          <version>1.0.3</version>
      </dependency>

      <dependency>
          <groupId>fr.opensagres.xdocreport</groupId>
          <artifactId>fr.opensagres.xdocreport.template.freemarker</artifactId>
          <version>1.0.3</version>
      </dependency>

      <dependency>
        <groupId>fr.opensagres.xdocreport</groupId>
        <artifactId>fr.opensagres.xdocreport.converter.docx.xwpf</artifactId>
        <version>1.0.3</version>
      </dependency>

What is the expected output? What do you see instead?

Expecting a pdf file to be generated. I saw 

Exception in thread "main" 
org.apache.poi.xwpf.converter.core.XWPFConverterException: 
java.lang.NullPointerException
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:59)
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:37)
    at org.apache.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:45)
    at com.namedropper.integrationtest.Docx2Pdf.main(Docx2Pdf.java:23)
Caused by: java.lang.NullPointerException
    at org.apache.poi.xwpf.converter.core.MasterPageManager.visitHeadersFooters(MasterPageManager.java:198)
    at org.apache.poi.xwpf.converter.core.MasterPageManager.addSection(MasterPageManager.java:178)
    at org.apache.poi.xwpf.converter.core.MasterPageManager.compute(MasterPageManager.java:125)
    at org.apache.poi.xwpf.converter.core.MasterPageManager.initialize(MasterPageManager.java:95)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitBodyElements(XWPFDocumentVisitor.java:226)
    at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.start(XWPFDocumentVisitor.java:193)
    at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:55)
    ... 3 more

What version of the product are you using? On what operating system?

I am using eclipse/JDK 1.7 on Mac os Mavericks

Please provide any additional information below.

Original issue reported on code.google.com by alexonho...@gmail.com on 26 Jan 2014 at 9:50

Attachments:

GoogleCodeExporter commented 9 years ago
Your docx seems very strange. It doesn't contains w:sectPr in your 
word/document.xml. This sectPr gives the width/height of the page. Without that 
I don't know how to retrieve it?

Have you used MS Word to create this word? If yes, which version do you use?

Original comment by angelo.z...@gmail.com on 27 Jan 2014 at 8:57

GoogleCodeExporter commented 9 years ago

Original comment by angelo.z...@gmail.com on 27 Jan 2014 at 8:57

GoogleCodeExporter commented 9 years ago
Thanks for taking a look.

I was using Docx4j and the word file I used comes from one example there. I 
used my Mac MS word 2011 to save it again and now xdocreport can process it.

Can you please let me know how you debug it? Otherwise please feel free to 
close this bug . 

Original comment by alexonho...@gmail.com on 2 Feb 2014 at 5:21

GoogleCodeExporter commented 9 years ago
It's the first time that I have this case (word/doucment.xml doesn't contains 
w:sectPr) and  as I have explained you, I don't know which width/height I must 
use. I close this issue, but If some people are the same problem, I will study 
it more how to fix it. But if you use MS Word you should not have this problem.

I have noticed too that you use ${colour} in your docx without mergefield. You 
will have trouble if you don't use mergefield to merge your docx with java 
context. I suggest you to read 
https://code.google.com/p/xdocreport/wiki/DocxReportingQuickStart

Original comment by angelo.z...@gmail.com on 2 Feb 2014 at 7:18

GoogleCodeExporter commented 9 years ago
cleanup

Original comment by pascal.leclercq on 10 Oct 2014 at 7:37

GoogleCodeExporter commented 9 years ago
Hi I am also facing the same issue (NullPointerException).
There are two ways to create docx file:
1) Generating docx file using apache poi. while trying to convert that generate 
docx file to pdf i am getting exception.
2) Create docx file using MS Office, i am not getting any exception and pdf 
conversion is successful..

Can you please help me to resolve this issue?

Original comment by bujji.mc...@gmail.com on 9 Jun 2015 at 9:27

GoogleCodeExporter commented 9 years ago
I have no time to support that today, any PR are welcome!

Original comment by angelo.z...@gmail.com on 9 Jun 2015 at 4:03