Docotic.Pdf Library Help > Samples > Text > Character spacing

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

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

C#
using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class CharacterSpacing
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "CharacterSpacing.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                const string sampleText = "Lorem ipsum dolor sit amet, consectetur adipisicing elit";
                PdfCanvas canvas = pdf.Pages[0].Canvas;

                canvas.CharacterSpacing = 1;
                canvas.DrawString(10, 50, sampleText);

                canvas.CharacterSpacing = 4;
                canvas.DrawString(10, 60, sampleText);

                canvas.CharacterSpacing = 10;
                canvas.DrawString(10, 70, sampleText);

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
    }
}
VB
Imports System.Diagnostics
Imports System.IO

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class CharacterSpacing
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.

            Dim pathToFile As String = "CharacterSpacing.pdf"

            Using pdf As New PdfDocument()

                Const sampleText As String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"
                Dim canvas As PdfCanvas = pdf.Pages(0).Canvas

                canvas.CharacterSpacing = 1
                canvas.DrawString(10, 50, sampleText)

                canvas.CharacterSpacing = 4
                canvas.DrawString(10, 60, sampleText)

                canvas.CharacterSpacing = 10
                canvas.DrawString(10, 70, sampleText)

                pdf.Save(pathToFile)
            End Using

            Process.Start(pathToFile)
        End Sub
    End Class
End Namespace