sandi
sandi

Reputation: 127

Using iText7 to create Font "Courier_new"

I am trying to create a font Courier new in C# using iText7 package. I can only find Courier among the standard fonts, but i would like to use Courier new. My code looks like this:

PdfFont courier = PdfFontFactory.CreateFont(StandardFonts.COURIER, false);

How can I create custom fonts with iText7?

Upvotes: 1

Views: 2905

Answers (1)

Alexey Subach
Alexey Subach

Reputation: 12302

The set of standard fonts is fixed in the PDF specification and consists of 14 fonts in total. Moreover, the visual appearance of those fonts in PDF viewers may be implementation dependent and thus different from viewer to viewer (although in practice you pretty much can't see the difference).

To use your custom font you will need a font file (usually a .ttf or .otf file). E.g. the regular (not bold, not italic) Courier New font shipped with Windows is usually located at C:/Windows/Fonts/cour.ttf (please check with the Windows Fonts licenses whether you are allowed to use it).

You should also provide encoding to the method creating the font. If you don't provide the encoding your Latin characters will be converted just fine, but for a broader range of Unicode characters you should provide IDENTITY_H encoding.

Example:

PdfFont font = PdfFontFactory.createFont("C:/Windows/Fonts/cour.ttf", PdfEncodings.IDENTITY_H);

Upvotes: 3

Related Questions