Ich verwende iTextSharp, um ein PDF-Dokument zu generieren. Ich konnte eine Tabelle erstellen und hinzufügen. Jetzt möchte ich etwas normalen Text zur PDF hinzufügen. Wie mache ich das? Ich sah online und schlugen sie vor, Stücke verwenden, aber es funktioniert nicht:Hinzufügen von Text zu einer PDF-Datei
Chunk c1 = new Chunk("A chunk represents an isolated string. ");
Dies ist, wie ich die Tabelle wurde hinzugefügt:
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);
}
Wir haben fast gleichzeitig geantwortet ;-) –
;) Ja. Antworten am frühen Morgen ... – mkl