Ann Sara
Ann Sara

Reputation: 69

How to draw a horizontal line in pdf using pdfsharp

How could we draw two horizontal lines of width 3cm with a text in between using pdfsharp.I know how to print a string and it's working well.

I need to print date in between two horizontal lines .Could someone help me please. This is my code to print date

 graph.DrawString(date1, font, XBrushes.Black, new XRect(6.259843 * 72, 0.905512 * 72, 
    pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

Upvotes: 4

Views: 6753

Answers (1)

VDWWD
VDWWD

Reputation: 35514

You can use this snippet. It will draw a red line across the page at the middle. You may need to experiment with the line height of 5 to get your desired size.

PdfPage pdfPage = yourPDFdoc.AddPage();
pdfPage.Width = XUnit.FromMillimeter(210);
pdfPage.Height = XUnit.FromMillimeter(297);

using (XGraphics gfx = XGraphics.FromPdfPage(pdfPage))
{
    XPen lineRed = new XPen(XColors.Red, 5);

    gfx.DrawLine(lineRed, 0, pdfPage.Height / 2, pdfPage.Width, pdfPage.Height / 2);
}

Upvotes: 10

Related Questions