I want to insert given text to existing pdf at X,Y location provided.
I am using iTextSharp(4.1.6.0) for it
I am accepting the location(to insert the text at) and the value to be inserted there, in the datagridview control , The text is getting inserted at the specified position only when the location specified has no image.
The contents are not being inserted at the location which has image in the input pdf.
Is there any different way to add text to existing pdf so that the text will be inserted at the location specified irrespective of the existence of image.
Please find my code below:
for (int i = 0; i < reader.NumberOfPages; i++)
{
document.NewPage();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
gridColumn = Convert.ToInt32(row.Cells[2].Value);
if (gridColumn == i + 1)
{
//document.NewPage();
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.SetColorFill(iTextSharp.text.Color.BLACK);
cb.SetFontAndSize(bf, 8);
text = "" + row.Cells[3].Value;
cb.BeginText();
cb.ShowTextAligned(2, text, Convert.ToSingle(row.Cells[0].Value), Convert.ToSingle(row.Cells[1].Value), 0);
cb.EndText();
page = writer.GetImportedPage(reader, Convert.ToInt32(row.Cells[2].Value));
cb.AddTemplate(page, 0, 0);
}
else
{
page = writer.GetImportedPage(reader, i + 1);
cb.AddTemplate(page, 0, 0);
}
}//end foreach
}//end for i
PdfContentByte
? Did you make sure you get it by usingPdfStamper.GetOverContent
and notPdfStamper.GetUnderContent
? – Alexis Pigeon