Back to Devexpress

PdfGraphics.DrawLine(DXPen, Single, Single, Single, Single) Method

officefileapi-devexpress-dot-pdf-dot-pdfgraphics-dot-drawline-x28-devexpress-dot-drawing-dot-dxpen-system-dot-single-system-dot-single-system-dot-single-system-dot-single-x29.md

latest4.4 KB
Original Source

PdfGraphics.DrawLine(DXPen, Single, Single, Single, Single) Method

Draws a line that connects two points with specified coordinates.

Namespace : DevExpress.Pdf

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

NuGet Package : DevExpress.Pdf.Drawing

Declaration

csharp
public void DrawLine(
    DXPen pen,
    float x1,
    float y1,
    float x2,
    float y2
)
vb
Public Sub DrawLine(
    pen As DXPen,
    x1 As Single,
    y1 As Single,
    x2 As Single,
    y2 As Single
)

Parameters

NameTypeDescription
penDXPen

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

| | x1 | Single |

A Single object that specifies the x-coordinate of the first point.

| | y1 | Single |

A Single object that specifies the y-coordinate of the first point.

| | x2 | Single |

A Single object that specifies the x-coordinate of the second point.

| | y2 | Single |

A Single object that specifies the y-coordinate of the second point.

|

Remarks

Use this method to draw a straight line defined by two points. The x1 , y1 and x2 , y2 parameters specify the coordinates of points in world coordinate system.

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 a line that connects two points with specified coordinates.

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.CreateGraphicsWorldSystem()) {

        // Draw a line.
        using (var pen = new DXPen(Color.Red, 5))
          graphics.DrawLine(pen, 100, 100, 500, 700);

        // 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
Imports DevExpress.Drawing
'...

Using processor As New PdfDocumentProcessor()
    processor.CreateEmptyDocument()
    Dim page As PdfPage = processor.AddNewPage(PdfPaperSize.A4)
        Using graphics As PdfGraphics = processor.CreateGraphicsWorldSystem()
            ' Draw a line.
            Using pen As New DXPen(Color.Red, 5)
                graphics.DrawLine(pen, 100, 100, 500, 700)
            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