I'm adding bullets to my word document with apache poi. When I want to convert my word document to pdf file via XDocReport library, i'm getting this nullpointerexception on listContext error.
11:46:28,364 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-5) fr.opensagres.xdocreport.converter.XDocConverterException: fr.opensagres.poi.xwpf.converter.core.XWPFConverterException: java.lang.NullPointerException
at fr.opensagres.xdocreport.converter.docx.poi.itext.XWPF2PDFViaITextConverter.convert(XWPF2PDFViaITextConverter.java:72)
at com.utc.pw.ui.TestWSV2500View.createTestWS(TestWSV2500View.java:6345)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
Caused by: java.lang.NullPointerException
at fr.opensagres.poi.xwpf.converter.core.ListContext.addItem(ListContext.java:48)
at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.visitParagraph(XWPFDocumentVisitor.java:352)
at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.visitBodyElements(XWPFDocumentVisitor.java:231)
at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.visitTableCellBody(XWPFDocumentVisitor.java:1141)
at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.visitCell(XWPFDocumentVisitor.java:1076)
at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.visitTableRow(XWPFDocumentVisitor.java:1024)
at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.visitTableBody(XWPFDocumentVisitor.java:918)
at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.visitTable(XWPFDocumentVisitor.java:900)
at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.visitBodyElements(XWPFDocumentVisitor.java:235)
at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.start(XWPFDocumentVisitor.java:183)
at fr.opensagres.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:57)
... 83 more
My bullet codes is in here
//Bullet
CTAbstractNum cTAbstractNum = CTAbstractNum.Factory.newInstance();
cTAbstractNum.setAbstractNumId(BigInteger.valueOf(0));
CTLvl cTLvl = cTAbstractNum.addNewLvl();
cTLvl.addNewNumFmt().setVal(STNumberFormat.BULLET);
cTLvl.addNewLvlText().setVal("•");
XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
XWPFNumbering numbering = document.createNumbering();
BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
BigInteger numID = numbering.addNum(abstractNumID);
ListContext list=new ListContext();
list.createAndAddItem(cTLvl);
XWPFParagraph paragraph_cell2_table17=cell1_table17.addParagraph();
paragraph_cell2_table17.setSpacingBefore(10);
paragraph_cell2_table17.setSpacingAfter(10);
paragraph_cell2_table17.setIndentationLeft(500);
paragraph_cell2_table17.setVerticalAlignment(TextAlignment.CENTER);
paragraph_cell2_table17.setAlignment(ParagraphAlignment.LEFT);
paragraph_cell2_table17.setNumID(numID);
cell1_table17.setVerticalAlignment(XWPFVertAlign.CENTER);
paragraph_cell2_table17.getCTP().getPPr().addNewRPr().addNewSz().setVal(BigInteger.valueOf(24));
XWPFRun run_cell2_table17=paragraph_cell2_table17.createRun();
run_cell2_table17.setText("If the Engine shows a stabilized (>3sec) Vibration Level above 1.0 ips: perform the necessary Troubleshootings to make sure it is an Engine related vibration. If Vibration Level is still above 1.0 ips after performed extensive Troubleshootings: DO NOT continue the Test.");
run_cell2_table17.setFontFamily("Arial");
run_cell2_table17.setFontSize(10);
run_cell2_table17.setUnderline(UnderlinePatterns.SINGLE);
Am I miss something? Do you guys have any idea?
Your created bullet list only has one indent level. That's why the indent level is not set at all and
Microsoft Wordwill be fine with this.But
XDocReportexpects an indent level set for each numbering level. So ifXDocReportshall work, the indent level needs to be set even if there is only one.So:
Btw.: The
ListContextis unnecessary here.XDocReportcreates that context while parsing the document. So codeListContext list=new ListContext(); list.createAndAddItem(cTLvl);should be removed.