Skip to main content

PdfGraphics.TextOrigin Property

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

Namespace: DevExpress.Pdf

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

NuGet Package: DevExpress.Pdf.Drawing

Declaration

public PdfGraphicsTextOrigin TextOrigin { get; set; }

Property Value

Type Description
PdfGraphicsTextOrigin

Indicates the point location relative to the drawn text.

Available values:

Name Description
TopLeftCorner

The point is the top left corner of the text rectangle.

Baseline

The point is on the text baseline.

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