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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Juan HinesPosted Aug 14, 2015, 3:07 AM
Trevor CarterPosted Apr 11, 2013, 3:43 AM
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")
Satyapriya NayakPosted Apr 2, 2013, 5:29 AM