Nested Table using Aspose.Pdf.Document

Hello,

How to create Nested table using Aspose.Pdf.Document?

I’ve seen the below example which use the old Aspose.Pdf.Generator.

http://www.aspose.com/docs/display/pdfnet/Create+Nested+Table

Is there an example shows how this is been done in new Aspose.Pdf.Document ?

Thanks

Sree

Hi Sree,


Thanks for contacting support.

Please try using following code snippet to accomplish your requirement.

For your reference, I have also attached the PDF document generated over my end.

[C#]

Aspose.Pdf.Document pdf1 = new Document();<o:p></o:p>

Page page = pdf1.Pages.Add();

Aspose.Pdf.Table mainTable1 = new Aspose.Pdf.Table();

// mainTable1.ColumnAdjustment = ColumnAdjustment.AutoFitToContent;

mainTable1.ColumnWidths = "100 200";

mainTable1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5f, Aspose.Pdf.Color.YellowGreen);

Aspose.Pdf.Row row11 = mainTable1.Rows.Add();

Aspose.Pdf.Cell cell11 = row11.Cells.Add("Cell1"), cell21 = row11.Cells.Add();

cell11.BackgroundColor = Aspose.Pdf.Color.Pink;

Aspose.Pdf.Table nestedTable1 = new Aspose.Pdf.Table();

// if we comment out nested table border setting code then api throws following exception

nestedTable1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5f, Aspose.Pdf.Color.Blue);

nestedTable1.ColumnWidths = "100 100";

cell21.Paragraphs.Add(nestedTable1);

Aspose.Pdf.Row nestedRow11 = nestedTable1.Rows.Add(), nestedRow21 = nestedTable1.Rows.Add();

nestedRow11.Cells.Add("nested table header").ColSpan = 2;

nestedRow21.Cells.Add("nested cell 1");

nestedRow21.Cells.Add("nested cell 2");

page.Paragraphs.Add(mainTable1);

pdf1.Save("c:/pdftest/nestedtable11.pdf");