- Code: Select all
public class DocxToHTML {
// Config for non-command line version
static {
//inputfilepath = System.getProperty("user.dir") + "/sample-docs/word/sample-docxv2.docx;
inputfilepath = "test3.docx";
save = true;
}
static String inputfilepath;
static boolean save;
public static void main(String[] args) throws Exception {
convert(args);
}
public static void convert(String[] args)
throws Exception {
// Document loading (required)
WordprocessingMLPackage wordMLPackage;
wordMLPackage = Docx4J.load(new java.io.File(inputfilepath));
// HTML exporter setup (required)
// .. the HTMLSettings object
HTMLSettings htmlSettings = Docx4J.createHTMLSettings();
htmlSettings.setImageDirPath(inputfilepath + "_files");
htmlSettings.setImageTargetUri(inputfilepath.substring(inputfilepath.lastIndexOf("/")+1)
+ "_files");
htmlSettings.setWmlPackage(wordMLPackage);
// output to an OutputStream.
OutputStream os = new FileOutputStream(inputfilepath + ".html");
Docx4J.toHTML(htmlSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);
System.out.println("Saved: " + inputfilepath + ".html ");
}
}
However, the following logs and exceptions occurs:
[main] WARN org.docx4j.fonts.RunFontSelector - Font 'Calibri' is not mapped to a physical font.
java.lang.NullPointerException
at org.docx4j.fonts.RunFontSelector.unicodeRangeToFont(RunFontSelector.java:544)
at org.docx4j.fonts.RunFontSelector.fontSelector(RunFontSelector.java:489)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart$FontAndStyleFinder.apply(MainDocumentPart.java:508)
at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:163)
at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:166)
at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:166)
at org.docx4j.TraversalUtil.<init>(TraversalUtil.java:206)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.fontsInUse(MainDocumentPart.java:243)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.setFontMapper(WordprocessingMLPackage.java:323)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.setFontMapper(WordprocessingMLPackage.java:303)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.getFontMapper(WordprocessingMLPackage.java:354)
at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.process(PartialDeepCopy.java:78)
at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:72)
at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:124)
at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:51)
at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:32)
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:60)
at org.docx4j.Docx4J.toHTML(Docx4J.java:502)
at test.DocxToHTML.convert(DocxToHTML.java:100)
at test.DocxToHTML.main(DocxToHTML.java:59)
[main] INFO org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart - fontsInUse..
[main] INFO org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart - Style with name Normal, id 'a' is default paragraph style
[main] INFO org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart - Added virtual style, id 'DocDefaults', name 'DocDefaults'
[main] INFO org.docx4j.openpackaging.parts.WordprocessingML.StyleDefinitionsPart - Style with name Default Paragraph Font, id 'a0' is default character style
[main] WARN org.docx4j.fonts.RunFontSelector - Font 'Calibri' is not mapped to a physical font.
[main] ERROR org.docx4j.convert.out.common.AbstractExporter - Exception exporting package
org.docx4j.openpackaging.exceptions.Docx4JException: Error setting font mapper on copy
at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.process(PartialDeepCopy.java:82)
at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:72)
at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:124)
at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:51)
at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:32)
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:60)
at org.docx4j.Docx4J.toHTML(Docx4J.java:502)
at test.DocxToHTML.convert(DocxToHTML.java:100)
at test.DocxToHTML.main(DocxToHTML.java:59)
Caused by: java.lang.NullPointerException
Exception in thread "main" org.docx4j.openpackaging.exceptions.Docx4JException: Exception exporting package
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:79)
at org.docx4j.Docx4J.toHTML(Docx4J.java:502)
at test.DocxToHTML.convert(DocxToHTML.java:100)
at test.DocxToHTML.main(DocxToHTML.java:59)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Error setting font mapper on copy
at org.docx4j.convert.out.common.preprocess.PartialDeepCopy.process(PartialDeepCopy.java:82)
at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:72)
at org.docx4j.convert.out.common.Preprocess.process(Preprocess.java:124)
at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:51)
at org.docx4j.convert.out.common.AbstractWmlExporter.preprocess(AbstractWmlExporter.java:32)
at org.docx4j.convert.out.common.AbstractExporter.export(AbstractExporter.java:60)
... 3 more
Caused by: java.lang.NullPointerException
Why is this? Why a "Font 'Calibri' is not mapped to a physical font" ?