We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Grouping Table Rows

I have a table with several columns.


I have a loop from 1 to 100. Each time in the loop i add three rows.

How can i ensure that those 3 rows are on the same page?

If im at the end of the page and there is no room for row 3, i want to move to the next page and have 1, 2 and 3.

There is a is broken on the row, but that doesn’t help me group the 3 rows.
I can’t add 100 individual tables with 3 rows, because the autofit column logic will not line up the columns correctly.

Any help would be appreciated.

We are looking to switch over and use aspose and getting this to work is a must for our purchase.

Brandon

Hi Brandon,


Thanks for your inquiry. We will appreciate if you please share your sample code here. It would help us to understand correctly your requirement and test the scenario, so we will provide you more information accordingly.

Best Regards,

I created a solution and attached it. I also attached the screenshot of what I would like to accomplish.



Thank you for your help,

Brandon

Hi Brandon,


Thanks for your inquiry. You can accomplish your requirements using nested table in new DOM approach (Aspose.Pdf.Document). Please check following code snippet for the purpose. Hopefully it will serve the purpose.

var _pdf = new Document();<o:p></o:p>

float marginInPixels = (float)(72 * 0.5);

Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();

margin.Top = marginInPixels;

margin.Left = marginInPixels;

margin.Right = marginInPixels;

margin.Bottom = marginInPixels;

_pdf.PageInfo.Margin = margin;

_pdf.PageInfo.Height = Aspose.Pdf.PageSize.PageLetter.Height;

_pdf.PageInfo.Width = Aspose.Pdf.PageSize.PageLetter.Width;

Page section = _pdf.Pages.Add();

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

hTable.Alignment = Aspose.Pdf.HorizontalAlignment.Left;

int groupNumber = 1;

int groupCounter = 0;

for (Int32 i = 0; i <= 500 - 1; i++)

{

groupCounter += 1;

var aRow = hTable.Rows.Add();

var aCell = aRow.Cells.Add();

//Create a table to be nested with the reference of 2nd cell in the row

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

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

tab2.DefaultCellPadding = new Aspose.Pdf.MarginInfo

{

Bottom = 1,

Left = 1,

Right = 1,

Top = 1

};

tab2.Alignment = Aspose.Pdf.HorizontalAlignment.Left;

//Add the nested table into the paragraphs collection of the cell

aCell.Paragraphs.Add(tab2);

for (int cnt = 1; cnt <= 3; cnt++)

{

//Create 1st row in the nested table

Aspose.Pdf.Row row21 = tab2.Rows.Add();

var aCell1 = row21.Cells.Add();

aCell1.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("value 1"));

var aCell2 = row21.Cells.Add();

aCell2.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Group " + groupCounter));

}

}

section.Paragraphs.Add(hTable);

_pdf.Save(myDir+"TestTable_group.pdf");

Please feel free to contact us for any further assistance.


Best Regards,

Thanks for the response. I will check it out.

When building a pdf, I should use Document not PDF under the generators namespace? What is the recommended type and what is the difference?

Thank you,
Brandon

Hi Brandon,


The Document class is present under Aspose.Pdf namespace whereas Pdf class is present under Aspose.Pdf.Generator namespace. Please note that Aspose.Pdf is new Document Object Model (DOM) and we recommend using this approach because all the bug fixing and new features are being introduce under this namespace.

So with nested tables, by default the child table will attempt to stay on the same page without a page break? If you wanted to stop the group and allow the child table to be split what setting would that be?

Hi Brandon,


Thanks for your inquiry. Yes by default nested table data remains on same page and IsBroken property is not working for page break. We have logged a ticket PDFNEWNET-36915 in our issue tracking system for further investigation and resolution. We will notify you as soon as we resolve the issue.

We are sorry for the inconvenience caused.

Best

The issues you have found earlier (filed as PDFNEWNET-36915) have been fixed in Aspose.Pdf for .NET 9.3.0.

Blog post for this release can be viewed over this link


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Brandon,


In reference to above fix, you can use IsRowBroken property to break nested table rows. Please check following code snippet for the purpose.

string outFile =
myDir+“36915.pdf”;<o:p></o:p>

// Added document

var _pdf = new Document();

float marginInPixels = (float)(72 * 0.5);

Aspose.Pdf.MarginInfo margin1 = new Aspose.Pdf.MarginInfo();

margin1.Top = marginInPixels;

margin1.Left = marginInPixels;

margin1.Right = marginInPixels;

margin1.Bottom = marginInPixels;

_pdf.PageInfo.Margin = margin1;

_pdf.PageInfo.Height = Aspose.Pdf.PageSize.PageLetter.Height;

_pdf.PageInfo.Width = Aspose.Pdf.PageSize.PageLetter.Width;

Page section = _pdf.Pages.Add();

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

hTable.Alignment = Aspose.Pdf.HorizontalAlignment.Left;

int groupNumber = 1;

int groupCounter = 0;

for (Int32 i = 0; i <= 50 - 1; i++)

{

groupCounter += 1;

var aRow = hTable.Rows.Add();

//set IsRowBroken property to true to break rows

aRow.IsRowBroken = true;

var aCell = aRow.Cells.Add();

//Create a table to be nested with the reference of 2nd cell in the row

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

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

tab2.DefaultCellPadding = new Aspose.Pdf.MarginInfo

{ Bottom = 1, Left = 1, Right = 1, Top = 1 };

tab2.Alignment = Aspose.Pdf.HorizontalAlignment.Left;

//Add the nested table into the paragraphs collection of the cell

aCell.Paragraphs.Add(tab2);

for (int cnt = 1; cnt <= 34; cnt++)

{ //Create 1st row in the nested table

Aspose.Pdf.Row row21 = tab2.Rows.Add();

var aCell1 = row21.Cells.Add();

aCell1.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("value 1"));

var aCell2 = row21.Cells.Add();

aCell2.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Group " + groupCounter));

}

}

section.Paragraphs.Add(hTable);

_pdf.Save(outFile);

Please feel free to contact us for any further assistance.


Best Regards,