Display data in two columns in a single row

筅森魡賤 提交于 2019-12-11 10:07:29

问题


I have a datatable containg address of users. I converted it to PDF using iTextSharp and now my requirement is i want to display one user's name, address in one column and another user's name and address in another column. In one row there must be two columns only, how to do this using iTextSharp?


回答1:


Should be just a matter of creating a PdfPTable object and configuring the widths such that each row has 2 columns.

http://www.mikesdotnetting.com/Article/86/iTextSharp-Introducing-Tables

A sample I made from previous code (haven't tried to compile it...)

iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.LETTER, 20, 20, 20, 20);
PdfPTable table;
PdfPCell cell;
iTextSharp.text.Paragraph paragraph;

table = new PdfPTable(2);
paragraph = new Paragraph();
paragraph.Add(new Chunk("TEXT", FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.NORMAL)));
cell = new PdfPCell(paragraph);
cell.BorderWidth = 0;
cell.Padding = 0;
cell.PaddingTop = 12;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
cell = new PdfPCell(paragraph);
cell.BorderWidth = 0;
cell.Padding = 0;
cell.PaddingTop = 12;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
table.AddCell(cell);
table.SetWidthPercentage(new float[2] { 460f, 140f }, PageSize.LETTER);
table.HorizontalAlignment = Element.ALIGN_CENTER;
document.Add(table);


来源:https://stackoverflow.com/questions/1471475/display-data-in-two-columns-in-a-single-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!