HTML with <li></li> to docx
Posted: Fri Apr 12, 2019 1:42 am
Hello,
I discovered docx4j, and I am trying to use it to convert docx files to html, and from html back to docx.
I use docx4j v. 6.1.2, and docx4j-ImportXHTML v.6.1.0.
After some testing, I did the first step, but now I am stuck in the second one.
Here is my code :
When I launch the conversion, I always have a NullPointerException in the file XHTMLImporterImpl.class:1117 "listHelper.peekListItemStateStack().init();"
I checked in debug mode the different steps, and I found out that the ListItemStateStack is filled when meeting a "<ul>" or "<ol>" block in the html file, but then later on, the code tries to access this list for "<li>" blocks, which results in an NPE, because the list is empty, so the peek method returns a null, and it cannot launch the init() method.
Am I missing something?
Thank you very much for your help.
I discovered docx4j, and I am trying to use it to convert docx files to html, and from html back to docx.
I use docx4j v. 6.1.2, and docx4j-ImportXHTML v.6.1.0.
After some testing, I did the first step, but now I am stuck in the second one.
Here is my code :
- Code: Select all
File html = new File("C:\\Users\\guest\\Downloads\\tmp\\24-20-01-062.html");
WordprocessingMLPackage wordPackage = WordprocessingMLPackage.createPackage();
NumberingDefinitionsPart ndp = new NumberingDefinitionsPart();
wordPackage.getMainDocumentPart().addTargetPart(ndp);
ndp.unmarshalDefaultNumbering();
XHTMLImporterImpl xhtmlImporter = new XHTMLImporterImpl(wordPackage);
xhtmlImporter.setHyperlinkStyle("Hyperlink");
System.out.println("---------- CONVERSION -------------");
wordPackage.getMainDocumentPart().getContent().addAll(xhtmlImporter.convert(html, null));
System.out.println("---------- END CONVERSION -------------");
OutputStream out = new FileOutputStream("C:\\Users\\guest1477\\Downloads\\tmpOut\\24-20-01-062.docx");
wordPackage.save(out);
When I launch the conversion, I always have a NullPointerException in the file XHTMLImporterImpl.class:1117 "listHelper.peekListItemStateStack().init();"
I checked in debug mode the different steps, and I found out that the ListItemStateStack is filled when meeting a "<ul>" or "<ol>" block in the html file, but then later on, the code tries to access this list for "<li>" blocks, which results in an NPE, because the list is empty, so the peek method returns a null, and it cannot launch the init() method.
Am I missing something?
Thank you very much for your help.