• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2392
  • Last Modified:

ReportViewer render as PDF

Ive got a report working great using a ReportViewer in ASP.net, however every load I convert the HTML report into a PDF.

Is it possible instead of loading the ReportViewer up in the HTML view, outputting the PDF straight away?

I know I have to do:-
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=Test.pdf)

However I have no idea how to set the ReportViewer to output PDF straight away.

Any ideas on how I can do this, any code examples would be appriciated.

Thank you
  • 4
  • 4
1 Solution
''''''''''''''''''''   try this one on your *.aspx.vb

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 End Sub

Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
Dim fl As String = "c:\inetpub\wwwroot\samplereport.pdf"
Dim virtualDir = "http://localhost/samplereport.pdf"
Dim rds As ReportDataSource = New ReportDataSource("yourDataSetName", ObjectDataSource1)
        Dim b As Byte()
        b = ReportViewer1.LocalReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)

        If File.Exists(fl) = True Then
        End If

        Dim fs As New FileStream(fl, FileMode.Create)
        fs.Write(b, 0, b.Length)

        If File.Exists(fl) = True Then
              response.redirect(virtualDir )
             'or use a httphandler instead of just redirecting
        End If
 End Sub
tonelm54Author Commented:
Looks good, but when it runs:-
          b = ReportViewer1.LocalReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)

I get "An error occurred during local report processing."
tonelm54Author Commented:
Without the code, it does render the HTML report correctly.
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

can you tell me more about the error? what exactly is the description?
tonelm54Author Commented:
The message Im getting is:-

Microsoft.ReportingServices.ReportProcessing.ProcessingAbortedException: An error has occurred during report processing. ---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: DataSet1

An error occurred during local report processing.
tonelm54Author Commented:
My asp.net code is attached
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication18.WebForm1" %>

<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server">
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
            Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
            WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
            <LocalReport ReportPath="Report1.rdlc">
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />


Open in new window

'can you check please if DataSet1 is being  set to rds as report datasource on Sub Page_LoadComplete

'it shoul be like this below
Dim rds As ReportDataSource = New ReportDataSource("DataSet1", ObjectDataSource1)
sorry I forgot to add you need to add

Imports System.IO

on the top of your aspx.vb

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now