How To Change Text Rise in PDF Mosaic Library .NET

This sample shows how to adjust baseline of text (useful for drawing superscripts or subscripts) using PDFStringFormat.Rise property.

Text rise specifies the distance to move the baseline up or down from its default location.

C# :

using PDFMosaic;
using System.Drawing;

namespace TextRise
{
  class TextRise
  {
    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();

      float x = 0;      
      canvas.DrawString("Text rise 0 ", font, brush, x, 100, sf);

      sf.Rise = -font.Size / 2;
      x += font.GetTextWidth("Text rise 0 ");
      canvas.DrawString("Text rise -8 ", font, brush, x, 100, sf);

      sf.Rise = -font.Size / 4;
      x += font.GetTextWidth("Text rise -8 ");
      canvas.DrawString("Text rise -4 ", font, brush, x, 100, sf);
      x += font.GetTextWidth("Text rise -4 ");

      PDFPen pen = new PDFSolidPen();
      canvas.DrawLine(pen, 0, font.Size * 1.5f + 3 + 100, x, font.Size * 1.5f + 3 + 100);

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

VB.NET :

Imports PDFMosaic
Imports System.Drawing

Module TextRise
  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 x As Single = 0
    canvas.DrawString("Text rise 0 ", font, brush, x, 100, sf)

    sf.Rise = -font.Size / 2
    x += font.GetTextWidth("Text rise 0 ")
    canvas.DrawString("Text rise -8 ", font, brush, x, 100, sf)

    sf.Rise = -font.Size / 4
    x += font.GetTextWidth("Text rise -8 ")
    canvas.DrawString("Text rise -4 ", font, brush, x, 100, sf)
    x += font.GetTextWidth("Text rise -4 ")

    Dim pen As New PDFSolidPen()
    canvas.DrawLine(pen, 0, font.Size * 1.5F + 3 + 100, x, font.Size * 1.5F + 3 + 100)

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