How to convert Default.aspx page to aaaaa.pdf file??
..................Prakash
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Apr 2, 2013, 1:29 AM EDT
Trevor Carter2 reputationPosted Apr 10, 2013, 11:43 PM EDT
First of all you need to get HTML content of .aspx page. Then you can use some 3rd party libraries to convert HTML to PDF. For examle you may want to look at Elerium HTML to PDF component. It allows to convert html string/file/url to PDF including styles, but it is not free.
To get HTML content you can place all components on Panel and use this code:
StringWriter objStringWriter = new StringWriter();
HtmlTextWriter objHtmlWriter = new HtmlTextWriter(objStringWriter);
Panel1.RenderControl(objHtmlWriter);
string html_form = objStringWriter.ToString();
After that you can convert result HTML to PDF:
Docs.HtmlToPdf htmlToPdf = new Docs.HtmlToPdf();
htmlToPdf.OpenHTML(html_form);
htmlToPdf.SavePDF(@"outfile.pdf")
You also can easily convert .aspx page from url:
Uri url = new Uri(@"page_adress");
Docs.HtmlToPdf htmlToPdf = new Docs.HtmlToPdf();
htmlToPdf.OpenHTML(url);
htmlToPdf.SavePDF(@"outfile.pdf")
Juan Hines18 reputationPosted Aug 13, 2015, 11:07 PM EDT