Click here to Skip to main content
15,437,002 members
Please Sign up or sign in to vote.
1.82/5 (6 votes)
See more:
I am developing a web application in C#. I want to export my data to a pdf file. How can i do that? Plz help me.

Thanking you
Updated 21-Apr-19 8:52am
sravani.v 16-May-12 6:58am    
What data you want to export(gridview or else..)?
jagadeeshmn 16-May-12 7:02am    
GRID VIEW..sry for not mentioning in the question
Deepika615 15-Jun-15 2:50am    
is there any solution without using itextSharp?
[no name] 19-Apr-19 11:42am    
Hello! I would like to recommend I used it to export my data to a pdf file. It's really convenient and easy to use. Go check the website for more information. It helped a lot!
Fikri AZR 10-Jan-20 6:24am    
how to use ?

ITextSharp[^] is a good API for this kind of tasks. Here[^] is a good tutorial on how to export some data to PDF using this API.
Share this answer
Share this answer
Prasad_Kulkarni 23-May-12 0:41am    
Good links 5!
P.Salini 23-May-12 4:52am    
Thank you Prasad.
Here are the samples on

Exporting a DataGridView to an Excel/PDF/image file by using Reporting Services report generation:
Exporting a DataGridView to an Excel/PDF/image file by using Reporting Services report generation[^]

Creating PDF Tables using C# (.NET 2.0) and iTextSharp:
Creating PDF Tables using C# (.NET 2.0) and iTextSharp[^]

Tutorials on creating PDF files using C# 2.0:
Tutorials on creating PDF files using C# 2.0[^]

If you have any questions, please feel free to tell us.
Share this answer
Prasad_Kulkarni 19-Jul-12 4:51am    
Good links +5!
Member 10378236 4-Nov-13 3:30am    
Same thing i wana do with panel, I wanto export all contect of a particular panel.
Refer this, if you get some needful..

protected void ExportToPDF(object sender, EventArgs e)
    //Get the data from database into datatable
    string strQuery = "select CustomerID, ContactName, City, PostalCode" + 
      " from customers";
    SqlCommand cmd = new SqlCommand(strQuery);
    DataTable dt = GetData(cmd);
    //Create a dummy GridView
    GridView GridView1 = new GridView();
    GridView1.AllowPaging = false;
    GridView1.DataSource = dt;
    Response.ContentType = "application/pdf";
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
Share this answer
jdang 19-Oct-12 12:19pm    
Is PdfWrtier free?
Member 11210751 7-Jan-15 2:21am what is the Htmltextwriter and they are class names.if its classes what i wrote the code in that classes?please give me the answer as soon as possible
First u export PDF file in your data,

The best idea for create crystal report used expert option.
Share this answer
You can use free print to PDF software, like cutePDF printer (not writer!!!)....
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900