I'm working on a form where I need a client to receive a copy of the form in a PDF format after they have submitted the form, I created a button to get the PDF form however the issue lies in where the PDF form shows JavaScript, CSS, jquery code, and the form has a drop down lists of the Cities, Regions the problem there is the drop downs show all the information that it contains not the one that the client chose. My aim is for PDF form to show the data that the client filled in.
protected void btn_PDF_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=The_Client_Information.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
WebClient client = new WebClient(); String html = client.DownloadString("http://localhost:50389/The_Client_Information.aspx");
Regex regSimple = new Regex(@"(?i)<img\b[^>]*?style\s*=(['""]?)(?<style>[^'""]+)\1[^>]*?>");
if (regSimple.IsMatch(html))
{
html = html.Replace(Convert.ToString(regSimple.Match(html)), Convert.ToString(regSimple.Match(html)).Replace("style=\"", "").Replace("height:", "height=\"").Replace("\"width:", "width=\""));
}
Document pdfDoc = new Document(iTextSharp.text.PageSize.A4.Rotate(), 10, 10, 10, 10);
pdfDoc.SetPageSize(iTextSharp.text.PageSize.A4);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}