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

Free Support Forum - aspose.com

Table does not break correctly if it is broken after the header and the first row is repeating

Hi! I have an issue with Aspose PDF 8.0. I set the RepeatingRows to 1 (setting IsFirstRowRepeated to true gives the same output) but my table is broken right after the header but the header is not repeated on the next page. Having just the header of the table on a page without any data row would not be accepted by my client so the table should not be broken in this case. I have attached the resulting PDF for the code below which reproduces the problem :

public static void FirstRowNotRepeatedOnTableBreakWhenTableIsBrokenAfterHeader()
{
Pdf pdf = new Pdf();
Section section = new Section(pdf);
section.IsLandscape = true;
pdf.Sections.Add(section);
for (int i = 0; i < 36; i++)
{
section.Paragraphs.Add(new Text("Line " + i));
}
Table t = new Table();
t.ColumnWidths = “50% 50%”;
t.RepeatingRows = 1;
//t.IsFirstRowRepeated = true;
Row row = t.Rows.Add();
row.BackgroundColor = new Color(“LightGray”);
row.Cells.Add(“Header 1”);
row.Cells.Add(“Header 2”);
for (int i = 0; i < 5; i++)
{
row = t.Rows.Add();
row.Cells.Add(“Data 1-” + i);
row.Cells.Add(“Data 2-” + i);
}
section.Paragraphs.Add(t);
string filename = @“d:\FirstRowNotRepeatedOnTableBreakWhenTableIsBrokenAfterHeader.pdf”;
pdf.Save(filename);
Process.Start(filename);
}

Thanks,

Jean-François Rouleau

Hi Jean-François,


Thanks for using our products.

In order to generate the correct output where table header and its contents are placed together on PDF file, you need to set the value of IsKeptWithNext to true. Or you can set the value of IsBroken property of Table class true so that rows of table are not broken when table reaches at the end of page.

For your reference, I have also attached the resultant PDF which is generated over my end. In case I am not able to properly understand the requirement, please share some further details.

Hi! I can understand why you thought I needed the IsKeptWithNext or IsBroken property: my sample was not clear.

My table is multiple pages long so I want the table to be broken. I have updated my sample code to produce 2 PDFs: HeaderRepeatedCorrectly.pdf shows what I want but FirstRowNotRepeatedOnTableBreakWhenTableIsBrokenAfterHeader.pdf shows the edge case where the only thing that fits on the first page is the header row. We can observe in this PDF that the first line of the second page is bold (the header should be there I guess) and that the first line of the 3rd page is actually the first data row! It seems that the first data row is used instead of the header row.

As stated in my original post, the properties RepeatingRows = 1 and IsFirstRowRepeated = true produce the same result.

Here is the updated sample:

public static void FirstRowNotRepeatedOnTableBreakWhenTableIsBrokenAfterHeader()
{
const int FirstRowRepeatedAsExpected = 34;
const int FirstRowNotRepeatedButFirstDataRowIsUsedInstead = 36;
foreach (int testParam in new int[] { FirstRowRepeatedAsExpected, FirstRowNotRepeatedButFirstDataRowIsUsedInstead })
{
Pdf pdf = new Pdf();
Section section = new Section(pdf);
section.IsLandscape = true;
pdf.Sections.Add(section);

for (int i = 0; i < testParam; i++)
{
section.Paragraphs.Add(new Text("Line " + i));
}
Table t = new Table();
t.ColumnWidths = “50% 50%”;
// Both properties should be equivalent and executing the sample code shows that the effect is the same
//t.RepeatingRows = 1;
t.IsFirstRowRepeated = true;
Row row = t.Rows.Add();
row.BackgroundColor = new Color(“LightGray”);
row.Cells.Add(“Header 1”);
row.Cells.Add(“Header 2”);
for (int i = 0; i < 50; i++)
{
row = t.Rows.Add();
row.Cells.Add(“Data 1-” + i);
row.Cells.Add(“Data 2-” + i);
}
section.Paragraphs.Add(t);
string filename = testParam == FirstRowNotRepeatedButFirstDataRowIsUsedInstead ?
@“d:\FirstRowNotRepeatedOnTableBreakWhenTableIsBrokenAfterHeader.pdf” : @“d:\HeaderRepeatedCorrectly.pdf”;
pdf.Save(filename);
Process.Start(filename);
}
}

Hi there,


Sorry for the delayed response. We have replicated the issue and logged as PDFNEWNET-35352 in our issue tracking system for further investigation and resolution. We will keep you updated about issue progress via this forum thread.

Please feel free to contact us for any further assistance.

Best Regards,

