How to re-paginate a PDF

I am creating a PDF using ASPOSE PDF .NET. What I did was to create 1 page [doc.PageInfo.Height = 10000;] and then add/append tables to it. Then at the end - how do I re-paginate the 1 page so it is broken into several A4 size pages.?

Hi Mar,

Thanks for contacting support.

Aspose.Pdf for .NET automatically adds new page(s) into document, if content of the document does not fit on one page. Which means you do not need to specify height of a page, if you are going to add a long table, so that you will not have to split the page later.

Furthermore, please check following code snippet where I have added only one page in document and also added a table with enough rows, so that API will break it into parts and shift to new added pages automatically. Later, you can set the height and width of the page(s) as of A4 size as I did below for your reference.

Document doc = new Document();

doc.Pages.Add();

Table tb = new Table();

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

{

    Row row = new Row();

    tb.Rows.Add(row);

    Cell cell = row.Cells.Add();

    cell.Border = new BorderInfo { Top = new GraphInfo { Color = Color.Black, LineWidth = 1 }, Left = new GraphInfo { Color = Color.Black, LineWidth = 1 }, Right = new GraphInfo { Color = Color.Black, LineWidth = 1 } };

    cell.Paragraphs.Add(new TextFragment("Test Cell"));

}

doc.Pages[1].Paragraphs.Add(tb);

foreach (Page page in doc.Pages)

{

    page.PageInfo.Height = PageSize.A4.Height;

    page.PageInfo.Width = PageSize.A4.Width;

}

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

Please try using above approach to add your table inside a document and in case if you still face any issue, please feel free to contact us.

Best Regards,