Skip to main content

PdfGraphics.DrawString(String, Font, SolidBrush, PointF) Method

Draws text with the specified brush and font parameters at the specified page point.

Namespace: DevExpress.Pdf

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

NuGet Package: DevExpress.Pdf.Drawing


public void DrawString(
    string text,
    Font font,
    SolidBrush brush,
    PointF point


Name Type Description
text String

A text to draw.

font Font

An object that defines font options.

brush SolidBrush

An object that determines the color and texture of the drawn text.

point PointF

A point in the world coordinate system where you can position text.


Use the MeasureString method to calculate the size of the drawn text and a point where you can draw text.

The point parameter define the point where the text’s upper-left corner is located. Set the TextOrigin property to Baseline to make the point parameter define the point where the start of the text’s baseline is located. Set this property before the DrawString method call.

Use the UseKerning property to enable kerning in drawn text.

To draw a string on the PDF page, use one of the following methods:

PdfGraphics.AddToPageForeground, PdfGraphics.AddToPageBackground
These methods allow you to draw content on an existing page.
Draws content on a new page.

The code sample below draws text in the center of an empty page:

draw string result

using DevExpress.Pdf;
using DevExpress.Drawing;

using (var processor = new PdfDocumentProcessor()) {
  using (PdfGraphics graphics = processor.CreateGraphics()) {

      // Obtain the first document page
      PdfPage page = processor.AddNewPage(PdfPaperSize.A4);
      PdfRectangle pageSize = page.CropBox;

      // Specify text to draw
      string text = "PDF Document API";
      using (SolidBrush textBrush = new SolidBrush(Color.FromArgb(255, Color.DarkOrange))) {
          using (DXFont font = new DXFont("Segoe UI", 20, DXFontStyle.Regular)) {
              // Calculate text size
              SizeF textSize = graphics.MeasureString(text, font, new PdfStringFormat(), 72, 72)

              // Calculate a point where to draw text
              PointF textPoint =
                  new PointF((float)((pageSize.Width - textSize.Width) / 2), (float)((pageSize.Height - textSize.Height) / 2));

              // Draw text at the calculated point
              graphics.DrawString(text, font, textBrush, textPoint);

              // Add graphics content to the page foreground
              graphics.AddToPageForeground(page, 72, 72);

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the DrawString(String, Font, SolidBrush, PointF) method.


The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also