How to export data into pdf file [Resolved]

Posted by santoshkumar413-24453 under C# on 1/21/2014 | Points: 10 | Views : 6083 | Status : [Member] | Replies : 6
Hi,


Any one can help me to export data from grid view to pdf file in asp.net.



Thanks,

Santosh




Responses

Posted by: kgovindarao523-21772 on: 1/21/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

In asp.net, we don’t have direct feature to export gridview data to PDF. For that reason here I am using third party library ITextSharp.dll reference

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
gvdetails.AllowPaging = false;
gvdetails.DataBind();
gvdetails.RenderControl(hw);
gvdetails.HeaderRow.Style.Add("width", "15%");
gvdetails.HeaderRow.Style.Add("font-size", "10px");
gvdetails.Style.Add("text-decoration", "none");
gvdetails.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
gvdetails.Style.Add("font-size", "8px");
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End()


Please Mark as Answer if you satisfied with the response.

Thank you,
Govind

santoshkumar413-24453, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mattyclown on: 3/19/2014 [Member] Starter | Points: 25

Up
0
Down

You are use OCR sdk to extract text from pdf or you can save pdf to txt file format or you just use some pdf text extracting control.

http://www.rasteredge.com/how-to/vb-net-imaging/pdf-text-extract/


santoshkumar413-24453, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Oliver32 on: 4/10/2014 [Member] Starter | Points: 25

Up
0
Down
How about doing that like this: )
Step 1, Load Data Information
private void btnLoad_Click(object sender, EventArgs e)
{
using (OleDbConnection oleDbConnection = new OleDbConnection())
{
oleDbConnection.ConnectionString = this.tbCS.Text;
OleDbCommand oleDbCommand = new OleDbCommand();
oleDbCommand.CommandText = this.tbCT.Text;
oleDbCommand.Connection = oleDbConnection;
using (OleDbDataAdapter da = new OleDbDataAdapter(oleDbCommand))
{
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView.DataSource = dt;
}
}
}

Step 2, Set Export into PDF

private void btnRun_Click(object sender, EventArgs e)
{
Spire.DataExport.PDF.PDFExport PDFExport = new Spire.DataExport.PDF.PDFExport();
PDFExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
PDFExport.DataTable = this.dataGridView.DataSource as DataTable;
PDFExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
PDFExport.SaveToFile("20110223.pdf");

}

The sample codes are from this Article -http://www.e-iceblue.com/Knowledgebase/Spire.DataExport/Program-Guide/How-to-Export-DataTable-to-PDF.html,check it out.

santoshkumar413-24453, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajnilari2015 on: 11/28/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
@Evanpan, why don't u put ur question as a fresh post in the forum so a so get more visibility (:

--
Thanks & Regards,
RNA Team

santoshkumar413-24453, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lucygrey on: 1/11/2016 [Member] Starter | Points: 25

Up
0
Down
Hey,I am sharing a link you will get the steps there with code,check it:
http://www.c-sharpcorner.com/UploadFile/0c1bb2/export-gridview-to-pdf/



http://www.keenesystems.com/Services/SoftwareDevelopment.aspx

santoshkumar413-24453, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response