Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get report in .PDF format. I'm using C#, Asp.net language. My values are stored in DataTable I want to get DataTable values in PDF File. So how can I solve this problem?

Could anybody help me please?

Thanks in Advance
Posted
Updated 10-Apr-14 0:53am
v2

u need to import a dll itextsharp to do so.. download this dll and it will work for you.
 
Share this answer
 
 
Share this answer
 
You can export it Using ItextSharp DLL

Export HTML Table to PDF in ASP.NET[^]

You can Export it from RDLC report and crystal reports also.. :)

C#
private void CreatePDF(string fileName)
{
    // Setup DataSet
    MyDataSetTableAdapters.YourTableAdapterHere ds = new MyDataSetTableAdapters.YourTableAdapterHere();


    // Create Report DataSource
    ReportDataSource rds = new ReportDataSource("MyDataSourceName", ds.GetData());


    // Variables
    Warning[] warnings;
    string[] streamIds;
    string mimeType = string.Empty;
    string encoding = string.Empty;
    string extension = string.Empty;
  

    // Setup the report viewer object and get the array of bytes
    ReportViewer viewer = new ReportViewer();
    viewer.ProcessingMode = ProcessingMode.Local;
    viewer.LocalReport.ReportPath = "YourReportHere.rdlc";
    viewer.LocalReport.DataSources.Add(rds); // Add datasource here
  

    byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
  

    // Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
    Response.Buffer = true;
    Response.Clear();
    Response.ContentType = mimeType;
    Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension);
    Response.BinaryWrite(bytes); // create the file
    Response.Flush(); // send it to the client to download
}
 
Share this answer
 
v3
Comments
Aboobakkar Siddeq D U 10-Apr-14 5:39am    
Which namespace should I add to this?
Nirav Prabtani 10-Apr-14 6:48am    
using Microsoft.Reporting.WebForms;
using System.IO;
Aboobakkar Siddeq D U 10-Apr-14 7:10am    
Here I want to get DataTable values in PDF file
Nirav Prabtani 10-Apr-14 7:17am    
?????
Aboobakkar Siddeq D U 10-Apr-14 7:26am    
Here in your code i can't see DataTable, In my case I have values in DataTable and now I want to get DataTable values in PDF report, It should download automatically when button is clicked.

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