Restart page numbering

Hello,
I have different sections in my document,
I want to restart page numbers for each section,
I would like to know how to do it, Is there any property like IsPageNumberRestarted which we used to have in Generator.

I have one solution where I can create new document for each section and merge them later,
but I don’t want to go this way.

Could you please suggest me any another way

Hi Sameer,

Thanks for contacting support.

You can use TextStamp to add page numbers inside PDF document. Please check following code snippet where I have added TextStamps inside PDF document, starting from different number on different pages.

Document doc1 = new Document();

TextStamp pns = new TextStamp("");

pns.BottomMargin = 10;

pns.HorizontalAlignment = HorizontalAlignment.Center;

pns.VerticalAlignment = VerticalAlignment.Bottom;

int i = 1;

while (i < 20)

{

    Page currpage = doc1.Pages.Add();

    currpage.Paragraphs.Add(new TextFragment("This is First Document with Page # " + i));

    pns.Value = i.ToString();

    currpage.AddStamp(pns);

    i++;

}

Document doc2 = new Document();

i = 1;

while (i <= 11)

{

    doc2.Pages.Add().Paragraphs.Add(new TextFragment("This is Second Document with Page # " + i));

    i++;

}

Document doc3 = new Document();

i = 1;

while (i <= 10)

{

    doc3.Pages.Add().Paragraphs.Add(new TextFragment("This is Third Document with Page # " + i));

    i++;

}


int secondDocStart = doc1.Pages.Count + 2;

int secondDocEnd = doc1.Pages.Count + doc2.Pages.Count;

int thirdDocStart = doc1.Pages.Count + doc2.Pages.Count + 2;

int thirdDocEnd = doc1.Pages.Count + doc2.Pages.Count + doc3.Pages.Count;


doc1.Pages.Add(doc2.Pages);

doc1.Pages.Add(doc3.Pages);


i = 1;

for (int a = secondDocStart; a <= secondDocEnd; a++)

{

    pns.Value = i.ToString();

    doc1.Pages[a].AddStamp(pns);

    i++;

}


i = 1;

for (int a = thirdDocStart; a <= thirdDocEnd; a++)

{

    pns.Value = i.ToString();

    doc1.Pages[a].AddStamp(pns);

    i++;

}

doc1.Save(dataDir + "PageNumberStamps.pdf");

For your reference, I have also attached an output generated by above code. In case of any further assistance, please feel free to contact us.

Best Regards,