Page 1 of 1

Unable to set the FontMapper

PostPosted: Sat Jan 02, 2016 11:38 am
by wschofield
I'm building an application which reads in a docx template, modifies it, and then writes the modified docx file out. All that works fine. However, I also need to export it to pdf which is where the proverbial "wheels come off". I am using Mac OS X El Capitan and JBoss Developer Studio 9. The problem seems to involve fonts but I'm not sure what. One message that logs out is to delete the fop-font.cache but I'm not sure where it is. Any help is much appreciated. More info below:

I am trying to use a template I found here https://github.com/plutext/docx4j/blob/ ... utPDF.java

However, the first problem I find is that I get a NoClassDefFoundError when I try to set the fontMapper. See partial output below:

Mapper fontMapper = new IdentityPlusMapper();
wordMLPackage.setFontMapper(fontMapper);

[main] INFO org.docx4j.fonts.RunFontSelector - theme font for lang org.docx4j.wml.CTLanguage@63c5b63a is null, but we don't have that
[main] WARN org.docx4j.openpackaging.parts.ThemePart - Empty typeface in font for MINOR_EAST_ASIA
[main] INFO org.docx4j.fonts.RunFontSelector - theme font for lang org.docx4j.wml.CTLanguage@63c5b63a is null, but we don't have that
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/cache/CacheLoader
at org.docx4j.fonts.RunFontSelector.unicodeRangeToFont(RunFontSelector.java:818)
at org.docx4j.fonts.RunFontSelector.fontSelector(RunFontSelector.java:583)
at org.docx4j.fonts.RunFontSelector.fontSelector(RunFontSelector.java:316)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart$FontAndStyleFinder.apply(MainDocumentPart.java:521)
at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:159)
at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:162)
at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:162)
at org.docx4j.TraversalUtil.<init>(TraversalUtil.java:209)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.fontsInUse(MainDocumentPart.java:245)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.setFontMapper(WordprocessingMLPackage.java:337)
at org.docx4j.openpackaging.packages.WordprocessingMLPackage.setFontMapper(WordprocessingMLPackage.java:299)[/color]

Now if I comment that out and attempt to generate the pdf document I get a very similar problem when I execute this line:

Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);

See below:

[main] WARN org.docx4j.openpackaging.parts.ThemePart - Empty typeface in font for MINOR_EAST_ASIA
[main] INFO org.docx4j.fonts.RunFontSelector - theme font for lang org.docx4j.wml.CTLanguage@2adc9300 is null, but we don't have that
[main] WARN org.docx4j.openpackaging.parts.ThemePart - Empty typeface in font for MINOR_EAST_ASIA
[main] INFO org.docx4j.fonts.RunFontSelector - theme font for lang org.docx4j.wml.CTLanguage@2adc9300 is null, but we don't have that
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/cache/CacheLoader
at org.docx4j.fonts.RunFontSelector.unicodeRangeToFont(RunFontSelector.java:818)
at org.docx4j.fonts.RunFontSelector.fontSelector(RunFontSelector.java:583)
at org.docx4j.fonts.RunFontSelector.fontSelector(RunFontSelector.java:316)
at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart$FontAndStyleFinder.apply(MainDocumentPart.java:521)

Re: Unable to set the FontMapper

PostPosted: Sat Jan 02, 2016 12:13 pm
by wschofield
A related question is what libraries (dependencies) do I need to include? I do have some embedded png graphics and have had to include a number of batik libraries.

Re: Unable to set the FontMapper

PostPosted: Mon Jan 11, 2016 4:12 pm
by jason
The cause of that particular NoClassDefFoundError is missing guava-17

You can find that, together with other deps, in http://www.docx4java.org/docx4j/docx4j-3.2.2.zip or individually at http://www.docx4java.org/docx4j/docx4j- ... endencies/

However, its better to just use Maven if you can.

BTW, there aren't any issues with OSX that I'm aware of. If there is any problem, it is something recent...