Skip to main content
Skip table of contents

How to use the font Verdana in PdfStamper?

Why doesn't exchanging the Part BaseFont.HELVETICA with "Verdana" work?

I want to use Verdana as a font while stamping a PDF file with iText PDF. The original file uses Verdana, which isn't an option in the class Basefont.

Here is the function to create my font right now:

 

def standardStampFont() {
    return BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false)
}
I'd like to change that to the Verdana Font, but simply exchanging the Part BaseFont.HELVETICA with "Verdana" doesn't work.

 

Posted on StackOverflow on Oct 16, 2014 by Alain Sarti

iText can support the Standard Type 1 fonts, because iText ships with AFM file (Adobe Font Metrics files). iText has no idea about the font metrics of other fonts (Verdana isn't a Standard Type 1 font). You need to provide the path to the Verdana font file.

BaseFont.createFont("c:/windows/fonts/verdana.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED)

Note that I change false to BaseFont.EMBEDDED because the same problem you have on your side, will also occur on the side of the person who looks at your file: his PDF viewer can render Standard Type 1 fonts, but may not be able to render other fonts such as Verdana.

Caveat: The hard coded path "c:/windows/fonts/verdana.ttf" works for me on my local machine because the font file can be found using that path on my local machine. This code won't work on the server where I host the iText site, though (which is a Linux server that doesn't even have a c:/windows/fonts directory). I am using this hard coded path by way of example. You should make sure that the font is present and available when you deploy your application.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.