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

Declaration

public void DrawRectangle(
    Pen pen,
    RectangleF bounds
)

Parameters

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.

Remarks

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.
PdfDocumentProcessor.RenderNewPage
Draws content on a new page.

Example

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()) {
    processor.CreateEmptyDocument();
    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);
    }
    processor.SaveDocument("out2.pdf");
}
Process.Start("out.pdf");

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the DrawRectangle(Pen, RectangleF) method.

Note

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