PDF to HTML5 conversion – Truetype fonts

One of my favourite features of the PDF File Format is the ability to embed Truetype fonts inside the actual PDF file. This means that you are not limited to a small set of fonts or relying on the user to have the same fonts as you.

The HTML5 File format also supports TrueType fonts, so it would be really cool if we could use the font data in the PDF File to render the HTML5 version of the page…

There are a couple of technical issues with the TrueType font data inside the PDF. First of all, it usually includes only the displayed characters – not a problem for us as we only need those characters. Secondly, the data needs to be modified to work with HTML5 browsers. We already had all the code to read Truetype fonts in our Font engine so it was relatively straight-forward to write the code to rewrite the font data so that it worked.

So how well does it work? Well, you can see the results below (click on the image to open or download the trial version and try it for yourself). My favourite feature is that the code we include to adjust the font size to produce the best fit on the page now uses the exact widths from the the added fonts!

Click on image to see PDF file

We will keep you posted on updates and also look at adding other font types. What would you like to see next?

This post is part of our “Fonts Articles Index” in these articles we explore Fonts.
Click here to see all the other articles in the PDF to HTML5 conversion series.

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>