Click here to Skip to main content
14,392,909 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi
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
Posted
Updated 21-Apr-19 9:52am
Comments
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 ZetPDF.com. 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!
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

   
v3
Comments
Prasad_Kulkarni 23-May-12 0:41am
   
Good links 5!
P.Salini 23-May-12 4:52am
   
Thank you Prasad.
Rate this:
Please Sign up or sign in to vote.

Solution 5

Here are the samples on codeproject.com:

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.
   
Comments
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.
Rate this:
Please Sign up or sign in to vote.

Solution 6

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;
    GridView1.DataBind();
 
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", 
      "attachment;filename=DataTable.pdf");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);
    GridView1.RenderControl(hw);
    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);
    pdfDoc.Open();
    htmlparser.Parse(sr);
    pdfDoc.Close();
    Response.Write(pdfDoc);
    Response.End();  
}
   
v2
Comments
jdang 19-Oct-12 12:19pm
   
Is PdfWrtier free?
Member 11210751 7-Jan-15 2:21am
   
hi.here what is the Htmltextwriter and Document.is they are class names.if its classes what i wrote the code in that classes?please give me the answer as soon as possible
Rate this:
Please Sign up or sign in to vote.

Solution 3

First u export PDF file in your data,

The best idea for create crystal report used expert option.
   
Rate this:
Please Sign up or sign in to vote.

Solution 8

You can use free print to PDF software, like cutePDF printer (not writer!!!)....
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100