using itextsharp i am converting aspx page to pdf document,but in pdf file only one page is creating every time but still data is there in aspx page which was not created in pdf file.I am working with asp.net using C#,kindly give the solution as early as possible
private void ConvertPDF()
{
try
{
string path = Server.MapPath("~/Img/Student Photos//PDFFiles//");
path = path + objbllpreadm.objELLPreAdmission.User_id + ".pdf";
if (File.Exists(path))
{
File.Delete(path);
}
attchmt = objbllpreadm.objELLPreAdmission.User_id + ".pdf";
string filename1 = "";
filename1 = objbllpreadm.objELLPreAdmission.User_id + ".pdf";
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + filename1);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
var output = new FileStream(path, FileMode.Create);
StringReader sr = new StringReader(sw.ToString());
iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A3, 0f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, output);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
catch (Exception exp)
{
var ErrorMessage = new JavaScriptSerializer().Serialize(exp.Message.ToString());
ShowAlertMessage(ErrorMessage);
}
}
the above method i am using for converting the aspx page to pdf document,the code completely running,no errors throwing,after running the code one pdf file will download which contains 2 pages and one more file will create in "~/Img/Student Photos//PDFFiles//" folder which contains single page...remaining data not coming