Skip to main content

PdfGraphics.DrawRectangle(Pen, RectangleF) Method

Draws a rectangle in the specified page area.

Namespace: DevExpress.Pdf

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

NuGet Package: DevExpress.Pdf.Drawing


public void DrawRectangle(
    Pen pen,
    RectangleF bounds


Name Type Description
pen Pen

A Pen object that specifies the color, width, and style of the rectangle.

bounds RectangleF

A RectangleF structure that specifies a page area (in world coordinate system) where you can draw a rectangle.


Use this method to draw a rectangle in the page area specified by the bounds parameter.

To draw a shape 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 a rectangle in the specified area of the document page.

Draw a Rectangle

using DevExpress.Pdf;
using System.Drawing;

using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
    PdfPage page = processor.AddNewPage(PdfPaperSize.A4);
    using (PdfGraphics graphics = processor.CreateGraphics()) {

        // Draw a rectangle.
        using (var pen = new Pen(Color.Red, 5))
            graphics.DrawRectangle(pen, new RectangleF(50, 50, 500, 300));

        // Add graphics content to the document page.
        graphics.AddToPageForeground(page, 72, 72);
See Also