Docotic.Pdf Library Help > Samples > Text > Horizontal scaling

This sample shows how to increase or decrease the size of a text line using horizontal scaling.

The PdfCanvas.TextHorizontalScaling property specifies horizontal scaling to use when drawing text. The horizontal scaling adjusts the width of glyphs by stretching or compressing them in the horizontal direction. The value of PdfCanvas.TextHorizontalScaling property is specified as a percentage of the normal width of the glyphs, with 100 being the normal width.

C#
using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class TextHorizontalScaling
    {
        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 = "TextHorizontalScaling.pdf";

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

                canvas.TextHorizontalScaling = 10;
                canvas.DrawString(10, 50, sampleText);

                canvas.TextHorizontalScaling = 50;
                canvas.DrawString(10, 60, sampleText);

                canvas.TextHorizontalScaling = 100;
                canvas.DrawString(10, 70, sampleText);

                pdf.Save(pathToFile);
            }

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

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class TextHorizontalScaling
        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 = "TextHorizontalScaling.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.TextHorizontalScaling = 10
                canvas.DrawString(10, 50, sampleText)

                canvas.TextHorizontalScaling = 50
                canvas.DrawString(10, 60, sampleText)

                canvas.TextHorizontalScaling = 100
                canvas.DrawString(10, 70, sampleText)

                pdf.Save(pathToFile)
            End Using

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