|
I was searching perfect snippet for my project but i was failed to found ,
i want to dynamically generated html report (transactional report ) on whole page,but i was facing problem
using itextsharp DLL having different problem like
"document has no pages "
and
"illegal character found.."
i was test more than dozen of code but after too effort , i found a way to render whole page or particular
div render or save as pdf..
NOTE : if you have found this error like
"
Unable to cast object of type 'iTextSharp.text.html.simpleparser.IncCell' to type 'iTextSharp.text.html.simpleparser.IncTable'
"
this is because you have binding issue make sure before simple is properly binding, extra single code in pdf div area found are cause of error.
Now
i want to share the my finding to all.
Core function of PDF is
protected void exportbtn_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition",
"attachment;filename=Customers.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
//this.Page.RenderControl(hw);
// this.repCustomers.RenderControl(hw);
this.grid.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString().Replace("\r", "").Replace("\n", "").Replace(" ", ""));
Document pdfDoc = new Document(iTextSharp.text.PageSize.A4, 10f, 10f, 10f, 0.0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
RIZWAN
|
|
|
|