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. create pdf downloader

create pdf downloader

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelp
5 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.
  • B Offline
    B Offline
    bemahesh
    wrote on last edited by
    #1

    hi, i have a report downloader in my asp.net/vb web application. When user selects report to download it pops up download dialog box and asks if user wants to open or save the file. currently, i am generating excel report. it is working fine. however, i want to generate pdf report as well. here is my code that i am having problem with in pdf Dim sb As System.Text.StringBuilder sb = New System.Text.StringBuilder filename = "http:\\abc.org\Reports\report1.pdf" get data using dataadpater here ( returns dataset) Dim dt As New DataTable Dim dr As DataRow Dim dc As DataColumn dt = dstMain.Tables("SearchResults") For Each dc In dt.Columns sb.Append((dc.ColumnName).ToString() & Chr(9)) Next sb.Append(vbCrLf) For Each dr In dt.Rows For Each dc In dt.Columns sb.Append(dr(dc.ColumnName).ToString & Chr(9)) Next sb.Append(vbCrLf) Next sb.Append(vbCrLf) 'Response.ContentType = "Application/x-msexcel" Response.ContentType = "Application/pdf" 'Response.OutputStream.Write(sb, 0, sb.Length) Response.AppendHeader("content-disposition", "attachment; filename=""" & filename & """") 'Write the file directly to the HTTP output stream. Response.AppendHeader("content-length", sb.Length) Response.Write(sb.ToString) Response.End() Thanks Needy

    M I 3 Replies Last reply
    0
    • B bemahesh

      hi, i have a report downloader in my asp.net/vb web application. When user selects report to download it pops up download dialog box and asks if user wants to open or save the file. currently, i am generating excel report. it is working fine. however, i want to generate pdf report as well. here is my code that i am having problem with in pdf Dim sb As System.Text.StringBuilder sb = New System.Text.StringBuilder filename = "http:\\abc.org\Reports\report1.pdf" get data using dataadpater here ( returns dataset) Dim dt As New DataTable Dim dr As DataRow Dim dc As DataColumn dt = dstMain.Tables("SearchResults") For Each dc In dt.Columns sb.Append((dc.ColumnName).ToString() & Chr(9)) Next sb.Append(vbCrLf) For Each dr In dt.Rows For Each dc In dt.Columns sb.Append(dr(dc.ColumnName).ToString & Chr(9)) Next sb.Append(vbCrLf) Next sb.Append(vbCrLf) 'Response.ContentType = "Application/x-msexcel" Response.ContentType = "Application/pdf" 'Response.OutputStream.Write(sb, 0, sb.Length) Response.AppendHeader("content-disposition", "attachment; filename=""" & filename & """") 'Write the file directly to the HTTP output stream. Response.AppendHeader("content-length", sb.Length) Response.Write(sb.ToString) Response.End() Thanks Needy

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi there, Because, the Excel file can be saved in the html format with the table element, so your sample code would work. However, the pdf format is different, so what you might need to use is a library to generate the pdf document, then send the binary content to the output stream of the Response object.

      1 Reply Last reply
      0
      • B bemahesh

        hi, i have a report downloader in my asp.net/vb web application. When user selects report to download it pops up download dialog box and asks if user wants to open or save the file. currently, i am generating excel report. it is working fine. however, i want to generate pdf report as well. here is my code that i am having problem with in pdf Dim sb As System.Text.StringBuilder sb = New System.Text.StringBuilder filename = "http:\\abc.org\Reports\report1.pdf" get data using dataadpater here ( returns dataset) Dim dt As New DataTable Dim dr As DataRow Dim dc As DataColumn dt = dstMain.Tables("SearchResults") For Each dc In dt.Columns sb.Append((dc.ColumnName).ToString() & Chr(9)) Next sb.Append(vbCrLf) For Each dr In dt.Rows For Each dc In dt.Columns sb.Append(dr(dc.ColumnName).ToString & Chr(9)) Next sb.Append(vbCrLf) Next sb.Append(vbCrLf) 'Response.ContentType = "Application/x-msexcel" Response.ContentType = "Application/pdf" 'Response.OutputStream.Write(sb, 0, sb.Length) Response.AppendHeader("content-disposition", "attachment; filename=""" & filename & """") 'Write the file directly to the HTTP output stream. Response.AppendHeader("content-length", sb.Length) Response.Write(sb.ToString) Response.End() Thanks Needy

        I Offline
        I Offline
        Ista
        wrote on last edited by
        #3

        this will do it Response.AddHeader("Content-Disposition: Application/pdf"; Response.TransmitFile( <filename>); Response.Flush(); Response.End(); Put that in the Page-Load and it will display your file I might be wrong about the Application.pdf But a week ago I did the same answer. search through my posts and I pasted the code directly from a code file. Nick 1 line of code equals many bugs. So don't write any!!

        I 1 Reply Last reply
        0
        • I Ista

          this will do it Response.AddHeader("Content-Disposition: Application/pdf"; Response.TransmitFile( <filename>); Response.Flush(); Response.End(); Put that in the Page-Load and it will display your file I might be wrong about the Application.pdf But a week ago I did the same answer. search through my posts and I pasted the code directly from a code file. Nick 1 line of code equals many bugs. So don't write any!!

          I Offline
          I Offline
          Ista
          wrote on last edited by
          #4

          what I typed in is all you need to display a file 1 line of code equals many bugs. So don't write any!!

          1 Reply Last reply
          0
          • B bemahesh

            hi, i have a report downloader in my asp.net/vb web application. When user selects report to download it pops up download dialog box and asks if user wants to open or save the file. currently, i am generating excel report. it is working fine. however, i want to generate pdf report as well. here is my code that i am having problem with in pdf Dim sb As System.Text.StringBuilder sb = New System.Text.StringBuilder filename = "http:\\abc.org\Reports\report1.pdf" get data using dataadpater here ( returns dataset) Dim dt As New DataTable Dim dr As DataRow Dim dc As DataColumn dt = dstMain.Tables("SearchResults") For Each dc In dt.Columns sb.Append((dc.ColumnName).ToString() & Chr(9)) Next sb.Append(vbCrLf) For Each dr In dt.Rows For Each dc In dt.Columns sb.Append(dr(dc.ColumnName).ToString & Chr(9)) Next sb.Append(vbCrLf) Next sb.Append(vbCrLf) 'Response.ContentType = "Application/x-msexcel" Response.ContentType = "Application/pdf" 'Response.OutputStream.Write(sb, 0, sb.Length) Response.AppendHeader("content-disposition", "attachment; filename=""" & filename & """") 'Write the file directly to the HTTP output stream. Response.AppendHeader("content-length", sb.Length) Response.Write(sb.ToString) Response.End() Thanks Needy

            I Offline
            I Offline
            Ista
            wrote on last edited by
            #5

            Ok misread that I think. An excel file can be either the file, csv, or xml. this free library will help http://www.carlosag.net/[^] 1 line of code equals many bugs. So don't write any!!

            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