How to Create or Modify PDF Form in ASP.net

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.

DOWNLOAD

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , | Posted under 3rd Party Software, ASP .NET 2, ASP .NET 3.5, ASP .NET 4.0, DotNet/Windows Hosting | RSS 2.0

Author Spotlight

David Bauernschmidt

David Bauernschmidt

I live in the historical triangle of Virginia where I am married with two daughters. I have spent over 13 years working for a Fortune 500 company in the computer area. I started in VB 6.0 and by the time I ended my employment I was supervising a development team where we built many web applications. When my first daughter was born I wanted to spend more time with her so I left and became a programmer analyst for local government as well as launch my own company. Since then I have grown James River Webs into a profitable web design and application company helping small businesses create a big presence on the internet. As an employee I have created web application used by citizens and other companies. I enjoy fly fishing, and spending time with my family. I also enjoy learning new approaches and development tools when it comes to developing applications.

Leave a Reply

Your email address will not be published. Required fields are marked *


8 × = 16

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>