Page 1 of 1

"'Calibri' is not mapped to a physical font" converting html

PostPosted: Mon Dec 16, 2013 8:12 pm
by waytofall
I'm using the following codes to convert a docx file to hmtl:

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" ?

Re: "'Calibri' is not mapped to a physical font" converting

PostPosted: Mon Dec 16, 2013 8:41 pm
by jason
Please try http://www.docx4java.org/docx4j/docx4j- ... 131211.jar and tell us whether it fixes the NullPointerException.

Why a "Font 'Calibri' is not mapped to a physical font" ?


Assuming you are using the IdentityPlus font mapper, it indicates that Calibri is not installed on your computer.

Re: "'Calibri' is not mapped to a physical font" converting

PostPosted: Tue Dec 17, 2013 1:14 am
by waytofall
jason wrote:Please try http://www.docx4java.org/docx4j/docx4j- ... 131211.jar and tell us whether it fixes the NullPointerException.

Why a "Font 'Calibri' is not mapped to a physical font" ?


Assuming you are using the IdentityPlus font mapper, it indicates that Calibri is not installed on your computer.


Hi Jason,

I'm new to docx4j, I didn't do anything except adding the needed the libs, copying the sample codes and running it, so I don't know what the font mapper thing is. A pity that this problem still occurs after I use your "docx4j-nightly-20131211.jar". About the installing font issue, I can use the calibri font whenever I want in my MS word so the font is surely installed. One thing to mention is that, the document that I use is mostly written in CJK font (actually it's Chinese), is this the problem? Since it's only simple example and I didn't do much.

Thanks.

Re: "'Calibri' is not mapped to a physical font" converting

PostPosted: Tue Dec 17, 2013 6:51 am
by jason
waytofall wrote:the document that I use is mostly written in CJK font (actually it's Chinese)


Can you please post or email me the docx (or at least a simplified test case which exhibits the issue), and I will fix the issue for you.

Re: "'Calibri' is not mapped to a physical font" converting

PostPosted: Tue Dec 17, 2013 12:46 pm
by waytofall
jason wrote:Can you please post or email me the docx (or at least a simplified test case which exhibits the issue), and I will fix the issue for you.


I've sent you a email to jason@plutext.org, please let me know if you want me to sent to another mailbox.

Re: "'Calibri' is not mapped to a physical font" converting

PostPosted: Wed Dec 18, 2013 5:22 pm
by jason