How to Create PDF Document Using ITextSharp in Asp.Net C#

PDF Generate


C# Coding

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;

public partial class PDF : System.Web.UI.Page

    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter adp;
    SqlDataReader rd;
    DataSet ds;
    string query;

    public void dbcon()
        string connn = (System.Configuration.ConfigurationManager.ConnectionStrings["dbcon"].ToString());
        con = new SqlConnection(connn);


    protected void Page_Load(object sender, EventArgs e)

    public override void VerifyRenderingInServerForm(Control control)

    protected void Button1_Click(object sender, EventArgs e)
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Add(new Paragraph("Welcome to dotnetdrizzles"));
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition""attachment;" +


First Create new Webform  - insert values to Database Table - show the data from Gridview

Next download Itextsharp from  below link 

Above Link  Download  itextsharp.dll  File to your  Computer

Select Web form-Select Add Reference - Browse & select iTextsharp.dll file

 Next - Itextsharp Files add to bin

          Next - ItextSharp  Library files Calls to Namespaces

                                      Server Render control

PDF Generate Coding

Click - F5 Button  - Run the program

Select - PDF Generate Button 




Post a Comment