我正在使用iTextSharp生成PDF文檔。我能夠創建並添加一個表格。現在我想給PDF添加一些正常文本。我怎麼做?我在網上看了一下,他們建議使用大塊,但它不工作:將文本添加到PDF
Chunk c1 = new Chunk("A chunk represents an isolated string. ");
這是我是如何將表:
private byte[] CreatePDFFile(StudentJournalAdd studentjournal, SearchResult<JournalAttendanceStatus> StatusList, string studentName)
{
var normalFont = FontFactory.GetFont(FontFactory.HELVETICA, 12);
var boldFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12);
string Details = string.Empty;
int icount = 0;
bool bflag = false;
PdfPTable table = new PdfPTable(3);
table.TotalWidth = 550f;
table.LockedWidth = true;
float[] widths = new float[] { 10f, 20f, 10f };
table.SetWidths(widths);
table.HorizontalAlignment = 1;
table.SpacingBefore = 20f;
table.SpacingAfter = 30f;
table.DefaultCell.PaddingTop = 2f;
table.DefaultCell.PaddingBottom = 2f;
//PdfPCell cellHeading = new PdfPCell(new Phrase("AdminNo - " + studentjournal.StudentJournaldtls.AdminNo + " (WeekNo) - " + studentjournal.StudentJournaldtls.WeekNo + "\n\n", boldFont));
PdfPCell cellHeading = new PdfPCell(new Phrase("Temasek Polytechnic - Student Internship Programme Journal\n\n " + studentName + " (" + studentjournal.StudentJournaldtls.AdminNo + ")\n\n Week No: " + studentjournal.StudentJournaldtls.WeekNo + "\n\n" + "DAILY/WEEKLY SUMMARY OF TASKS" + "\n\n", boldFont));
cellHeading.Colspan = 3;
cellHeading.Rowspan = 2;
cellHeading.Border = 0;
cellHeading.HorizontalAlignment = 1;
cellHeading.VerticalAlignment = Element.ALIGN_MIDDLE;
table.AddCell(cellHeading);
PdfPCell cell0 = new PdfPCell(new Phrase("Day", boldFont));
cell0.PaddingBottom = 10f;
cell0.VerticalAlignment = Element.ALIGN_CENTER;
cell0.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell0);
PdfPCell cell1 = new PdfPCell(new Phrase("Task Assigned", boldFont));
cell1.PaddingBottom = 10f;
cell1.VerticalAlignment = Element.ALIGN_CENTER;
cell1.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell1);
PdfPCell cell2 = new PdfPCell(new Phrase("Attendance", boldFont));
cell2.PaddingBottom = 10f;
cell2.VerticalAlignment = Element.ALIGN_CENTER;
cell2.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell2);
}
我們幾乎同時回答;-) –
;)是的。清晨的答案... – mkl