From AsciiDoc/DocBook to PDF, ePub and mobi - part 4
Recently I have learned one (very useful!) trick, that I wanted to share with you. It occurred that it is very simple to create PDF files with custom embedded fonts.
(I think I have learned this from http://www.simon-cozens.org/content/docbook-fop-fonts-and-multilingua - in case of issues, please read this blog post).
My idea was to replace the default font used for listing. The default monospaced font is too wide - it takes too much space so some lines go out of page, which is especially painful for printed formats. I have found some really nice fonts on fontsquirrel.com and wanted to use them instead.
After I downloaded .oft file, I had to convert it into .ttf. This was pretty simple - there are many online converters which do the job.
Then, I instructed fop to use this new font. I created a new configuration file fop.config:
<?xml version="1.0"?>
<fop version="1.0"> <renderers>
<renderer mime="application/pdf">
<fonts>
<font embed-url="file:///home/tomek/btgt/resources/OxygenMono-Regular.ttf">
<font-triplet name="OxygenMono" style="normal" weight="normal"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>
I have updated my scripts so it runs FOP with this configuration file:
fop -c $RESDIR/fop.config -fo $TARGET/btgt.fo -pdf $TARGET/btgt.pdf
The last thing was to inform xsltproc to use this font for listings. All I had to do was to add this line to configuration xsl file:
<xsl:param name="monospace.font.family">OxygenMono</xsl:param>
The Result
Have a look at the two screenshots of generated PDF files.
This is the default font:
And now the same snippet of code using Oxygen Mono font:
- Tomek Kaczanowski's blog
- Login to post comments
This used to be my blog. I moved to http://tomek.kaczanowscy.pl long time ago.