HTML Table Export to PDF using C#

Posted by Asjad under ASP.NET on 12/20/2010 | Points: 10 | Views : 34683 | Status : [Member] | Replies : 7
Hi
I have a table
<table id="mytable" border="0" >
<tr>
<td>
dATA
</td>
<td>
dATA</td>
<td>
dATATTATAA;</td>
</tr>
<tr>
<td>
DUMMY</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
</table>


And i want to export to pdf code i used is

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=myexcel.pdf");
Response.ContentType = "application/pdf";
StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
mytable.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();

but its not working and giving error that file can not be open.......

Please help.....




Responses

Posted by: SheoNarayan on: 12/20/2010 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
I think you will have to use some third party component in order to generate .pdf. Have a look at this article that describes the stuff you are looking for http://www.dotnetfunda.com/articles/article977-pdf-generator-in-net--dynamically-generate-pdf-in-aspnet-.aspx ,

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Asjad, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 12/21/2010 [Member] Bronze | Points: 25

Up
0
Down
hi,

Try to below code
   1. public void button3_Click(object sender, EventArgs e)  

2. {
3. DuoDimension.HtmlToPdf.SetLicenseCode("LICENSE-KEY");
4. string file_html = @"K:\hdoc.html";
5. string file_pdf = @"K:\new.pdf";
6. try
7. {
8. DuoDimension.HtmlToPdf conv = new DuoDimension.HtmlToPdf();
9. conv.OpenHTML(file_html);
10. conv.SavePDF(file_pdf);
11. textBox4.Text = "C# Example: Converting succeeded";
12. }
13. catch (Exception ex)
14. {
15. textBox4.Text = ex.Message;
16. }
17. }

more discus about convert HTML Table to PDF show below link

http://www.c-sharpcorner.com/forums/ShowMessages.aspx?ThreadID=64874

LP MER

Asjad, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Fchivu on: 12/23/2010 [Member] Starter | Points: 25

Up
0
Down
You can try Evo html to pdf http://www.evopdf.com converter for .net. It is a really good library.

Asjad, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/6/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
hi,

try this library...

http://www.codeproject.com/KB/graphics/giospdfnetlibrary.aspx

This acts as a library and easily you can do the export to pdf

Thanks
Karthik
www.f5Debug.net

Asjad, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Stevnetk on: 3/13/2012 [Member] Starter | Points: 25

Up
0
Down
hi,
try this html to pdf converter http://www.hiqpdf.com . it is very powerful. convert anything a browser can render to pdf. see demo and source code at http://www.hiqpdf.com/demo/Default.aspx
thanks,
stevnetk

Asjad, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sebas on: 4/24/2013 [Member] Starter | Points: 25

Up
0
Down
Hello,
You may want to look at Elerium HTML to PDF component . It allows to convert html string/file/url to PDF including styles, but it is not free.
Please look at this example:
http://eleriumsoft.com/PDF_NET/HTML2PDF/Examples/Create_PDF_using_HTML_string.aspx

Asjad, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sjoseph on: 6/16/2014 [Member] Starter | Points: 25

Up
0
Down
Expert PDF also provide facility of converting HTML to PDF into C#. Here is the sample code:

PdfConverter pdfConverter = new PdfConverter();

pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
pdfConverter.PdfDocumentOptions.ShowHeader = true;
pdfConverter.PdfDocumentOptions.ShowFooter = true;
pdfConverter.PdfDocumentOptions.LeftMargin = 5;
pdfConverter.PdfDocumentOptions.RightMargin = 5;
pdfConverter.PdfDocumentOptions.TopMargin = 5;
pdfConverter.PdfDocumentOptions.BottomMargin = 5;
pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true;

pdfConverter.PdfDocumentOptions.ShowHeader = false;
//pdfConverter.PdfHeaderOptions.HeaderText = "Sample header: " + TxtURL.Text;
//pdfConverter.PdfHeaderOptions.HeaderTextColor = Color.Blue;
//pdfConverter.PdfHeaderOptions.HeaderDescriptionText = string.Empty;

For more information visit: http://www.html-to-pdf.net/html-to-pdf-csharp.aspx

Asjad, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response