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



我们如何使用 pdfsharp 绘制两条宽 3 厘米的水平线,中间有文字。我知道如何打印字符串,而且效果很好。

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

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

此代码段。它将在中间的页面上画一条红线。您可能需要尝试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);
}

最新更新