How To Increase Or Decrease The Size Of a Text Line Using Horizontal Scaling in PDF Mosaic Library .NET

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

The PDFStringFormat.Scaling 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.

C# :

using PDFMosaic;
using System.Drawing;

namespace HorizontalScaling
{
  class HorizontalScaling
  {
    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();      
      string text = "Horizontal scaling = ";

      sf.Scaling = 50.0f;
      canvas.DrawString(text + "50.0%", font, brush, 10, 100, sf);

      sf.Scaling = 100f;
      canvas.DrawString(text + "100.0%", font, brush, 10, 130, sf);

      sf.Scaling = 150.0f;
      canvas.DrawString(text + "150.0%", font, brush, 10, 160, sf);

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

VB.NET :

Imports PDFMosaic
Imports System.Drawing

Module HorizontalScaling
  Sub Main()
    Dim document As PDFDocument = 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()
    Dim text As String = "Horizontal scaling = "

    sf.Scaling = 50.0F
    canvas.DrawString(text + "50.0%", font, brush, 10, 100, sf)

    sf.Scaling = 100.0F
    canvas.DrawString(text + "100.0%", font, brush, 10, 130, sf)

    sf.Scaling = 150.0F
    canvas.DrawString(text + "150.0%", font, brush, 10, 160, sf)

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