Using a primary and a fallbackfont in Flying Saucer PDF generator

543 views
Skip to first unread message

Staffan Gustafsson

unread,
Dec 20, 2013, 2:45:15 AM12/20/13
to flying-s...@googlegroups.com
I'm having trouble getting flying saucer to use a secondary font for the glyphs/charachters which are not present in my main font.

The Java code I'm using for this purpose is more or less:

    String result = getPrintHtmlContent(urlString);
    result = CharacterConverter.replaceInvalidCharacters(result);

    ITextRenderer renderer = new ITextRenderer();
    renderer.getFontResolver();
    renderer.getFontResolver().addFont(FONTS_DIR_PATH + "ARIALUNI.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    renderer.getFontResolver().addFont(FONTS_DIR_PATH + "droidsans/DroidSans.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    renderer.getFontResolver().addFont(FONTS_DIR_PATH + "droidsans/DroidSansBold.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

    renderer.setDocumentFromString(result, "http://" + frontendHost + ":" + frontendPort + frontendContextRoot);
    renderer.layout();

    renderer.createPDF(os);

And the css:

    body {
      font-family: "Droid Sans", "Arial Unicode MS";
    }

I have also included the fonts in the css by using the @font-face rule.

I am able to get this to work using either of the fonts separately, so there seems to be no problem with flying saucer finding the fonts or the css not rendering correctly.

If I on the other hand do as above and try to use both fonts the output PDF is only using Droid Sans...

Is it even possible to use a "fallback font" in flying saucer, as it is on websites?


(also asked at stackoverflow http://stackoverflow.com/questions/20612624/using-a-primary-and-a-fallbackfont-in-flying-saucer-pdf-generator)

Patrick Wright

unread,
Dec 20, 2013, 5:11:54 AM12/20/13
to flying-s...@googlegroups.com
Hi Staffan,

we last discussed fallback fonts in 2010, see http://markmail.org/thread/hr62evfpnahlv2mh. I believe we never acted on it and we didn't receive any patches to address it. If memory serves this has only been brought up once or twice since the project was started.

If you're interested in working on this, I think Pete can point you to the sections of code to be addressed. I think it would be best if the test for presence of glyphs in a font could be short-circuited somehow to avoid passing the cost on to all documents.


Patrick


Reply all
Reply to author
Forward
0 new messages