I have wrote some code for the page content exporting to PDF. And Complete design code is under Content Place Holder in design page. As the data is generated dynamically, it is little tough to handle. After this code im getting following error at htmlworker.Parse(str); as Input string was not in a correct format Can please help on this?
Design Page:
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="CPH1">
<div id="MyDiv" style="background-color: #DDE3EC;">
<table>
Some code
</table>
<table>
<tr>
<td style="height: 21px">
<asp:Literal ID="LiQues" runat="server"></asp:Literal>
<asp:PlaceHolder ID="phQues" runat="server" ></asp:PlaceHolder>
</td>
</tr>
</table>
<table>
Some code
</table>
</div>
</<asp:Content>
Code behind
protected void btnExpPDF_Click1(object sender, EventArgs e)
{
//string attachment = "attachment; filename=CFSSurveyPage.pdf";
Response.ClearContent();
// Response.AddHeader("content-disposition", "attachment; filename=" + strFileName + ".xls");
Response.AddHeader("content-disposition", "attachment; filename=" + "CFSSurveyPage" + ".pdf");
Response.ContentType = "application/pdf";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
this.Page.Form.Controls[7].RenderControl(htextw);
// (this.Page.Master.Controls[3].Controls[7].Controls[47]).RenderControl(htextw);
//div2.RenderControl(htextw);
StringReader str = new StringReader(stw.ToString());
Document document = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlworker = new HTMLWorker(document);
PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
htmlworker.Parse(str);
document.Close();
Response.Write(document);
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}