Back to Devexpress

PdfGraphics.FillRectangle(DXBrush, RectangleF) Method

officefileapi-devexpress-dot-pdf-dot-pdfgraphics-dot-fillrectangle-x28-devexpress-dot-drawing-dot-dxbrush-system-dot-drawing-dot-rectanglef-x29.md

latest5.1 KB
Original Source

PdfGraphics.FillRectangle(DXBrush, RectangleF) Method

Fills the interior of a rectangle located in the specified page area.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Pdf.v25.2.Drawing.dll

NuGet Package : DevExpress.Pdf.Drawing

Declaration

csharp
public void FillRectangle(
    DXBrush brush,
    RectangleF bounds
)
vb
Public Sub FillRectangle(
    brush As DXBrush,
    bounds As RectangleF
)

Parameters

NameTypeDescription
brushDXBrush

A DXBrush object that specifies the brush used to fill the rectangle.

| | bounds | RectangleF |

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

|

Remarks

This method fills the rectangle interior with a brush. The bounds parameter specifies the page rectangle to fill.

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

PdfGraphics.AddToPageForeground, PdfGraphics.AddToPageBackgroundThese methods allow you to draw content on an existing page.PdfDocumentProcessor.RenderNewPageDraws content on a new page.

The following code snippet fills a rectangle with the specified brush.

csharp
using DevExpress.Pdf;
using DevExpress.Drawing;
//...

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    processor.CreateEmptyDocument();
    PdfPage page = processor.AddNewPage(PdfPaperSize.A4);
        using (PdfGraphics graphics = processor.CreateGraphicsWorldSystem())
        {
            // Fill a rectangle.
            using (var brush = new DXSolidBrush(Color.Blue))
                graphics.FillRectangle(brush, new RectangleF(50, 50, 500, 300));

            // Add graphics content to the document page.
            graphics.AddToPageForeground(page);
        }
    processor.SaveDocument("out2.pdf");
}
Process.Start("out.pdf");
vb
Imports DevExpress.Pdf
Imports System.Drawing
'...

Using processor As New PdfDocumentProcessor()
    processor.CreateEmptyDocument()
    Dim page As PdfPage = processor.AddNewPage(PdfPaperSize.A4)
        Using graphics As PdfGraphics = processor.CreateGraphicsWorldSystem()
            ' Fill a rectangle.
            Using brush = New DXSolidBrush(Color.Blue)
                graphics.FillRectangle(brush, New RectangleF(50, 50, 500, 300))
            End Using

            ' Add graphics content to the document page.
            graphics.AddToPageForeground(page)
        End Using
    processor.SaveDocument("out2.pdf")
End Using
Process.Start("out.pdf")

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FillRectangle(DXBrush, 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.

pdf-document-api-highlight-search-results/CS/HighlightSearchResults/Program.cs#L53

csharp
using (var brush = new DXSolidBrush(Color.FromArgb(130, 55, 155, 255)))
        graphics.FillRectangle(brush, rect);
}

pdf-document-api-highlight-search-results/VB/HighlightSearchResults/Program.vb#L44

vb
Using brush = New DXSolidBrush(Color.FromArgb(130, 55, 155, 255))
    graphics.FillRectangle(brush, rect)
End Using

See Also

PdfGraphics Class

PdfGraphics Members

DevExpress.Pdf Namespace