troubleshooting Question

itextsharp with c#

Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America asked on
C#
3 Comments1 Solution165 ViewsLast Modified:
Below codes are working to me. but I would like to populate field on pdf.
like I have doc.pdf and have field name call 'firstname' and I want to populate value john.
How can I do that?


  protected void Page_Load(object sender, EventArgs e)
        {
ShowPdf(CreatePDF());
}
  private byte[] CreatePDF()
        {
            Document doc = new Document(PageSize.LETTER, 50, 50, 50, 50);

            using (System.IO.MemoryStream output = new MemoryStream())
            {
                PdfWriter wri = PdfWriter.GetInstance(doc, output);
                doc.Open();
                Paragraph header = new Paragraph("End Sheet") { Alignment = Element.ALIGN_CENTER };
                Paragraph paragraph = new Paragraph("Testing the iText pdf.");
                Phrase phrase = new Phrase("This is a phrase but testing some formatting also. \nNew line here.");
                Chunk chunk = new Chunk("This is a chunk.");
                doc.Add(header);
                doc.Add(paragraph);
                doc.Add(phrase);
                doc.Add(chunk);             
                doc.Close();
                return output.ToArray();
            }
        }
        private void ShowPdf(byte[] strS)
        {
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + DateTime.Now);
            Response.BinaryWrite(strS);
            Response.End();
            Response.Flush();
            Response.Clear();
        }
ASKER CERTIFIED SOLUTION
Shalu M

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros