Pdf.Document method to recalculate/re-stack pages

Hi,

I’m creating a new document and adding a table on page 1 with dynamic rows - it depends on the data that is coming, they could be 10 or 1000.
In case of many rows the doc will split to a new page automatically - is there a method that I can call to trigger this?

Currently, after adding those rows I’m calling doc.Save(dummyMemoryStream) and is doing the job, but I’m wondering if there is a better way to do it.

I need to know how many pages are before applying the PageNumberStamp. If I do not do that dummy save the page numbers are not correct.

I’m using Aspose.Pdf v.17.2 C#

@niktv

Thanks for contacting support.

In order to get correct PageCount, you can call Document.ProcessParagraphs method, after which you will get correct count of pages. Please check following sample code snippet, which will demonstrate the required functionality.

Document doc = new Document();
var page = doc.Pages.Add();
Table table = new Table();

Row Header = new Row();
Header.Cells.Add("header");
Header.Cells.Add("header");
table.Rows.Add(Header);
            
Row r = new Row();
r.Cells.Add("Cell");
r.Cells.Add("Cell");
int i = 0;
while (i < 80)
{
 table.Rows.Add(r);
 i++;
}
table.RepeatingRowsCount = 1;
page.Paragraphs.Add(table);

int countbefore = doc.Pages.Count;
doc.ProcessParagraphs();
int countafter = doc.Pages.Count;

doc.Save(dataDir + "PageBreakTable.pdf");

PageCount.png (1.0 KB)

In case of any further assistance, please feel free to let us know.

Thanks that works! :+1: