Issue 359 in xdocreport: NullPointerException when converting a sample docx to pdf file

1,387 views
Skip to first unread message

xdocr...@googlecode.com

unread,
Jan 26, 2014, 4:50:18 PM1/26/14
to xdocr...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 359 by alexonho...@gmail.com: NullPointerException when
converting a sample docx to pdf file
http://code.google.com/p/xdocreport/issues/detail?id=359

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.



Attachments:
unmarshallFromTemplateExample.docx 3.1 KB

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

xdocr...@googlecode.com

unread,
Jan 27, 2014, 3:57:30 AM1/27/14
to xdocr...@googlegroups.com

Comment #1 on issue 359 by angelo.z...@gmail.com: NullPointerException when
converting a sample docx to pdf file
http://code.google.com/p/xdocreport/issues/detail?id=359

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?

xdocr...@googlecode.com

unread,
Jan 27, 2014, 3:58:30 AM1/27/14
to xdocr...@googlegroups.com
Updates:
Status: Accepted
Owner: angelo.z...@gmail.com

Comment #2 on issue 359 by angelo.z...@gmail.com: NullPointerException when
converting a sample docx to pdf file
http://code.google.com/p/xdocreport/issues/detail?id=359

(No comment was entered for this change.)

xdocr...@googlecode.com

unread,
Feb 2, 2014, 12:21:28 PM2/2/14
to xdocr...@googlegroups.com

Comment #3 on issue 359 by alexonho...@gmail.com: NullPointerException when
converting a sample docx to pdf file
http://code.google.com/p/xdocreport/issues/detail?id=359

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 .

xdocr...@googlecode.com

unread,
Feb 2, 2014, 2:18:24 PM2/2/14
to xdocr...@googlegroups.com
Updates:
Status: WontFix

Comment #4 on issue 359 by angelo.z...@gmail.com: NullPointerException when
converting a sample docx to pdf file
http://code.google.com/p/xdocreport/issues/detail?id=359

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

xdocr...@googlecode.com

unread,
Jun 9, 2015, 5:27:48 AM6/9/15
to xdocr...@googlegroups.com

Comment #6 on issue 359 by bujji.mc...@gmail.com: NullPointerException when
converting a sample docx to pdf file
https://code.google.com/p/xdocreport/issues/detail?id=359

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?

xdocr...@googlecode.com

unread,
Jun 9, 2015, 12:03:53 PM6/9/15
to xdocr...@googlegroups.com

Comment #7 on issue 359 by angelo.z...@gmail.com: NullPointerException when
converting a sample docx to pdf file
https://code.google.com/p/xdocreport/issues/detail?id=359

I have no time to support that today, any PR are welcome!

thomstr...@gmail.com

unread,
Jul 20, 2018, 1:10:16 AM7/20/18
to xdocreport
try add "document.createNumbering()" whose variable document is your XWPFDocument before invoke PdfConverter.getInstance().convert().

在 2014年1月27日星期一 UTC+8上午5:50:18,xdocr...@googlecode.com写道:
Reply all
Reply to author
Forward
0 new messages