Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Exporting Asp.Net page to PDF file

Exporting Asp.Net page to PDF file

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Raheem MA
    wrote on last edited by
    #1

    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

    A D R 3 Replies Last reply
    0
    • R 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

      A Offline
      A Offline
      Anurag Gandhi
      wrote on last edited by
      #2

      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.

      R 1 Reply Last reply
      0
      • R 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

        D Offline
        D Offline
        deepikakhorana
        wrote on last edited by
        #3

        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

        R 1 Reply Last reply
        0
        • A Anurag Gandhi

          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.

          R Offline
          R Offline
          Raheem MA
          wrote on last edited by
          #4

          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

          A 1 Reply Last reply
          0
          • R 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

            A Offline
            A Offline
            Anurag Gandhi
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • D deepikakhorana

              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

              R Offline
              R Offline
              Raheem MA
              wrote on last edited by
              #6

              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

              D 1 Reply Last reply
              0
              • R 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

                R Offline
                R Offline
                Raheem MA
                wrote on last edited by
                #7

                Hello Friends, My requirement is we will have many Asp.Net server controls on a webpage and a export button. On clicking Export button, all the content & asp.net controls should be exported to PDF file. Please help me, this is urgent. Thank you in Advance, Raheem MA

                1 Reply Last reply
                0
                • R 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

                  D Offline
                  D Offline
                  deepikakhorana
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups