Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+

PdfGraphics.TextOrigin Property

Specifies how to interpret a point passed to the PdfGraphics.DrawString method as a parameter.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v21.1.Drawing.dll

NuGet Package: DevExpress.Pdf.Drawing

Declaration

public PdfGraphicsTextOrigin TextOrigin { get; set; }

Property Value

Type Default Description
PdfGraphicsTextOrigin PdfGraphicsTextOrigin.TopLeftCorner

Indicates the point location relative to the drawn text.

Remarks

Use the TextOrigin property to change the location of a point passed to one of the following DrawString overloads as a parameter:

The image below shows the difference between PdfGraphicsTextOrigin.TopLeftCorner and PdfGraphicsTextOrigin.Baseline values.

TextOrigin Difference

The text point is calculated as follows:

using DevExpress.Pdf;
using System.Drawing;
//...
using (var processor = new PdfDocumentProcessor())
{
    processor.CreateEmptyDocument();

    using (PdfGraphics graphics = processor.CreateGraphics())
    {
        PdfPage page = processor.AddNewPage(PdfPaperSize.A4);
        PdfRectangle pageSize = page.CropBox;

        string text = "DevExpress";
        using (SolidBrush textBrush = new SolidBrush(Color.FromArgb(255, Color.DarkOrange)))
        {
            using (Font font = new Font("Segoe UI", 20, FontStyle.Regular))
            {
                SizeF textSize = graphics.MeasureString(text, font);
                PointF textPoint =
                   new PointF((float)((pageSize.Width - textSize.Width) / 2), (float)((pageSize.Height - textSize.Height) / 2));
                graphics.TextOrigin = PdfGraphicsTextOrigin.Baseline;

                graphics.DrawString(text, font, textBrush, textPoint);
                graphics.AddToPageForeground(page, 72, 72);
            }
        }
    }
    processor.SaveDocument("result.pdf");
}
See Also