Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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

Draws a line that connects two points with specified coordinates.

Namespace: DevExpress.Pdf

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

NuGet Package: DevExpress.Pdf.Drawing

#Declaration

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

#Parameters

Name Type Description
pen Pen

A Pen 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 (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    processor.CreateEmptyDocument();
    PdfPage page = processor.AddNewPage(PdfPaperSize.A4);
        using (PdfGraphics graphics = processor.CreateGraphics())
        {
            // Draw a line.
            using (var pen = new Pen(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