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

Free Support Forum - aspose.com

How to set page numbers for spanning pages

Hi,

I have a pdf document that usually consists of 3 pages with text and table data. The content is generated from user input. Creating the document I call doc.Pages.Add()-functions multiple times to start a new page on predefined points. But sometimes users enter a lot of data and content that should fit on one page is spanning into the next page. But Aspose.Pdf is unaware of this page spanning. It knows only this 3 pages although there are for example 5 pages and page numbers are shown only on this 3 pages. Pages which are created as result of spanning have no page numbers. Can you help me? Here is my simplified code:

        Document doc = new Document();

        Page p = doc.Pages.Add();

        TextStamp footerPageNr = new TextStamp("S. 1");
        footerPageNr.BottomMargin = 10;
        footerPageNr.RightMargin = 10;
        footerPageNr.HorizontalAlignment = HorizontalAlignment.Right;
        footerPageNr.VerticalAlignment = VerticalAlignment.Bottom;


        p.Paragraphs.Add(... some content ...);

        p = doc.Pages.Add();

        p.Paragraphs.Add(... some content that doesn't fit actual page...);

        p = doc.Pages.Add();

        p.Paragraphs.Add(_... some content ..._);


        int cntPages = doc.Pages.Count;
        for (int i = 1; i <= cntPages; i++)
        {
            footerPageNr.Value = "p. " + i + "/" + cntPages;
            doc.Pages[i].AddStamp(footerPageNr);

        }

My Aspose.Pdf version: 10.4.0.0

@wmDB,

You are using quite an old version of the Aspose.Pdf for .NET API and with the latest version 17. 10 of Aspose.Pdf for .NET API, you can call ProcessParagraphs method of the Document instance to get the correct page count. Please download the latest version 17.10 of Aspose.Pdf for .NET API and try the following code:

[C#]

Document doc = new Document();
Aspose.Pdf.Page p = doc.Pages.Add();

TextStamp footerPageNr = new TextStamp("S. 1");
footerPageNr.BottomMargin = 10;
footerPageNr.RightMargin = 10;
footerPageNr.HorizontalAlignment = HorizontalAlignment.Right;
footerPageNr.VerticalAlignment = VerticalAlignment.Bottom;
p.Paragraphs.Add(new TextFragment("... some content..."));
p = doc.Pages.Add();
p.Paragraphs.Add(new TextFragment("... some content that doesn't fit actual page..."));
p = doc.Pages.Add();
p.Paragraphs.Add(new TextFragment("_...some content..._"));
doc.ProcessParagraphs();
int cntPages = doc.Pages.Count;
for (int i = 1; i <= cntPages; i++)
{
    footerPageNr.Value = "p. " + i + "/" + cntPages;
    doc.Pages[i].AddStamp(footerPageNr);
}