c# - text not wrapping in table cell using iText5 for .NET -
i have function generates text report. list of document text database , create pdf report. pdf report format should follows
logo(top left).........some static text company (top right) [header information is...................................... .........................different each document in list] [.....................document text.............................] date(bottom left) page count(bottom right)
the document text may run more 1 page , in case header information document repeats. and, if document text runs second page , terminates in mid page start next document on new page. here attempt:
public static void printdocument(list<pdfdata> lst, ref memorystream memorystream) { itextsharp.text.font basefontbig = new itextsharp.text.font(itextsharp.text.font.fontfamily.helvetica, 12f, itextsharp.text.font.bold, itextsharp.text.basecolor.black); itextsharp.text.document document = new itextsharp.text.document(pagesize.letter, 40, 25, 30, 30); pdfevents e = new pdfevents(); pdfwriter pw = pdfwriter.getinstance(document, memorystream); pw.pageevent = e; document.open(); (int = 0; < lst.count; i++) { pdfptable maintable = new pdfptable(2); pdfptable outertable = new pdfptable(4); pdfptable contenttable = new pdfptable(1); maintable.keeptogether = true; outertable.widthpercentage = 50; outertable.keeptogether = false; outertable.totalwidth = 550f; float[] sgltblhdwidths = new float[4]; sgltblhdwidths[0] = 5f; sgltblhdwidths[1] = 15f; sgltblhdwidths[2] = 5f; sgltblhdwidths[3] = 5f; outertable.setwidths(sgltblhdwidths); outertable.lockedwidth = true; contenttable.lockedwidth = true; outertable.keeptogether = true; contenttable.widthpercentage = 90; contenttable.keeptogether = false; contenttable.totalwidth = 800f; contenttable.spacingbefore = 30f; string documentidentifier = lst[i].patient; string documentstatus =lst[i].documentstatus; stringbuilder sb = new stringbuilder(); sb.append(lst[i].documenttext); itextsharp.text.paragraph documentstatusp = new itextsharp.text.paragraph(documentstatus, new itextsharp.text.font(itextsharp.text.font.fontfamily.courier, 12, itextsharp.text.font.bold, itextsharp.text.basecolor.black)); itextsharp.text.paragraph patient = new itextsharp.text.paragraph(documentidentifier, new itextsharp.text.font(itextsharp.text.font.fontfamily.courier, 12, itextsharp.text.font.bold, itextsharp.text.basecolor.black)); itextsharp.text.paragraph content = new itextsharp.text.paragraph(sb.tostring(), new itextsharp.text.font(itextsharp.text.font.fontfamily.courier, 10)); itextsharp.text.paragraph empty = new itextsharp.text.paragraph("", new itextsharp.text.font(itextsharp.text.font.fontfamily.courier, 12)); #region content pdfpcell contentcell = new pdfpcell(content); contentcell.border =1; contentcell.verticalalignment = element.align_top; contentcell.horizontalalignment = element.align_left; contenttable.addcell(contentcell); #endregion pdfpcell firstheader = new pdfpcell(empty); firstheader.border = 0; firstheader.fixedheight = 17f; outertable.addcell(firstheader); pdfpcell secondheader = new pdfpcell(patient); secondheader.border = 0; secondheader.fixedheight = 17f; secondheader.verticalalignment = 2; outertable.addcell(secondheader); pdfpcell thirdheader = new pdfpcell(documentstatusp); thirdheader.border = 0; thirdheader.fixedheight = 17f; thirdheader.horizontalalignment = 1; thirdheader.verticalalignment = 2; outertable.addcell(thirdheader); pdfpcell forthheader = new pdfpcell(empty); forthheader.border = 0; forthheader.fixedheight = 17f; outertable.addcell(forthheader); pdfpcell outertblcell = new pdfpcell(outertable); outertblcell.border = 0; pdfpcell contenttblcell = new pdfpcell(contenttable); contenttblcell.border = 0; maintable.addcell(outertblcell); maintable.addcell(contenttblcell); document.add(maintable); if (i != lst.count - 1) document.newpage(); } document.close(); }
this displayed report , required values except in content table when document text has long lines runs out of margins of page , cant see it. there way better achieve this? thanks!
i start fixing margins of page so:
const float leftmargin = 34; const float rightmargin = 34; const float topmargin = 134; const float bottommargin = 36; var document = new document(pagesize.a4, leftmargin, rightmargin, topmargin, bottommargin);
i fix width of table. in case document on portrait a4 page, know max width of page , can subtract margins. build table so:
private pdfptable createtable() { const float tablewidth = 527; var table = new pdfptable(1) { horizontalalignment = element.align_left, totalwidth = tablewidth, lockedwidth = true, splitlate = true, splitrows = true }; return table; }
Comments
Post a Comment