This sample shows how to align text in PDF document text fields.

Use PdfTextBox.TextAlign property to specify how text should be aligned within field boundaries.

C#
using System.Diagnostics;
using System.Drawing;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class TextFieldAlignment
    {
        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.

            using (PdfDocument pdf = new PdfDocument())
            {
                PointF startPoint = new PointF(10, 10);
                SizeF size = new SizeF(100, 100);
                float distance = 30.0f;
                PdfTextAlign[] horizontalAlignments = { PdfTextAlign.Left, PdfTextAlign.Center, PdfTextAlign.Right };

                PdfPage page = pdf.Pages[0];
                for (int h = 0; h < horizontalAlignments.Length; ++h)
                {
                    PdfTextBox textBox = page.AddTextBox(
                        startPoint.X + h * (size.Width + distance),
                        startPoint.Y,
                        size.Width,
                        size.Height
                    );
                    textBox.Multiline = true;
                    textBox.TextAlign = horizontalAlignments[h];
                    textBox.Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eu ligula ligula, sit amet tempor odio.";
                }

                string pathToFile = "TextFieldAlignment.pdf";
                pdf.Save(pathToFile);
                Process.Start(pathToFile);
            }
        }
    }
}
VB
Imports System.Diagnostics
Imports System.Drawing

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class TextFieldAlignment
        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.

            Using pdf As New PdfDocument()
                Dim startPoint As New PointF(10, 10)
                Dim size As New SizeF(100, 100)
                Dim distance As Single = 30.0F
                Dim horizontalAlignments As PdfTextAlign() = {PdfTextAlign.Left, PdfTextAlign.Center, PdfTextAlign.Right}

                Dim page As PdfPage = pdf.Pages(0)

                For h As Integer = 0 To horizontalAlignments.Length - 1
                    Dim left As Single = startPoint.X + h * (size.Width + distance)
                    Dim top As Single = startPoint.Y
                    Dim textBox As PdfTextBox = page.AddTextBox(left, top, size.Width, size.Height)

                    textBox.Multiline = True
                    textBox.TextAlign = horizontalAlignments(h)
                    textBox.Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum eu ligula ligula, sit amet tempor odio."
                Next

                Dim pathToFile As String = "TextFieldAlignment.pdf"
                pdf.Save(pathToFile)
                Process.Start(pathToFile)
            End Using
        End Sub
    End Class
End Namespace