以PDF格式打印该行

时间:2017-09-15 07:16:42

标签: c# pdf itext

我需要在PDF页面上打印一行。我尝试为此设置绝对坐标,但我的页面为空:

Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
using (var writer = PdfWriter.GetInstance(doc, new FileStream(path + "Report.pdf", FileMode.Create, FileAccess.ReadWrite)))
{ 
    string ttf = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "Futuris Cyrillic.TTF");
    BaseFont baseFont = BaseFont.CreateFont(ttf, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
    iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL);

    doc.Open();
    doc.NewPage();
    doc.Add(new Paragraph("", font));
    PdfContentByte cb = writer.DirectContent;
    LowHatPrint(cb, 1);

    doc.Close();
}

//.......

private void LowHatPrint(PdfContentByte cb, int number)
{
    cb.SetLineWidth(4);
    cb.SetGrayStroke(1);
    cb.MoveTo(0, 0);
    cb.LineTo( 100,  100);
    cb.Stroke();
}

LowHatPrint有什么问题?

1 个答案:

答案 0 :(得分:3)

请设置该行的颜色

cb.SetColorStroke(new BaseColor(255,0,0));