Monday, March 10, 2014

How to Create PDF Using itextsharp in Asp.Net

In this tutorial I am going to explain the process of creating pdf file using itextsharp in using c#.
First of all we will learn how to create static content PDF file using itextsharp . In the upcoming tutorials I will explain how to create PDF using database in and also how to customize the PDF document.

Steps to Create PDF in Using itextsharp:

Step 1: First download the itextsharp dll from this url: Dowload itextsharp.

Step 2: Extract the downloaded file. Inside that there will be multiple zip file. For creating PDF extract the the zip file named itextsharp-dll-core and copy and paste the itextsharp.dll on your desktop.

Step 3: Add new project or add reference to itextsharp.dll in existing project by Right Click on Add Reference as shown below:

add reference in visual studio

Step 4: In Add Reference window Select Browse as shown in the diagram below:

Add Reference to itextsharp

Step 5: Select the itextsharp.dll from desktop and click on ok as shown in the snapshot below:

Reference to itextsharp.dll

Add the following code to Generate PDF:


<html xmlns="">
<head runat="server">
 <form id="form1" runat="server">
 <asp:Button ID="Button1" runat="server" Text="Genrate PDF"
 onclick="Button1_Click" />

Add Reference in Code Behind:

using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;

C # Code:
   protected void Button1_Click(object sender, EventArgs e)
            var doc1 = new Document();

 //Name of the folder into which PDF is to be uploaded
            string pathoffile = Server.MapPath("UploadPDF");

            //Created pdf file with the name test.pdf
            PdfWriter.GetInstance(doc1, new FileStream(pathoffile +" /test.pdf", FileMode.Create ));

            //Open Pdf
            //Add New Paragraph to PDF File
            doc1.Add(new Paragraph("This is your first PDF using itextsharp"));

            //Close the Pdf file


Note: Add UploadPDF folder into your project inside which the pdf would be created.

Hope this has given you basic idea of creating pdf using itextsharp dll.


  1. Nice article I have also taken reference from link below that has demo app with code availaible to download

  2. Best article that I have seen never before like this. Thanks for sharing...
    Asp.Net AJAX Online Training | ASP.NET Training