Skip to main content

PdfGraphics.DrawRectangle(Pen, RectangleF) Method

Draws a rectangle in the specified page area.

Namespace: DevExpress.Pdf

Assembly: DevExpress.Pdf.v23.2.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");
See Also