RadPdfProcessing and nested tables

1 Answer 118 Views
PdfProcessing
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
SSirica asked on 12 Jun 2023, 04:53 PM

When creating a PDF is there a way to nest a table within another table without having to be specific of the tables Y position?  I actually have 3 tables that can look like this:

Table1 - Row1

Table2 - Row1

Table3 - Row1
Table3 - Row2

Table1 - Row2

The number of rows per table is determined by the data, so I don't necessarily know where I am on the page.  Do I have to increase some kind of counter for each line, cause that would be miserable?  I wish there were more extensive examples for creation of Pdf's.  I have seen the Developer Focused examples none of them even come close to what I am trying to accomplish.  

1 Answer, 1 is accepted

Sort by
0
Accepted
Yoan
Telerik team
answered on 15 Jun 2023, 10:01 AM

Hello Steve,

A sub/nested Table can be added to a RadFixedDocument by creating it in the Blocks collection of an already existing table cell:

Table table = new Table();

TableRow firstRow = table.Rows.AddTableRow();
firstRow.Cells.AddTableCell().Blocks.AddBlock().InsertText(" cell1 ");
firstRow.Cells.AddTableCell().Blocks.AddBlock().InsertText(" cell1 ");
            
TableRow secondRow = table.Rows.AddTableRow();
secondRow.Cells.AddTableCell().Blocks.AddBlock().InsertText(" cell2 ");
TableCell cell = secondRow.Cells.AddTableCell();


TableRow thirdRow = table.Rows.AddTableRow();
thirdRow.Cells.AddTableCell().Blocks.AddBlock().InsertText(" cell3 ");
thirdRow.Cells.AddTableCell().Blocks.AddBlock().InsertText(" cell3 ");

AddSubTable(cell);

And this is what the AddSubTable method can look like:

static void AddSubTable(TableCell cell)
{
    Table nestedTable = cell.Blocks.AddTable();

    TableRow firstRow = nestedTable.Rows.AddTableRow();
    firstRow.Cells.AddTableCell().Blocks.AddBlock().InsertText(" Nested cell 1 ");
    firstRow.Cells.AddTableCell().Blocks.AddBlock().InsertText(" Nested cell 2 ");
    firstRow.Cells.AddTableCell().Blocks.AddBlock().InsertText(" Nested cell 3 ");

    TableRow secondRow = nestedTable.Rows.AddTableRow();
    secondRow.Cells.AddTableCell().Blocks.AddBlock().InsertText(" Nested cell 4 ");
    secondRow.Cells.AddTableCell().Blocks.AddBlock().InsertText(" Nested cell 5 ");
    secondRow.Cells.AddTableCell().Blocks.AddBlock().InsertText(" Nested cell 6 ");
}

I am attaching a sample project I created to test this functionally. Please, feel free to modify it in a way closer to your scenario, and feel free to ask questions if you have any.

Hope this helps.

Regards,
Yoan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

SSirica
Top achievements
Rank 3
Iron
Iron
Iron
commented on 15 Jun 2023, 01:29 PM

Thank you Yoan.
Tags
PdfProcessing
Asked by
SSirica
Top achievements
Rank 3
Iron
Iron
Iron
Answers by
Yoan
Telerik team
Share this question
or