This sample shows how to adjust baseline of text (useful for drawing superscripts or subscripts) using PdfCanvas.TextRise property.
Text rise specifies the distance to move the baseline up or down from its default location. A positive value for PdfCanvas.TextRise property moves the baseline up, a negative value moves the baseline down.
using System.Diagnostics; using System.Drawing; namespace BitMiracle.Docotic.Pdf.Samples { public static class TextRise { 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. PdfDocument pdf = new PdfDocument(); const string sampleText = "Hello!"; PdfCanvas canvas = pdf.Pages[0].Canvas; canvas.TextPosition = new PdfPoint(10, 50); canvas.TextRise = 0; canvas.DrawString(sampleText); canvas.TextRise = 5; canvas.DrawString(sampleText); canvas.TextRise = -10; canvas.DrawString(sampleText); string pathToFile = "TextRise.pdf"; pdf.Save(pathToFile); pdf.Dispose(); Process.Start(pathToFile); } } }
Imports System.Diagnostics Imports System.Drawing Imports BitMiracle.Docotic.Pdf Namespace BitMiracle.Docotic.Pdf.Samples Public NotInheritable Class TextRise 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 pdf As New PdfDocument() Const sampleText As String = "Hello!" Dim canvas As PdfCanvas = pdf.Pages(0).Canvas canvas.TextPosition = New PdfPoint(10, 50) canvas.TextRise = 0 canvas.DrawString(sampleText) canvas.TextRise = 5 canvas.DrawString(sampleText) canvas.TextRise = -10 canvas.DrawString(sampleText) Dim pathToFile As String = "TextRise.pdf" pdf.Save(pathToFile) pdf.Dispose() Process.Start(pathToFile) End Sub End Class End Namespace
