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

Free Support Forum - aspose.com

Pdf.Document method to recalculate/re-stack pages


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#


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();
Row r = new Row();
int i = 0;
while (i < 80)
table.RepeatingRowsCount = 1;

int countbefore = doc.Pages.Count;
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: