Table of Contents

Enum TextAlign

Namespace
Syncfusion.Pdf.Graphics
Assembly
Syncfusion.Pdf.Portable.dll

Specifies how text in a is horizontally aligned.

public enum TextAlign

Fields

Center = 3

The text is aligned in the center.

Justify = 4

The text is justified.

Left = 1

The text is aligned to the left.

Right = 2

The text is aligned to the right.

Examples

//Create a new PDF document.
PdfDocument doc = new PdfDocument();
//Add a page to the document.
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
//Set the font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
//Simple HTML content
string htmlText = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files ";
//Create new PDF HTML text element.
PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement();
//Set text align.
htmlTextElement.TextAlign = TextAlign.Left;
//Set html text.
htmlTextElement.HTMLText = htmlText;
//Set font.
htmlTextElement.Font = font;
//Format Layout.
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
format.Layout = PdfLayoutType.Paginate;
format.Break = PdfLayoutBreakType.FitPage;
//Draw htmlString to PDF page.
htmlTextElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
//Save the document.
doc.Save("Output.pdf");
//Close the document.
doc.Close(true);
 'Create a new PDF document.
 Dim doc As New PdfDocument()
 'Add a page to the document.
 Dim page As PdfPage = doc.Pages.Add()
 'Create PDF graphics for the page.
 Dim graphics As PdfGraphics = page.Graphics
 'Set the font.
 Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
 'Simple HTML content
 Dim htmlText As String = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files "
 'Create new PDF HTML text element.
 Dim htmlTextElement As New PdfHTMLTextElement()
 'Set text align
 htmlTextElement.TextAlign = TextAlign.Left
 'Set html text.
 htmlTextElement.HTMLText = htmlText
 'Set font.
 htmlTextElement.Font = font
'Format Layout.
 Dim format As New PdfMetafileLayoutFormat()
 format.Layout = PdfLayoutType.Paginate
 format.Break = PdfLayoutBreakType.FitPage
 'Draw htmlString to PDF page.
 htmlTextElement.Draw(page, New RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format)
 'Save the document.
 doc.Save("Output.pdf")
 'Close the document.
 doc.Close(True)