Table break issue

Hi,

I have a table to hold the title and content. The requirement is when the space of a page can only contain the title, put the title and the content together in the next page. I used the below code snippet to simulate my requirement. When numberOfLine is set to 55, there is an error message popup when open the TableAndContent.pdf file. The file is attached for your reference.

I tried to use IsFirstRowRepeated and IsKeptTogether but cannot make it.

Please advice how can I achieve this. Thanks a lot.

Regards,
Iris

private void CreatePDF()
{
Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section _sec = pdf1.Sections.Add();
_sec.Paragraphs.Add(NewTable(1));
_sec.Paragraphs.Add(NewTable(2));
pdf1.Save(@“C:\temp\TableAndContent.pdf”);
}
private Aspose.Pdf.Generator.Table NewTable(int idx)
{
int numberOfLine = 55;
Aspose.Pdf.Generator.Table tab = new Aspose.Pdf.Generator.Table();
tab.ColumnWidths = “250”;
tab.Border = new Aspose.Pdf.Generator.BorderInfo()
{
Right = new Aspose.Pdf.Generator.GraphInfo() { LineWidth = 0.1F, Color = new Aspose.Pdf.Generator.Color(“Black”) },
Left = new Aspose.Pdf.Generator.GraphInfo() { LineWidth = 0.1F, Color = new Aspose.Pdf.Generator.Color(“Black”) },
Bottom = new Aspose.Pdf.Generator.GraphInfo() { LineWidth = 0.1F, Color = new Aspose.Pdf.Generator.Color(“Black”) },
Top = new Aspose.Pdf.Generator.GraphInfo() { LineWidth = 0.1F, Color = new Aspose.Pdf.Generator.Color(“Black”) }
};
//tab.IsFirstRowRepeated = true;
// tab.IsKeptTogether = true;
tab.IsKeptWithNext = true;
Aspose.Pdf.Generator.Row rowTitle = tab.Rows.Add();
rowTitle.BackgroundColor = new Aspose.Pdf.Generator.Color(“LightGray”);
rowTitle.Cells.Add("Table " + idx.ToString());
Aspose.Pdf.Generator.Row rowContent = tab.Rows.Add();
rowContent.BackgroundColor = new Aspose.Pdf.Generator.Color(“White”);
//row.Cells.Add("Content Row ");
Aspose.Pdf.Generator.Cell contentCell = rowContent.Cells.Add();
// contentCell.Paragraphs.Add(new Aspose.Pdf.Generator.Text(“Content Row”));
Aspose.Pdf.Generator.Table tabContent = new Aspose.Pdf.Generator.Table();
tabContent.ColumnWidths = “125 125”;
contentCell.Paragraphs.Add(tabContent);
Aspose.Pdf.Generator.Row row = tabContent.Rows.Add();
row.BackgroundColor = new Aspose.Pdf.Generator.Color(“LightGray”);
row.Cells.Add(“Header 1”);
row.Cells.Add(“Header 2”);
for (int i = 0; i < numberOfLine * idx; i++)
{
row = tabContent.Rows.Add();
row.Cells.Add(“Data 1-” + i);
row.Cells.Add(“Data 2-” + i);
}

return tab;
}

Hi Iris,

Sorry for the inconvenience faced.

While using the latest version of Aspose.Pdf for .NET 8.5.0, I’ve managed to reproduce
this issue on my side and logged it in our bug tracking system as PDFNEWNET-36021
for further investigation and resolution. We’ll keep you updated about the issue progress via this forum thread.

Please feel free to contact us for any further assistance.

Best Regards,

Thanks Tilal.


My client’s requirement is: If a single line content doesn’t fit in the same page right after the heading, place the heading and content together in the new page. In the current version of Aspose.Pdf, is there a way to achieve this?

Regards,
Iris

Hi Iris,


Thanks for providing additional information. We’ve recorded and shared your requirement with development team. We will notify you as soon as we resolve the issue.

We are sorry for the inconvenience caused.

Best Regards,

IrisWu: If a single line of content doesn’t fit on the same page right after the heading, place the heading and content together on the new page.

Hi Iris,

