How To Change Character Spacing in PDF Mosaic Library .NET

This sample shows how to change character spacing using PDFStringFormat.CharacterSpacing property.

Character spacing defines a distance between adjacent characters in a line of text.

C# :

using PDFMosaic;
using System.Drawing;

namespace CharacterSpacing
{
  class CharacterSpacing
  {
    static void Main()
    {
      PDFDocument document = new PDFDocument();
      document.Pages.Add(new PDFPage(PDFPaperFormat.A4));
      PDFCanvas canvas = document.Pages[0].Canvas;

      PDFFont font = new PDFFont("Arial", 16);
      PDFBrush brush = new PDFSolidBrush();

      PDFStringFormat sf = new PDFStringFormat();
      sf.CharacterSpacing = 1.0f;
      string text = "Character spacing = ";

      canvas.DrawString(text + "1.0", font, brush, 10, 100, sf);
      sf.CharacterSpacing = 5.0f;
      canvas.DrawString(text + "5.0", font, brush, 10, 130, sf);
      sf.CharacterSpacing = 10.0f;
      canvas.DrawString(text + "10.0", font, brush, 10, 160, sf);

      document.Save("CharacterSpacing.pdf", true);
    }
  }
}

VB.NET :

Imports PDFMosaic
Imports System.Drawing

Module CharacterSpacing
  Sub Main()
    Dim document As New PDFDocument()
    document.Pages.Add(New PDFPage(PDFPaperFormat.A4))
    Dim canvas As PDFCanvas = document.Pages(0).Canvas

    Dim font As PDFFont = New PDFFont("Arial", 16)
    Dim brush As PDFBrush = New PDFSolidBrush()

    Dim sf As PDFStringFormat = New PDFStringFormat()
    sf.CharacterSpacing = 1.0F
    Dim text As String = "Character spacing = "

    canvas.DrawString(text + "1.0", font, brush, 10, 100, sf)
    sf.CharacterSpacing = 5.0F
    canvas.DrawString(text + "5.0", font, brush, 10, 130, sf)
    sf.CharacterSpacing = 10.0F
    canvas.DrawString(text + "10.0", font, brush, 10, 160, sf)

    document.Save("CharacterSpacing.pdf", True)
  End Sub
End Module