how to place two tables side by side using itext sharp
11,146
You may need to look at updating your layout to use columns (see here for more details):
http://www.mikesdotnetting.com/Article/89/iTextSharp-Page-Layout-with-Columns
Without seeing more about your layout it's hard to say which column based layout is best.
Alternatively you could absolutely position your tables and write them that way.
As a third option (which is very much like an old html page), you could nest tables like this:
PdfPTable outer = new PdfPTable(2);
outer.AddCell(table1);
outer.AddCell(table2);
document.Add(outer);
Author by
nsds
Updated on June 15, 2022Comments
-
nsds about 2 years
I have to create a pdf file with two tables. and these two table should place horizontally in the document .I have tried out like this ,
var doc1 = new Document(PageSize.A4); PdfWriter.GetInstance(doc1, new FileStream(path + "/" + pdf_name + "", FileMode.Create)); doc1.Open(); var table1 = new PdfPTable(1); //table1 table1.HorizontalAlignment = Element.ALIGN_LEFT; table1.SpacingBefore = 50; table1.DefaultCell.Border = 1; table1.WidthPercentage = 40; PdfPCell cell = new PdfPCell(new Phrase(student_name, boldTableFont)); // cell.Border = 1; // cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right cell.HorizontalAlignment = Element.ALIGN_CENTER; table1.AddCell(cell); doc1.Add(table1); var table2= new PdfPTable(1); //table2 table2.DefaultCell.Border = 1; table2.HorizontalAlignment = 2; table2.SpacingBefore = 50; table2.WidthPercentage = 40; PdfPCell cell21 = new PdfPCell(new Phrase("success", body)); cell21.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right table2.AddCell(cell21); doc1.Add(table2); doc1.Close();
but the second table is not come on the right side of table1 with spacingbefore=50. Please help me for finding out the problem