i tried this
protected void writetoPDF()
{
MyPage tmpPage = new MyPage();
HtmlForm form = new HtmlForm();
form.Controls.Add(form1);
tmpPage.Controls.Add(form);
StringWriter sw = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
form.Controls[0].RenderControl(htmlWriter);
string htmlContent = sw.ToString();
Document document = new Document();
var fileName = HttpContext.Current.ApplicationInstance.Server.MapPath("");
fileName = fileName + @"\Report.pdf";
PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create));
document.Open();
System.Xml.XmlTextReader _xmlr = new System.Xml.XmlTextReader(new StringReader(htmlContent));
using (TextReader sReader = new StringReader(htmlContent.ToString()))
{
List<IElement> list = HTMLWorker.ParseToList(sReader, new StyleSheet());
foreach (IElement elm in list)
{
document.Add(elm);
}
}
document.Close();
ShowPdf(fileName);
if (File.Exists(fileName))
File.Delete(fileName);
}
private void ShowPdf(string s)
{
string saveas = qms_control_nbr + ".pdf";
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "inline;filename=" + saveas);
Response.ContentType = "application/pdf";
Response.WriteFile(s);
Response.Flush();
Response.Clear();
}
this is working but all the formating defined for the aspx page gone.
Can anyoone advice?