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.1.Drawing.dll
NuGet Package: DevExpress.Pdf.Drawing
Declaration
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.
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");