PDF Mosaic: How to use fonts (TrueType, OpenType, Type1) for writing text


Home       Features       Download       License       Tutorial       Version History       Source Code

 

This sample shows how to use fonts in PDF Mosaic library. PDF Mosaic Library .NET provides several ways to add fonts to PDF document. You can:

  1. load font from file;
  2. add font using its name (the library looks for fonts installed in system);
  3. use built-in PDF fonts.

Class PDFFont represents a font in the PDF document. The class initializes a new instance of the standard font with specified properties.


 

C# :

using PDFMosaic;
using System.Drawing;
 
namespace Fonts
{
  class Fonts
  {
    static void Main()
    {
      PDFDocument document = new PDFDocument();
      document.Pages.Add(new PDFPage(PDFPaperFormat.A4));
      PDFCanvas canvas = document.Pages[0].Canvas;
 
      PDFBrush brush = new PDFSolidBrush();
 
      PDFFont systemFont = new PDFFont("Arial", 12);
      canvas.DrawString("The system font.", systemFont, brush, 10, 60);
 
      PDFFont standardFont = new PDFFont(PDFStandardFont.TimesItalic, 12);
      canvas.DrawString("The standard font.", standardFont, brush, 10, 90);
 
      PDFFont fontFromFile = PDFFont.FromFile("..\\..\\symbol.ttf", 12);
      canvas.DrawString("Font from file.", fontFromFile, brush, 10, 120);
 
      document.Save("Fonts.pdf", true);
    }
  }
}

 

Visial Basic.NET :

Imports PDFMosaic
Imports System.Drawing
 
Module Fonts
  Sub Main()    
    Dim document As New PDFDocument()
    document.Pages.Add(New PDFPage(PDFPaperFormat.A4))
    Dim canvas = document.Pages(0).Canvas
 
    Dim brush As New PDFSolidBrush()
 
    Dim systemFont As New PDFFont("Arial", 12)
    canvas.DrawString("The system font.", systemFont, brush, 10, 60)
 
    Dim standardFont As New PDFFont(PDFStandardFont.TimesItalic, 12)
    canvas.DrawString("The standard font.", standardFont, brush, 10, 90)
 
    Dim fontFromFile = PDFFont.FromFile("..\\..\\symbol.ttf", 12)
    canvas.DrawString("Font from file.", fontFromFile, brush, 10, 120)
 
    document.Save("Fonts.pdf", True)
  End Sub
End Module

 


Home       Features       Download       License       Tutorial       Version History       Source Code