How to Create or Modify PDF Form in ASP.net
Written by David Bauernschmidt Monday, 4 March 2013
It seems like regularly something comes up in the programming world that is requested by a client that should be easy, ends up proving to take more time, more money or both. So it is nice to find a solution to a problem that IS easy. This article is to show you how easy it is to use ASP.net web form to open up a PDF, set a value on a form and then send it back to the user’s browser. I have attached the project below if you want to download it. The first thing you need to do is go download iTextSharp.dll. I will be using visual basic (vb) for this project.
Step 1: Start VS 2012
Step 2: Create a new project
Step 3: Add the iTextSharp.dll reference that you downloaded from above.
Step 4: Create a new web page
Step 5: Add this to the code behind for the .aspx page created in step 4
Dim var As New iTextSharp.text.pdf.PdfReader(Server.MapPath("~/SamplePDF.pdf")) Dim output As New MemoryStream() Dim stamper As New iTextSharp.text.pdf.PdfStamper(var, output) stamper.AcroFields.SetField("Name", "Fred Flinstone") stamper.AcroFields.SetField("chk_Cash", "Yes") 'Match its export value ' Form fields should no longer be editable stamper.FormFlattening = True stamper.Close() var.Close() Response.AddHeader("Content-Disposition", "attachment; filename=YourPDF.pdf") Response.ContentType = "application/pdf" Response.BinaryWrite(output.ToArray()) Response.End()
Although this is very simple application you can take it and run with it. You can download the project from here.
Looking for quality web hosting? Look no further than Arvixe Web Hosting!