Thanks for contacting support.
In order to achieve custom numbering of the pages inside a PDF, you can use TextStamp. Please check following code snippet where I have implement the custom numbering in a PDF as per your requirement.
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, an output generated by above code, is also attached. In case of any further assistance, please feel free to contact us.
Best Regards,