Playing with iText / XMLWorker samples (mostly this one ), I could easily write simple applications that can create PDF files from HTML using my own additional fonts, but as soon as I try to use my stuff in some kind of web code service, I ended up with exceptions such as:
Table 'name' does not exist in file:/C:/work/MyServer/target/classes/fonts/My%20Font.ttf
ExceptionConverter: com.itextpdf.text.DocumentException: Table 'name' does not exist in file:/C:/work/MyServer/target/classes/fonts/My%20Font.ttf
... which seems to indicate that in the context of the web service, the font file could not be loaded as expected. Here is most of my code:
public HtmlRenderer(final String css, final String[] fontPaths) {
cssResolver = new StyleAttrCSSResolver();
if (css != null) {
final CssFile cssFile = XMLWorkerHelper.getCSS(new ByteArrayInputStream(css.getBytes()));
cssResolver.addCss(cssFile);
}
XMLWorkerFontProvider fontProvider = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
if (fontPaths != null) {
for (final String fontPath : fontPaths) {
final String path = this.getClass().getResource(fontPath).toExternalForm();
fontProvider.register(path);
}
}
CssAppliers cssAppliers = new CssAppliersImpl(fontProvider);
htmlContext = new HtmlPipelineContext(cssAppliers);
htmlContext.setTagFactory(Tags.getHtmlTagProcessorFactory());
...
Should I rely on things like:
- Extract fonts from resources in temporary files (see here )
- factory (. )
!