Am using the below code for replace image and text on pdf, its is good working on the image replace part, but i dont know the how can write the text replace in same code.
private void AddAnImage() { string qrfile = qrcode(); using (var inputPdfStream = new FileStream(Server.MapPath("PDF/input.pdf"), FileMode.Open)) using (var inputImageStream = new FileStream(qrfile, FileMode.Open)) using (var outputPdfStream = new FileStream(Server.MapPath("PDF/output.pdf"), FileMode.Create)) { PdfReader reader = new PdfReader(inputPdfStream); PdfStamper stamper = new PdfStamper(reader, outputPdfStream); PdfContentByte pdfContentByte = stamper.GetOverContent(1); var image = iTextSharp.text.Image.GetInstance(inputImageStream); image.SetAbsolutePosition(50, 75); pdfContentByte.AddImage(image); PdfContentByte canvas = stamper.GetOverContent(2); ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(DateTime.Now.ToShortDateString()), 0, 0, 0); stamper.Close(); } }
I have worked with iText with vb previously and I used code similar to below to build up pdf files on the fly.
Dim doc As Document = New Document
Dim txt_JourneyLabel As New Chunk()
txt_JourneyLabel = New Chunk("SOME TEXT HERE", font_courier)
doc.Add(New Paragraph(txt_JourneyLabel
This may not be the most efficient piece of code ever written but it does work.
Rgds,
Jonathan