2017-11-18 131 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); 
}