Visual Studio .NET - How to Export Gridview to pdf without using any third party tool

Asked By Wsg Dotnet on 15-Jul-14 09:45 AM
How to Export Gridview to pdf in asp.net
I searched in many forums. but many of them said to use third party tools.
I don't want any third party tools.
Suggest me any sample for without using third party tool and export Gridview to pdf
The Below code is working, When I open the Pdf file the error is showing that " Adobe reader could not open test.pdf. because the file type hasbeen damaged"
 

Dim FilePath As String = "c:\test.pdf"
response.ContentType = "application/pdf"
response.AddHeader("Content-Type", "application/pdf")
response.AddHeader("Content-Disposition", "attachment; filename=" + FilePath)
response.WriteFile(FilePath)
response.end()

check here.. - Santhosh N replied to Wsg Dotnet on 16-May-08 07:29 AM

Check this for the same problem addressed here, As suggested try to use memory stream to do the stuff..

http://forums.asp.net/t/1256528.aspx

Try This - SP replied to Wsg Dotnet on 16-May-08 07:53 AM

See the followin link ::

http://www.dotnetspider.com/forum/ViewForum.aspx?ForumId=109866

It is having a sample code to convert gridview data into pdf.

Chirag Bhavsar replied to Wsg Dotnet on 09-Feb-15 12:53 PM
http://geekswithblogs.net/vivek/archive/2006/09/26/92316.aspx
Many times we would like to export our page as an Excel sheet, Word doc or PDF file. This can be simply achieved by changing the ContentType of the Response object and overriding the RenderControl method of the control to be exported:
Page Load()

{

 //bind data to data bound controls and do other stuff

 Response.Clear(); //this clears the Response of any headers or previous output 

Response.Buffer = true; //make sure that the entire output is rendered simultaneously

 ///

///Set content type to MS Excel sheet

///Use "application/msword" for MS Word doc files

///"application/pdf" for PDF files

///

 Response.ContentType = "application/vnd.ms-excel";

StringWriter stringWriter = new StringWriter(); //System.IO namespace should be used

 HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);

 ///

///Render the entire Page control in the HtmlTextWriter object

///We can render individual controls also, like a DataGrid to be

///exported in custom format (excel, word etc)

///

this.RenderControl(htmlTextWriter);

Response.Write(stringWriter.ToString());

Response.End();

} //end page load
For exporting ASP.NET pages as PDF files, you need to know the Adobe PDF specs for generating the PDf correctly. There is already a wonderful component which does the same and its free! See this article along with sample source code on how to export a page to PDF:
http://www.codeproject.com/cs/library/giospdfnetlibrary.asp
http://itextsharp.sourceforge.net/tutorial/index.html

export to PDF - mv ark replied to Wsg Dotnet on 16-May-08 08:14 AM
AFAIK, it is not possible to generate PDF files natively with C# or VB.NET. You can explore these 2 free & open source libraries  to generate PDFs on the fly:
PDFSharp - http://www.pdfsharp.com/PDFsharp/index.php?option=com_frontpage&Itemid=1
iText#  - http://sourceforge.net/projects/itextsharp/

Sample code is also available from the above links
Web2PDF Online - mv ark replied to Wsg Dotnet on 16-May-08 08:43 AM

Web2PDF Online ( http://web2.pdfonline.com/getting_started/index.htm ) is a free service for websites that allows visitors to save web pages as PDF files.

You can consider adapting your code to utilize this service

http://web2.pdfonline.com/getting_started/index.htm 

Export Gridview with out using Crystal report - Wsg Dotnet replied to Santhosh N on 08-Feb-15 12:41 PM

http://forums.asp.net/t/1256528.aspx in this link they are used crystal report. but I dont want that. What I want is, If the user clicks the export button in a Asp.net page 3 options will be asked 1.text 2.excel 3.pdf  first 2 is I finished. using content type="application/text" and "application/ms-excel" but pdf is not worked. so I asked without using crystal report and third party tool how can I achieve this?

How to Export Gridview to pdf without using any third party tool - Girish Kerimani replied to Wsg Dotnet on 15-Sep-08 09:27 AM
Can i get the Code for Exporting GridView to PDF format without using third party component
Anoop S replied to Wsg Dotnet on 15-Jul-14 08:58 AM
You can use http://sourceforge.net/projects/itextsharp/ to create pdf file,  you can see example here:
http://csharpdotnetfreak.blogspot.com/2008/12/export-gridview-to-pdf-using-itextsharp.html