Back to Devexpress

PdfGraphics.DrawPath(DXPen, DXGraphicsPath) Method

officefileapi-devexpress-dot-pdf-dot-pdfgraphics-dot-drawpath-x28-devexpress-dot-drawing-dot-dxpen-devexpress-dot-drawing-dot-dxgraphicspath-x29.md

latest4.6 KB
Original Source

PdfGraphics.DrawPath(DXPen, DXGraphicsPath) Method

Draws the specified path on a page.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Drawing

Declaration

csharp
public void DrawPath(
    DXPen pen,
    DXGraphicsPath path
)
vb
Public Sub DrawPath(
    pen As DXPen,
    path As DXGraphicsPath
)

Parameters

NameTypeDescription
penDXPen

A DXPen object that specifies the color, width, and style of the path.

| | path | DXGraphicsPath |

A DXGraphicsPath object in world coordinate system.

|

Remarks

A path is a series of connected lines, curves, and geometric shape primitives. The DrawPath method allows you to draw paths that specify outlines of open and closed figures.

The current transformation matrix of the PdfGraphics object applies to the GraphicsPath object before the DrawPath method draws this path.

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 draws the specified path on a page.

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

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    processor.CreateEmptyDocument();
    PdfPage page = processor.AddNewPage(PdfPaperSize.A4);
        using (PdfGraphics graphics = processor.CreateGraphicsWorld(72,72))
        {
            // Create a path.
            DXGraphicsPath path = new DXGraphicsPath();
            PointF[] points = new PointF[]
            {
              new PointF(150, 150),
              new PointF(70, 100),
              new PointF(100, 300),
              new PointF(300, 400),
              new PointF(400, 700)
            };
            path.AddClosedCurve(points);

            // Draw a path.
            using (var pen = new DXPen(Color.Red, 5))
                graphics.DrawPath(pen, path);

            // 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.CreateGraphicsWorld(72,72)
            ' Create a path.
            Dim path As New DXGraphicsPath()
            Dim points() As PointF = {
                New PointF(150, 150),
                New PointF(70, 100),
                New PointF(100, 300),
                New PointF(300, 400),
                New PointF(400, 700)
            }
            path.AddClosedCurve(points)

            ' Draw a path.
            Using pen As New DXPen(Color.Red, 5)
                graphics.DrawPath(pen, path)
            End Using

            ' Add graphics content to the document 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