Hi ashhadsaud,
I have created the sample that full-fill your requirement.
HTML
<asp:Button ID="btnModify" Text="Add Data To New Page" runat="server" OnClick="AddDataToNewPage" />
Code
protected void AddDataToNewPage(object sender, EventArgs e)
{
String pathin = @"F:\test.pdf";
String pathout = @"F:\test1.pdf";
PdfReader reader = new PdfReader(pathin);
PdfStamper stamper = new PdfStamper(reader, new FileStream(pathout, FileMode.Create));
PdfPCell cell = null;
PdfPTable table = null;
DataTable dt = GetDataTable();
if (dt != null)
{
Font font8 = FontFactory.GetFont("ARIAL", 7);
Font fontBold = FontFactory.GetFont("ARIAL", 14);
table = new PdfPTable(dt.Columns.Count);
cell = new PdfPCell(new Phrase(new Chunk("CustomerId", fontBold)));
table.AddCell(cell);
cell = new PdfPCell(new Phrase(new Chunk("CompanyName", fontBold)));
table.AddCell(cell);
cell = new PdfPCell(new Phrase(new Chunk("Country", fontBold)));
table.AddCell(cell);
for (int rows = 0; rows < dt.Rows.Count; rows++)
{
for (int column = 0; column < dt.Columns.Count; column++)
{
cell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows][column].ToString(), font8)));
table.AddCell(cell);
}
}
}
ColumnText ct = new ColumnText(stamper.GetOverContent(1));
ct.AddElement(table);
Rectangle rect = new Rectangle(46, 190, 530, 36);
ct.SetSimpleColumn(36, 36, PageSize.A4.Width - 36, PageSize.A4.Height - 175);
ct.Go();
Rectangle rectangle = reader.GetPageSize(1);
int HfPgNumber = 1;
for (int i = 1; i <= Convert.ToInt16(HfPgNumber); i++)
{
stamper.InsertPage(Convert.ToInt16(HfPgNumber + 1), rectangle);
BaseFont font = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
PdfContentByte overContent = stamper.GetOverContent(i + 1);
overContent.SaveState();
overContent.BeginText();
overContent.SetFontAndSize(font, 10.0f);
overContent.SetTextMatrix(100, 750);
overContent.ShowText("This is new text added in page " + (i + 1));
overContent.EndText();
overContent.RestoreState();
}
stamper.Close();
reader.Close();
}
private static PdfPCell PhraseCell(Phrase phrase, int align)
{
PdfPCell cell = new PdfPCell(phrase);
cell.BorderColor = Color.WHITE;
cell.VerticalAlignment = PdfCell.ALIGN_TOP;
cell.HorizontalAlignment = align;
cell.PaddingBottom = 2f;
cell.PaddingTop = 0f;
return cell;
}
private DataTable GetDataTable()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 10 CustomerId, CompanyName, Country FROM Customers"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
con.Open();
sda.SelectCommand = cmd;
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
}
}
}
Screenshot Before

Screenshot After Added
