How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

C# PDF Generator SDK
C#: How to add, apply Font resources to PDF file in .NET ASP.NET MVC, WinForms applications


C# Demo Code to add a font to adobe pdf file









In this C# tutorial, you will learn how to create, insert text with font specified on PDF document using C# in ASP.NET MVC Web, Windows applications.

  • Use standard 14 fonts
  • Use operating system fonts

How to add text with font on a new PDF report file using C#

  1. Download XDoc.PDF Report Generator C# library
  2. Install C# library to set text font on PDF document
  3. Step by Step Tutorial














Insert text with standard 14 fonts in PDF using C#


In PDF, 14 Type 1 fonts are defined as the standard fonts.

  • Times−Roman
  • Times−Bold
  • Times−Italic
  • Times−BoldItalic
  • Helvetica
  • Helvetica−Bold
  • Helvetica−Oblique
  • Helvetica−BoldOblique
  • Courier
  • Courier−Bold
  • Courier−Oblique
  • Courier−BoldOblique
  • Symbol
  • ZapfDingbats



Below are the steps and C# sample source code to insert text with standard fonts in PDF using C#.

  1. Use PDFBuildHandler.Create() to create a new PDF document
  2. Open the document object, start editing the PDF content
  3. Add a new text paragraph with standard font to the PDF document
  4. Save the PDF file



String outputFilePath = Program.RootPath + "\\" + "Sample14.pdf";

Document document = new Document();
PDFBuildHandler.Create(document, outputFilePath);

//  open document
document.Open();

document.Add(new Paragraph("Font: Helvetica Regular", new Font(Font.FontFamily.Helvetica, 24F, Font.FontStyle.Regular)));
document.Add(new Paragraph("Font: Helvetica Bold", new Font(Font.FontFamily.Helvetica, 24F, Font.FontStyle.Bold)));
document.Add(new Paragraph("Font: Helvetica Italic", new Font(Font.FontFamily.Helvetica, 24F, Font.FontStyle.Italic)));
document.Add(new Paragraph("Font: Helvetica Bold Italic", new Font(Font.FontFamily.Helvetica, 24F, Font.FontStyle.BoldItalic)));

document.Add(new Paragraph("Font: Times New Roman Regular", new Font(Font.FontFamily.TimesRoman, 24F, Font.FontStyle.Regular)));
document.Add(new Paragraph("Font: Times New Roman Bold", new Font(Font.FontFamily.TimesRoman, 24F, Font.FontStyle.Bold)));
document.Add(new Paragraph("Font: Times New Roman Italic", new Font(Font.FontFamily.TimesRoman, 24F, Font.FontStyle.Italic)));
document.Add(new Paragraph("Font: Times New Roman Bold Italic", new Font(Font.FontFamily.TimesRoman, 24F, Font.FontStyle.BoldItalic)));

document.Add(new Paragraph("Font: Courier Regular", new Font(Font.FontFamily.Courier, 24F, Font.FontStyle.Regular)));
document.Add(new Paragraph("Font: Courier Bold", new Font(Font.FontFamily.Courier, 24F, Font.FontStyle.Bold)));
document.Add(new Paragraph("Font: Courier Italic", new Font(Font.FontFamily.Courier, 24F, Font.FontStyle.Italic)));
document.Add(new Paragraph("Font: Courier Bold Italic", new Font(Font.FontFamily.Courier, 24F, Font.FontStyle.BoldItalic)));

document.Add(new Paragraph("Font: Symbol", new Font(Font.FontFamily.Symbol, 24F, Font.FontStyle.Regular)));
document.Add(new Paragraph("Font: ZapfDingbats", new Font(Font.FontFamily.ZapfDingbats, 24F, Font.FontStyle.Regular)));

//  close document and save to the output file
document.Close();




Create font by importing from a system font in C#


Below are the steps and C# sample source code to insert text with fonts from your operating system in PDF using C#.

  1. Use PDFBuildHandler.Create() to create a new PDF document
  2. Open the document object, start editing the PDF content
  3. Add a new text paragraph with system font to the PDF document
  4. Save the PDF file

s

String outputFilePath = Program.RootPath + "\\" + "Sample15.pdf";

Document document = new Document();
PDFBuildHandler.Create(document, outputFilePath);

//  open document
document.Open();

Font aFont = Font.CreateFont(new System.Drawing.Font("Arial", 72F, System.Drawing.FontStyle.Regular), new Color(255, 0, 0));

document.Add(new Paragraph("Embedded Font: Arial, 72F, Rregular", aFont));

//  close document and save to the output file
document.Close();