Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
recently, I have an HTML file that is opened in an iframe. In the HTML file, there is some textbox so when the user fills the textbox then by click button, the HTML or iframe content will be saved as a pdf file.

What I have tried:

Response.ContentType = "Application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
StringWriter s_tw = new StringWriter();
HtmlTextWriter h_textw = new HtmlTextWriter(s_tw);
h_textw.AddStyleAttribute("font-size", "7pt");
h_textw.AddStyleAttribute("color", "Black");
myiframe.RenderControl(h_textw);//Name of the ifarme
Document doc = new Document();

doc = new Document(PageSize.A4, 50, 50, 40, 40);
FontFactory.GetFont("Times New Roman", 14);
//PdfWriter pdf = PdfWriter.GetInstance(doc, Response.OutputStream);
StringReader s_tr = new StringReader(s_tw.ToString());
HTMLWorker html_worker = new HTMLWorker(doc);
PdfWriter writer = PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
doc.NewPage();
html_worker.Parse(s_tr);
doc.Close();
Response.Write(doc);
Response.End();
Posted
Comments
gggustafson 9-Apr-20 13:52pm    
What is Response?
Member 14192879 9-Apr-20 18:46pm    
i used a response to write the output stream mean to write the content of iframe to the output stream.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900