Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a horizontal line in pdf using pdfsharp

Tags:

c#

asp.net

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);
like image 784
Ann Sara Avatar asked Oct 26 '25 05:10

Ann Sara


1 Answers

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);
}
like image 109
VDWWD Avatar answered Oct 28 '25 20:10

VDWWD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!