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 - 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 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">
         <font embed-url="file:///home/tomek/btgt/resources/OxygenMono-Regular.ttf">          
            <font-triplet name="OxygenMono" style="normal" weight="normal"/>

I have updated my scripts so it runs FOP with this configuration file:

fop -c $RESDIR/fop.config -fo $TARGET/ -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="">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:

This used to be my blog. I moved to long time ago.


Please comment using