Hello Everyone,
I'm facing problem while generating PDF. The below code is used for every page, but for some pages its generates PDF with data & some page generates PDF with No Data(blank).
Please help me out. Thanks in advance...!!
Namespace
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
Here is my code:-
if (GridViewAnalysisCategoryMaster.Rows.Count == AppConstants.EMPTY_STRING_LEN)
{
ChangeLabelColor(lblerror, "No Records Found to Export", AppConstants.BOOL_TRUE);
return;
}
else
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=AnalysisCategoryMaster_" + DateTime.Now.ToString("dd/MM/yyyy") + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
BindData(); // Here i'm binding gridview data to generate PDF.
GridViewAnalysisCategoryMaster.AllowPaging = AppConstants.BOOL_FALSE;
GridViewAnalysisCategoryMaster.DataBind();
GridViewAnalysisCategoryMaster.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
Regards,
Sumit
Loading
Sumit BanglorkarPosted Jun 17, 2013, 7:06 AM
Yes, its due to some problems with HTML tags. As you know some of my PDFs are generating with data, so i copied same gridview structure from HTML source (which is generating the PDF) & paste in another page (which is generating PDF widout Data), change the control ID as per requirement. I did this & its working fine for me.
Thank You...
Sumit
Ravishankar SinghPosted Jun 14, 2013, 2:42 AM