Hi there,

Thanks for your patience. Please use following code snippet of new generator(Aspose.Pdf.Document). Now its working as expected.

Moreover, I want to update you that we are making improvements/enhancements in new DOM approach and not working over Aspose.Pdf.Generator, as its obsolete now.

const int FirstRowRepeatedAsExpected = 66;
const int FirstRowNotRepeatedButFirstDataRowIsUsedInstead = 68;
foreach (int testParam in new int[] { FirstRowRepeatedAsExpected, FirstRowNotRepeatedButFirstDataRowIsUsedInstead })
{
Document pdf = new Document();
Page page = pdf.Pages.Add();
page.PageInfo.IsLandscape = true;
for (int i = 0; i < testParam; i++)
{
page.Paragraphs.Add(new TextFragment("Line " + i));
}
Aspose.Pdf.Table t = new Aspose.Pdf.Table();
t.ColumnWidths = “50% 50%”;
// Both properties should be equivalent and executing the sample code shows that the effect is the same
//t.RepeatingRows = 1;
// t.IsKeptWithNext = true;
t.RepeatingRowsCount = 1;
Aspose.Pdf.Row row = t.Rows.Add();
row.BackgroundColor = Aspose.Pdf.Color.LightGray;
row.Cells.Add(“Header 1”);
row.Cells.Add(“Header 2”);
for (int i = 0; i < 50; i++)
{
row = t.Rows.Add();
row.Cells.Add(“Data 1-” + i);
row.Cells.Add(“Data 2-” + i);
}
page.Paragraphs.Add(t);
string filename = testParam == FirstRowNotRepeatedButFirstDataRowIsUsedInstead ?
myDir+“FirstRowNotRepeatedOnTableBreakWhenTableIsBrokenAfterHeader.pdf” : myDir+“HeaderRepeatedCorrectly.pdf”;
pdf.Save(filename);
Process.Start(filename);
}

Please feel free to contact us for any further assistance.

Best Regards,a

Hi! I looked at the result but the header row is on the first page without any data row. I know my client won’t accept this and to me, this is still a bug.


Is the issue closed on your side?

Thanks,

Jean-François Rouleau

Hi Jean-François,


We have further investigated this issue and have developed a new code snippet. Can you please take a look over attached PDF file and confirm it fulfills your requirement. The output is based on upcoming release version of Aspose.Pdf for .NET 8.1.0.

[C#]

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

Page page = doc.Pages.Add();

page.PageInfo.IsLandscape = true;

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

{ page.Paragraphs.Add(new TextFragment("Line " + i)); }

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

t.ColumnWidths = "50% 50%";

t.RepeatingRowsCount = 1;

Aspose.Pdf.Row row = t.Rows.Add();

row.BackgroundColor = Aspose.Pdf.Color.LightGray;

row.Cells.Add("Header 1");

row.Cells.Add("Header 2");

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

{ row = t.Rows.Add(); row.Cells.Add("Data 1-" + i); row.Cells.Add("Data 2-" + i); }

page.Paragraphs.Add(t);

doc.Save(“c:/pdftest/TableBreakIssue.pdf”);

Hi! I looked at the result but the header row is on the first page without any data row. I know my client won’t accept this and to me, this is still a bug.


If the only row that appears on the page is the header row, do not show the header row, just add a page break so the table starts on the next page because here is not enough room on the first page.

Is the issue closed on your side?

Thanks,

Jean-François Rouleau
jeanfrancoisrouleau:
Hi! I looked at the result but the header row is on the first page without any data row. I know my client won't accept this and to me, this is still a bug.

If the only row that appears on the page is the header row, do not show the header row, just add a page break so the table starts on the next page because here is not enough room on the first page.
Hi Jean-François,

I have again tested the code snippet shared over 470889 post and as per my observations, the header row on first page also contains its related rows and table is breaking properly as specified in PDF document which you have shared HeaderRepeatedCorrectly.pdf. Can you please take a look over attached PDF file and confirm if the output being generated is correct ?

jeanfrancoisrouleau:
Is the issue closed on your side?
The issue is not yet closed. Please note that until or unless the customer's requirement is satisfied, we do not close the issue.

Yes the output is correct so the only case left to correct is the case where the only space available for the table is for the header row. A table with only a header row on a page should not happen.

Thanks,

Jean-François Rouleau

Hi Jean-François,


Thanks for your acknowledgement.

We are working on fixing the scenario where if the only space available for the table is for the header row, the table with only a header row on a page should not appear. As soon as we have some updates regarding its resolution, we would be more than happy to update you with the status of correction.

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


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