我確實在這裏的代碼,我不斷收到錯誤消息:文檔沒有頁面。我還設置了表格寬度和短語,但仍然出現錯誤消息。我現在完全不在了,但我試過尋找其他一些案例,但他們試圖修正它們的設置表格寬度。有什麼我想念的嗎?任何幫助,將不勝感激。謝謝!C# - iTextSharp該文檔沒有頁面
private void printPDF(object sender, EventArgs e)
{
Document docu = new Document(PageSize.LETTER);
PdfWriter writer = PdfWriter.GetInstance(docu, new FileStream("C:\\Report\\" + empno + ".pdf", FileMode.Create));
Phrase phrase = null;
PdfPCell cell = null;
PdfPTable table = null;
BaseColor color = null;
docu.Open();
//Header Table
table = new PdfPTable(2);
table.TotalWidth = 500f;
table.LockedWidth = true;
table.SetWidths(new float[] { 0.3f, 0.7f });
//Company Name and Address
phrase = new Phrase();
phrase.Add(new Chunk("Company Name\n\n", FontFactory.GetFont("Arial", 16, iTextSharp.text.Font.BOLD, BaseColor.ORANGE)));
phrase.Add(new Chunk("Company Address", FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
cell.VerticalAlignment = PdfPCell.ALIGN_TOP;
table.AddCell(cell);
docu.Add(table);
docu.Close();
}
private static PdfPCell PhraseCell(Phrase phrase, int align)
{
PdfPCell cell = new PdfPCell(phrase);
cell.BorderColor = BaseColor.WHITE;
cell.VerticalAlignment = PdfPCell.ALIGN_TOP;
cell.HorizontalAlignment = align;
cell.PaddingBottom = 2f;
cell.PaddingTop = 0f;
return cell;
}
是否有您的printPdf()方法的詳細代碼?除了添加表格並關閉它之外,您似乎沒有對文檔「docu」進行任何操作。是否需要返回給調用者? – njenson