2
我正在使用iTextSharp創建我的PDF文檔。 一切工作正常,我在代碼中沒有錯誤;然而,當我打開創建PDF時,它給了我錯誤,說該文檔將不能正確顯示,因爲它包含錯誤。iTextSharp一切正常,但打開PDF文檔時出現奇怪的錯誤
這裏是波紋管,該代碼給了我一個問題:
public class pdfevents : PdfPageEventHelper
{
public override void OnEndPage(PdfWriter writer, Document document)
{
base.OnEndPage(writer, document);
PdfContentByte cb = writer.DirectContent;
cb.BeginText();
cb.SetTextMatrix(20, document.GetBottom(-30));
BaseFont bf = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.SetFontAndSize(bf, 10);
//thats is the piece of code that makes problems
//if i remove it then document displays without error
cb.MoveTo(15F, document.GetBottom(-15));
cb.SetLineWidth(0.5F);
cb.LineTo(document.GetRight(0), document.GetBottom(-15));
cb.Stroke();
cb.ShowText(DateTime.Now.ToLongDateString());
int n = writer.PageNumber;
cb.SetTextMatrix(document.GetRight(20), document.GetBottom(-30));
cb.ShowText(" - " + n + " - ");
cb.EndText();
}
}
如果我刪除下面幾行:
//thats is the piece of code that makes problems
//if i remove it then document displays without error
cb.MoveTo(15F, document.GetBottom(-15));
cb.SetLineWidth(0.5F);
cb.LineTo(document.GetRight(0), document.GetBottom(-15));
話,我沒有得到任何錯誤打開生成的PDF,否則我可以打開PDF並查看文檔和它的內容,包括該行。但是,然後我得到錯誤,該文檔已生成錯誤。
有人可以告訴我什麼是錯的?
在此先感謝。 cb.Stroke();