2017-11-18 70 views
1

如何使用pdfsharp中的文本绘制两条宽度3cm的水平线。我知道如何打印字符串并且运行良好。如何使用pdfsharp绘制pdf中的水平线

我需要在两条横线之间打印日期。请有人帮助我。 这是我的代码打印日期

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

回答

2

您可以使用此片段。它会在中间的页面上划一条红线。您可能需要试验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); 
}