Back to Devexpress

PdfGraphics.IntersectClip(RectangleF) Method

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

latest4.8 KB
Original Source

PdfGraphics.IntersectClip(RectangleF) Method

Assigns the clip region of the PdfGraphics object to the intersection of the current clip region and the specified page region.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Drawing

Declaration

csharp
public void IntersectClip(
    RectangleF rect
)
vb
Public Sub IntersectClip(
    rect As RectangleF
)

Parameters

NameTypeDescription
rectRectangleF

A RectangleF structure that intersects the current clip region of the PdfGraphics object (defined in world coordinate system).

|

Remarks

This method allows you to crop the clip region of the PdfGraphics object. Use the PdfGraphics methods (like GDI+) to draw the updated clip region. Refer to the following article for a list of supported drawing method: PDF Graphics API. Then, call the PdfGraphics.AddToPageForeground, PdfGraphics.AddToPageBackground, or PdfDocumentProcessor.RenderNewPage method to add the resulting graphics to a document page.

The following code snippet sets the clip region of the PdfGraphics object to the intersection of the current clip region and the specified page region.

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()) {
            graphics.SaveGraphicsState();

            // Specify the page region that intersects the clip region.
            Rectangle clipRect = new Rectangle(100, 100, 200, 200);

            // Set the clip region to the intersection of
            // the current clip region with the specified rectangle.
            graphics.IntersectClip(clipRect);

            // Draw the updated clip region.
            using (var brush = new DXSolidBrush(Color.Blue))
                graphics.FillRectangle(brush, new RectangleF(0, 0, 500, 500));
            graphics.RestoreGraphicsState();

            // Add graphics content to the target 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()
            graphics.SaveGraphicsState()

            ' Specify the page region that intersects the clip region.
            Dim clipRect As New Rectangle(100, 100, 200, 200)

            ' Set the clip region to the intersection of
            ' the current clip region with the specified rectangle.
            graphics.IntersectClip(clipRect)

            ' Draw the updated clip region.
            Using brush = New DXSolidBrush(Color.Blue)
                graphics.FillRectangle(brush, New RectangleF(0, 0, 500, 500))
            End Using
            graphics.RestoreGraphicsState()

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

See Also

PdfGraphics Class

PdfGraphics Members

DevExpress.Pdf Namespace