tags:

views:

269

answers:

2

How to embed Helvetica font in PDF using iText?

Following does not work:

BaseFont helvetica = BaseFont.createFont(BaseFont.HELVETICA,
        BaseFont.CP1252, BaseFont.EMBEDDED);
Font font = new Font(helvetica, 20, Font.BOLD);

That is, this will return false:

font.getBaseFont().isEmbedded()

Embedding works if I provide the TrueType file myself as a parameter to createFont() method.

+1  A: 

I did some digging into source code and it seems that iText explicitly ignores BaseFont.EMBEDDED flag for certain fonts and Helvetica is one of them.

Embedding probably works if you provide font file (e.g. TrueType .ttf) for Helvetica.

Juha Syrjälä
+1  A: 

The PDF specification defines 8 fonts which are expected to be available in a PDF Viewer so they would not need to be embedded. Helvetica is one of these.

mark stephens
My problem was that I needed to embed *all* fonts used in PDF file, including those 8 to prevent any differences in rendering.
Juha Syrjälä