Hi simonoldma,
Change with the below code and check.
C#
protected void AddPageNumber(object sender, EventArgs e)
{
byte[] bytes = File.ReadAllBytes(Server.MapPath("~/PDF/Test.pdf"));
Font blackFont = FontFactory.GetFont("Arial", 12, Font.NORMAL, BaseColor.BLACK);
using (MemoryStream stream = new MemoryStream())
{
PdfReader reader = new PdfReader(bytes);
PdfStamper stamper = new PdfStamper(reader, stream);
int pages = reader.NumberOfPages;
for (int i = 1; i <= pages; i++)
{
ColumnText.ShowTextAligned(stamper.GetUnderContent(i), Element.ALIGN_RIGHT, new Phrase(i.ToString(), blackFont), 568f, 15f, 0);
}
stamper.Close();
stamper.Dispose();
bytes = stream.ToArray();
}
File.WriteAllBytes(Server.MapPath("~/PDF/Test1.pdf"), bytes);
}
VB.Net
Protected Sub AddPageNumber(sender As Object, e As EventArgs)
Dim bytes As Byte() = File.ReadAllBytes(Server.MapPath("~/PDF/Test.pdf"))
Dim blackFont As Font = FontFactory.GetFont("Arial", 12, Font.NORMAL, BaseColor.BLACK)
Using stream As New MemoryStream()
Dim reader As New PdfReader(bytes)
Dim stamper As New PdfStamper(reader, stream)
Dim pages As Integer = reader.NumberOfPages
For i As Integer = 1 To pages
ColumnText.ShowTextAligned(stamper.GetUnderContent(i), Element.ALIGN_RIGHT, New Phrase(i.ToString(), blackFont), 568.0F, 15.0F, 0)
Next
stamper.Close()
stamper.Dispose()
bytes = stream.ToArray()
End Using
File.WriteAllBytes(Server.MapPath("~/PDF/Test1.pdf"), bytes)
End Sub