Exporting Asp.Net page to PDF file
-
Hello, In our project, we have a requirement to export a web page (Asp.Net) to PDF file. All the controls on the page (The web page completely along with its format) should be exported to PDF file. Anybody has worked on this before? Can you please shed some light on this to get it work? As we have some constraints, we have to do it without spending money. Thank you in Advance, Raheem MA
-
Hello, In our project, we have a requirement to export a web page (Asp.Net) to PDF file. All the controls on the page (The web page completely along with its format) should be exported to PDF file. Anybody has worked on this before? Can you please shed some light on this to get it work? As we have some constraints, we have to do it without spending money. Thank you in Advance, Raheem MA
Try using some free ware pdf components like PDFSharp, MigraDoc, etc. The following link may help you: http://alt-soft.com/Support_kb_generating_pdf_from_asp_net.aspx[^] http://www.pdfsharp.com/PDFsharp/[^]
Anurag Gandhi. http://www.gandhisoft.com Life is a computer program and every one is the programmer of his own life.
-
Hello, In our project, we have a requirement to export a web page (Asp.Net) to PDF file. All the controls on the page (The web page completely along with its format) should be exported to PDF file. Anybody has worked on this before? Can you please shed some light on this to get it work? As we have some constraints, we have to do it without spending money. Thank you in Advance, Raheem MA
Hi Raheem The procedure is step1:render the page through asp.net code in a web browser, this will return a bitmap public System.Drawing.Bitmap CaptureWebPage(string URL) { // create a hidden web browser, which will navigate to the page System.Windows.Forms.WebBrowser web = new System.Windows.Forms.WebBrowser(); web.ScrollBarsEnabled = false; // we don't want scrollbars on our image web.ScriptErrorsSuppressed = true; // don't let any errors shine through web.Navigate(URL); // let's load up that page! // wait until the page is fully loaded while (web.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete) System.Windows.Forms.Application.DoEvents(); System.Threading.Thread.Sleep(1500); // allow time for page scripts to update // the appearance of the page // set the size of our web browser to be the same size as the page int width = web.Document.Body.ScrollRectangle.Width; int height = web.Document.Body.ScrollRectangle.Height; web.Width = width; web.Height = height; // a bitmap that we will draw to System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height); // draw the web browser to the bitmap web.DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, width, height)); return bmp; // return the bitmap for processing } Step 2: and then save this as PDF
-
Try using some free ware pdf components like PDFSharp, MigraDoc, etc. The following link may help you: http://alt-soft.com/Support_kb_generating_pdf_from_asp_net.aspx[^] http://www.pdfsharp.com/PDFsharp/[^]
Anurag Gandhi. http://www.gandhisoft.com Life is a computer program and every one is the programmer of his own life.
Anurag, Thank you for your reply. I did go through the links you provided. First one, AltSoft might match our requirement but it is not free of cost. Second One, just creates PDF files in Asp.net but does not export the asp.net page to PDF. Our requirement is exporting the complete Asp.net page (.aspx) to PDF file. Can you please provide any other information regarding this. Thank you in Advance, Raheem MA
-
Anurag, Thank you for your reply. I did go through the links you provided. First one, AltSoft might match our requirement but it is not free of cost. Second One, just creates PDF files in Asp.net but does not export the asp.net page to PDF. Our requirement is exporting the complete Asp.net page (.aspx) to PDF file. Can you please provide any other information regarding this. Thank you in Advance, Raheem MA
Hi, The following link may help you: Pdfizer, a dumb HTML to PDF converter, in C#[^] Generate PDF documents from a HTML page using ASP.NET[^] I my self haven't tried them, but hoping that it will solve your problem.
Anurag Gandhi. http://www.gandhisoft.com Life is a computer program and every one is the programmer of his own life.
-
Hi Raheem The procedure is step1:render the page through asp.net code in a web browser, this will return a bitmap public System.Drawing.Bitmap CaptureWebPage(string URL) { // create a hidden web browser, which will navigate to the page System.Windows.Forms.WebBrowser web = new System.Windows.Forms.WebBrowser(); web.ScrollBarsEnabled = false; // we don't want scrollbars on our image web.ScriptErrorsSuppressed = true; // don't let any errors shine through web.Navigate(URL); // let's load up that page! // wait until the page is fully loaded while (web.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete) System.Windows.Forms.Application.DoEvents(); System.Threading.Thread.Sleep(1500); // allow time for page scripts to update // the appearance of the page // set the size of our web browser to be the same size as the page int width = web.Document.Body.ScrollRectangle.Width; int height = web.Document.Body.ScrollRectangle.Height; web.Width = width; web.Height = height; // a bitmap that we will draw to System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height); // draw the web browser to the bitmap web.DrawToBitmap(bmp, new System.Drawing.Rectangle(0, 0, width, height)); return bmp; // return the bitmap for processing } Step 2: and then save this as PDF
Thank you Deepika for your response, But I dont want to capture the complete webpage. Following is the scenario: We have "Export" button on every webpage(contains Charts, graphs etc...). On Export button click, the charts , graphs ... of the particular page should be exported to PDF file. Any ideas ? Thank you in Advance, Raheem MA
-
Hello, In our project, we have a requirement to export a web page (Asp.Net) to PDF file. All the controls on the page (The web page completely along with its format) should be exported to PDF file. Anybody has worked on this before? Can you please shed some light on this to get it work? As we have some constraints, we have to do it without spending money. Thank you in Advance, Raheem MA
-
Thank you Deepika for your response, But I dont want to capture the complete webpage. Following is the scenario: We have "Export" button on every webpage(contains Charts, graphs etc...). On Export button click, the charts , graphs ... of the particular page should be exported to PDF file. Any ideas ? Thank you in Advance, Raheem MA
Hi Raheem You need to create one page named preview and render only those things which u need to export on that page (if it is a chart then only render chart on that page) and then try that code. at the time of export just redirect to the export page(another page which will run the bitmap and web browser code) which will do the stuff for you and then call the preview page in url then it will export only charts etc. Thanks Deepika