Click here to Skip to main content
15,919,749 members

Comments by Sakshii Arora (Top 2 by date)

Sakshii Arora 23-Jul-14 3:38am View    
I tried it but again its not working for me
Sakshii Arora 22-Jul-14 8:12am View    
i want to do the same thing convert my html table to pdf.. but confused how to do so please anybody can help .i tried this code above but it gives error that input string is not in correct format..
here is my c# code :-
pdfPannel.Visible = true;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
pdfPannel.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 80f, 80f, -2f, 35f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
and my html code is:
<asp:Panel ID="pdfPannel" runat="server" Height="466" Width="728">
<table cellpadding='2' cellspacing='2' width='100%'>
<tr><td colspan='100%'>
</td></tr>
<tr align="center" ><th colspan='100%' >INVOICE</th></tr>
<tr><td colspan='100%'>
</td></tr>
<tr><th colspan='4' align="right" >Bill No    :-</th><td align="left">njnn</td></tr>
<tr><th colspan='4' align="right" >Bill Date :-</th><td align="left">jnjnj</td></tr>
<tr><th colspan='100%'><br /></th></tr>
<tr><th align="left" >Customer Name:- </th><td colspan='4' align="left">ghgh</td></tr>
<tr><td colspan='100%'>
</td></tr>
<tr><th width='10%' align="left">S.no</th><th align="left">Particulars</th><th align="left">Quantity</th><th align="left">Rate</th><th align="left">Amount</th></tr>
<tr><td width='10%'>1.</td><td>pen</td><td>5</td><td>10</td><td>50</td></tr>
<tr><th colspan='100%'><br /></th></tr>
<tr><th colspan='100%'><br /></th></tr>
<tr><td colspan='100%'>
</td></tr>
<tr><th colspan='4' align='right'>Total Quantity :-</th><td>5.00</td></tr>
<tr><th colspan='4' align='right'>Sub Total         :-</th><td>50.00</td></tr>
<tr><th colspan='4' align='right'>Discount @      :-</th><td>0.00%</td></tr>
<tr><th colspan='4' align='right'>Total Amount   :-</th><td>50.00</td></tr>
<tr><td colspan='100%'>
</td></tr> </table>