HTML2PDF and PDFNet use different fonts for Helvetica

It seems that when we specify “Helvetica” in the HTML, and call :


Hello World!

It does not use the same font as when adding text using CreateTextBegin:

eb.CreateTextBegin(pdftron.PDF.Font.Create(_doc, pdftron.PDF.Font.StandardType1Font.e_helvetica), 8);

They should be the same - but they are not - as a result when we mix the two methods on the same document, it shows inconsistent fonts.

When inspecting the PDF using Adobe Acrobat, we find that one font is in ArialRegular, and the other is Helvetica (mapped to ArialMT) - See attached screenshot.

Is there a way to manually set the font when calling html2pdf.InsertFromHtmlString(…)?

First a clarification. In the PDF specification there are 14 standard fonts (including helvetica) that a conforming PDF reader (Adobe, PDFNet, foxit, etc) will support, without that font actually being in the PDF itself. In other words, the PDFNet library itself has the required helvetica font data inside. If you look at your last screen shot, all the other fonts are embedded (in the PDF) while helvetica is not, because the PDF reader has the info needed.

The issue is, your html specifies helvetica, but your computer doesn’t have it, so the user-agent (Chrome, Safari, HTML2PDF, etc) has to pick the best alternative (in this case Arial, since Arial is a windows knock off of helvetica). Since HTML2PDF is trying to match what you would see in a browser, it uses that alternative.

So what are the possible solutions?

  1. Tell PDFNet to use the font that HTML2PDF picked, by calling element.GetGState().GetFont() on one of the text runs created by HTML2PDF conversion.

  2. Acquire/purchase helvetica font and install on computer doing conversion. You can then use font-face css style to specify the exact font to use for the helvetica font family. Then in PDFNet use the step 1 above to get the same font.

  3. Change the font that was picked by HTML2PDF and switch it to helvetica. This is has to be done ‘manually’ and there are some postings on our forum on how to do this. Normally we don’t recommend this, as it is non-trivial (for instance spacing between characters would change, perhaps for the worse). But since arial is meant to be very similar to helvetica, this might work out ok. If you’re interested here are some links to help get you started.!searchin/pdfnet-sdk/change$20font/pdfnet-sdk/9TfFnRwLnhU/G3GU3rMVej8J!searchin/pdfnet-sdk/modify$20font/pdfnet-sdk/e1GwCsZplgk/DLshx-PoqfIJ