font registration for flying saucer with ITextRenderer

238 Views Asked by At

I am using Flying Saucer to generate pdf from html using iText-2.1.7.

For each document I print, I do:

ITextRenderer renderer = new ITextRenderer();

for each font I use:

renderer.getFontResolver().addFont(font.getPath(),font.getName(), BaseFont.CP1252, BaseFont.EMBEDDED, null);

and then the rest of the code to create the pdf:

renderer.getSharedContext().setReplacedElementFactory(...)
renderer.getSharedContext().setUserAgentCallback(...);
renderer.setDocument(xhtmlDom,null);
renderer.layout();
renderer.createPDF(byteArrayOutputStream);

So, for each document, I register all the fonts again and again...

Is this strictly necessary? Is there any font cache service I can use, or something similar?

Thank you very much!

0

There are 0 best solutions below