如何使用pdfsharp在pdf中绘制水平线

Ann*_*ara 1 c# asp.net

我们如何使用pdfsharp绘制两条宽度为3cm的水平线,中间插入一个文本,我知道如何打印字符串,并且效果很好。

我需要在两条水平线之间打印日期。有人可以帮我吗。这是我的打印日期代码

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

VDW*_*WWD 5

您可以使用此代码段。它将在页面中间绘制一条红线。您可能需要尝试使用的线高5来获得所需的尺寸。

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);
}
Run Code Online (Sandbox Code Playgroud)