Skip to main content
All docs
V25.1
  • 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.1.Drawing.dll

    NuGet Package: DevExpress.Pdf.Drawing

    Declaration

    public void DrawLine(
        DXPen pen,
        float x1,
        float y1,
        float x2,
        float y2
    )

    Parameters

    Name Type Description
    pen DXPen

    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.AddToPageBackground
    These methods allow you to draw content on an existing page.
    PdfDocumentProcessor.RenderNewPage
    Draws content on a new page.

    The code sample below draws a line that connects two points with specified coordinates.

    Draw a Line

    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.CreateGraphics())
            {
                // 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, 72, 72);
            }
        processor.SaveDocument("out2.pdf");
    }
    Process.Start("out.pdf");
    
    See Also