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