Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts

I generate a pdf file using iText sharp. I have Two tables now i want two different tables which is displayed in parallel. how ?. plz help.

Thanks in advance




I already Follow http://www.mikesdotnetting.com/Article/89/iTextSharp-Page-Layout-with-Columns[^] this link ...But not found solutions.Becouse in this link paragraphs devided in the end of page1 and then column2 start , but in my condition i want two tables parallely from 1 page to number of pages .............thanks
Posted
Updated 25-Feb-14 19:47pm
v2

I have find Solution..
C#
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(path + "/TablesSideBySide.pdf", FileMode.Create));
			doc.Open();

			PdfPTable table = new PdfPTable(3);
			table.TotalWidth = 144f;
			table.LockedWidth = true;
			PdfPCell cell = new PdfPCell(new Phrase("This is table 1"));
			cell.Colspan = 3;
			cell.HorizontalAlignment = 1;
			table.AddCell(cell);
			table.AddCell("Col 1 Row 1");
			table.AddCell("Col 2 Row 1");
			table.AddCell("Col 3 Row 1");
			table.AddCell("Col 1 Row 2");
			table.AddCell("Col 2 Row 2");
			table.AddCell("Col 3 Row 2");
			table.WriteSelectedRows(0, -1, doc.Left, doc.Top, writer.DirectContent);


			table = new PdfPTable(3);
			table.TotalWidth = 144f;
			table.LockedWidth = true;
			cell = new PdfPCell(new Phrase("This is table 2"));
			cell.Colspan = 3;
			cell.HorizontalAlignment = 1;
			table.AddCell(cell);
			table.AddCell("Col 1 Row 1");
			table.AddCell("Col 2 Row 1");
			table.AddCell("Col 3 Row 1");
			table.AddCell("Col 1 Row 2");
			table.AddCell("Col 2 Row 2");
			table.AddCell("Col 3 Row 2");
			table.WriteSelectedRows(0, -1, doc.Left + 200, doc.Top, writer.DirectContent);
 
Share this answer
 
v2
Comments
Ashish Rathod-.Net Developer 19-Dec-14 7:42am    
Hello ErBhati,

Your example is really good but i need one question to you that if table 1 store more then data and page break and then store data for table 2 then table 2 data store in second page not store in first page so can u please help me ..
ErBhati 1-Jan-15 3:40am    
Please check Solution 1 comments.I think you find your answer in Charan's Comment
 
Share this answer
 
Comments
ErBhati 26-Feb-14 1:46am    
Mr Kumar
I already Follow http://www.mikesdotnetting.com/Article/89/iTextSharp-Page-Layout-with-Columns[^] this link ...But not found solutions.Becouse in this link paragraphs devided in the end of page1 and then column2 start , but in my condition i want two tables parallely from 1 page to number of pages .............thanks
Charan_Kumar 26-Feb-14 3:00am    
given link clearly specifies...

MultiColumnText columns = new MultiColumnText();

//float left, float right, float gutterwidth, int numcolumns

columns.AddRegularColumns(36f, doc.PageSize.Width-36f, 24f, 2);

Paragraph para = new Paragraph(text, new Font(Font.HELVETICA, 8f));

para.SpacingAfter = 9f;

para.Alignment = Element.ALIGN_JUSTIFIED;

for (int i = 0; i < 8; i++)

{

columns.AddElement(para);

}
doc.Add(columns);
ErBhati 27-Feb-14 1:06am    
Mr Charan
By this code my tables not show proper .I want Two tables Parallels, If they Have data which is show on more than one page........This code shows table[2] when tables[1] data ends......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900