Hi,
I am facing issue while converting a html document into pdf using itextsharp dll in sharepoint visual webpart.I have attached my code below.Can anyone please help me to resolve?
protected void btnsub_Click(object sender, EventArgs e)
{
string currentURL = HttpContext.Current.Request.Url.ToString();
MemoryStream stream = new MemoryStream();
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
// HttpContext.Current.Response.Charset = "";
// String htmlText = strSelectUserListBuilder.ToString();
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter txtWriter = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(txtWriter);
//this.Page.RenderControl(hw);
div123.RenderControl(hw);//*error
StringReader sr = new StringReader(txtWriter.ToString());
iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 20f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
var bytes = stream.ToArray();
HttpContext.Current.Response.OutputStream.Write(bytes, 0, bytes.Length);
HttpContext.Current.Response.OutputStream.Flush();
HttpContext.Current.Response.Write(pdfDoc);
HttpContext.Current.Response.End();
}
This is the code which am trying to get pdf.but am getting an error in (*error)
I tried to resolve it by adding
Enableeventvalidation =true;in page directory
But there is no page directory in ascx page.
After this we need to add
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
Showing an error like no suitable method found to override
Poovi