Developing software in the Real World

Notes on embedding fonts in rst2pdf

I wanted to use Helvetica Light in a PDF that I’m creating using rst2pdf and this proved a little tricker than I expected.

Note that to use fonts with rst2pdf, you need to install fontconfig using brew:

Now, on to the problem!

In this case, I discovered that setting stdFont: Helvetica-Light or stdFont: HelveticaLight in the style file resulted in Verdana being used in the PDF file!

Fortunately, the -v switch to rst2pdf is your friend when you want to know what’s happening:

As can be seen by the output, rst2pdf can’t find Helvetica-Light and so has substituted Verdana instead. This would seem to be because it couldn’t find a TTF file for the font on my Mac as Helvetica Light is stored in a dfont file.

To solve this, I used DFontSplitter to extract Helvetica Light as a separate TTF file and added this as an embedded font to the style file:

and re-ran with -v which gave me this information:

I now know that the name to use when referencing this font is “fonts/HelveticaLight” and so I can use it within the style file like this:

and the font is embedded as I expected.

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *