officefileapi-devexpress-dot-pdf-dot-pdfgraphics-04f2edde.md
Specifies how to interpret a point passed to the PdfGraphics.DrawString method as a parameter.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Pdf.v25.2.Drawing.dll
NuGet Package : DevExpress.Pdf.Drawing
public PdfGraphicsTextOrigin TextOrigin { get; set; }
Public Property TextOrigin As PdfGraphicsTextOrigin
| 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.
|
Use the TextOrigin property to change the location of a point passed to the PdfGraphics.DrawString() overload as a parameter.
The image below shows the difference between PdfGraphicsTextOrigin.TopLeftCorner and PdfGraphicsTextOrigin.Baseline values.
The text point is calculated as follows:
using DevExpress.Pdf;
using DevExpress.Drawing;
//...
using (var processor = new PdfDocumentProcessor())
{
processor.CreateEmptyDocument();
using (PdfGraphics graphics = processor.CreateGraphicsWorldSystem())
{
PdfPage page = processor.AddNewPage(PdfPaperSize.A4);
PdfRectangle pageSize = page.CropBox;
string text = "DevExpress";
using (var textBrush = new DXSolidBrush(Color.FromArgb(255, Color.DarkOrange)))
{
using (DXFont font = new DXFont("Segoe UI", 20, DXFontStyle.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);
}
}
}
processor.SaveDocument("result.pdf");
}
Imports DevExpress.Pdf
Imports DevExpress.Drawing
'...
Using processor = New PdfDocumentProcessor()
processor.CreateEmptyDocument()
Using graphics As PdfGraphics = processor.CreateGraphicsWorldSystem()
Dim page As PdfPage = processor.AddNewPage(PdfPaperSize.A4)
Dim pageSize As PdfRectangle = page.CropBox
Dim text As String = "DevExpress"
Using textBrush As New DXSolidBrush(Color.FromArgb(255, Color.DarkOrange))
Using font As New DXFont("Segoe UI", 20, DXFontStyle.Regular)
Dim textSize As SizeF = graphics.MeasureString(text, font)
Dim textPoint As
New PointF(CSng((pageSize.Width - textSize.Width) \ 2), CSng((pageSize.Height - textSize.Height) \ 2))
graphics.TextOrigin = PdfGraphicsTextOrigin.Baseline
graphics.DrawString(text, font, textBrush, textPoint)
' Add graphics content to the page foreground
graphics.AddToPageForeground(page)
End Using
End Using
End Using
processor.SaveDocument("result.pdf")
End Using
See Also