I am using the Code below to Convert HTML to PDF and download:
public void generatePdfFromHtml(string html, string reportName)
{
try
{
Byte[] bytes;
string content = html;
using (var ms = new MemoryStream())
{
var doc = new Document();
if (reportName == "abc" || reportName == "cdf")
{
doc = new Document(PageSize.A4_LANDSCAPE, 10, 10, 20, 10);
}
else
{
doc = new Document(PageSize.A4, 30, 30, 30, 30);
}
var writer = PdfWriter.GetInstance(doc, ms);
doc.Open();
doc.NewPage();
var example_html = content;
using (var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(doc))
{
using (var sr = new StringReader(example_html))
{
htmlWorker.Parse(sr);
}
}
doc.Close();
bytes = ms.ToArray();
}
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=RegisteredCourses_" + General.Session.UserID + ".pdf");
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
Response.End();
Response.Close();
}
catch (Exception ex)
{
}
}
The code works perfectly fine on another page same coding perfectly fine until now , it wont download . Everything Works fine and i see the code reaching Response...
.But using console window in firebug i see this error:
Error: Sys.WebForms.PageRequestManagerParserErrorException: The message
received from the server could not be parsed.
Any suggestion?