As per my understanding, your requirement is that if the contents of a subsequent table cannot be accommodated on the first page, the Header/Heading row should appear on the subsequent page along with other table contents (rows). If that is the case, then please note that IsKeptWithNext supports the feature to display the table on the subsequent page if its contents cannot be accommodated on the current page. I am afraid that currently this property is causing problems. We will further investigate the issue during the resolution of PDFNEWNET-36021.

IrisWu: In the current version of Aspose.Pdf, is there a way to achieve this?

Besides using Aspose.Pdf.Generator approach, I would suggest you to please try using the DOM approach of the Aspose.Pdf namespace. However, when using this approach, another issue (i.e., the Header of the subsequent table is not appearing) occurs. For the sake of correction, I have separately logged it in our issue tracking system as PDFNEWNET-36036. We will investigate this issue in detail and will keep you updated on the status of a correction.

We apologize for your inconvenience.

[C#]

Aspose.Pdf.Document pdfdoc = new Aspose.Pdf.Document();
pdfdoc.Pages.Add();
pdfdoc.Pages[1].Paragraphs.Add(DOMNewTable(1));
pdfdoc.Pages[1].Paragraphs.Add(new TextFragment(" "));
pdfdoc.Pages[1].Paragraphs.Add(DOMNewTable(2));
pdfdoc.Save("c:/pdftest/DOM_Approach.pdf");

private Aspose.Pdf.Table DOMNewTable(int idx)
{
    int numberOfLine = 55;

    Aspose.Pdf.Table tab = new Aspose.Pdf.Table();
    tab.ColumnWidths = "250";
    tab.Border = new Aspose.Pdf.BorderInfo()
    {
        Right = new Aspose.Pdf.CellBorderStyle(Aspose.Pdf.Color.Black),
        Left = new Aspose.Pdf.CellBorderStyle(Aspose.Pdf.Color.Black),
        Top  = new Aspose.Pdf.CellBorderStyle(Aspose.Pdf.Color.Black),
        Bottom = new Aspose.Pdf.CellBorderStyle(Aspose.Pdf.Color.Black)
    };

    // tab.IsKeptTogether = true;
    tab.IsKeptWithNext = true;

    Aspose.Pdf.Row rowTitle = tab.Rows.Add();
    rowTitle.BackgroundColor = Aspose.Pdf.Color.LightGray;
    rowTitle.Cells.Add("Table " + idx.ToString());

    Aspose.Pdf.Row rowContent = tab.Rows.Add();
    rowContent.BackgroundColor = Aspose.Pdf.Color.White;

    //row.Cells.Add("Content Row");
    Aspose.Pdf.Cell contentCell = rowContent.Cells.Add();

    //   contentCell.Paragraphs.Add(new Aspose.Pdf.Generator.Text("Content Row"));

    Aspose.Pdf.Table tabContent = new Aspose.Pdf.Table();
    tabContent.ColumnWidths = "125 125";
    contentCell.Paragraphs.Add(tabContent);

    Aspose.Pdf.Row row = tabContent.Rows.Add();
    row.BackgroundColor = Aspose.Pdf.Color.LightGray;
    row.Cells.Add("Header 1");
    row.Cells.Add("Header 2");

    for (int i = 0; i < numberOfLine * idx; i++)
    {
        row = tabContent.Rows.Add();
        row.Cells.Add("Data 1-" + i);
        row.Cells.Add("Data 2-" + i);
    }

    return tab;
}

Thanks Nayyer.


Let me clarify my client’s requirement. If space left in the current page can only show the title without any content, then the title should come with the content in the next page. However, if the space can show the title and at least one line of content, then keep the title and content in the current page, and the subsequent content in the next page. If I used IsKeptWithNext ,then the title would go with the content in the next page although there is space in the current page for the title and part of the content.


Regards,
Iris

Hi Iris,


Thanks for sharing additional information. Definitely it will help us to resolve the issue and meet your requirements. As soon as issue is resolved, we will update you via this forum thread.

Thanks for your patience and cooperation.

Best Regards,

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


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

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


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

Hi Iris,


Thanks for your patience.

In order to resolve the problems reported earlier, please try using the new Document Object Model of Aspose.Pdf namespace. For further details, please visit Working with Tables