We help IT Professionals succeed at work.

Crystal Report Viewer - Export to/open a PDF after entering parameters

synapse88 used Ask the Experts™
I have a report viewer in place, and i would like the report in question to be opened in a PDF after the user enters parameters and clicks the submit button (instead of the report being opened in the report viewer window.)

I did some reading elsewhere and found this snippet

rptSP.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Report");

Open in new window

and i also found a posting where the following was recommended:

Write code to export the report to pdf inside of the CrystalReportViewer_BeforeRenderObject event.

but I haven't made it much past that. Can anyone provide a code example, or link to one which shows this solution in place?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Consultant
Most Valuable Expert 2011
Top Expert 2013
What version of Crystal?

I believe this example shows how to export

try this
   Protected Sub CrystalReportViewer_BeforeRenderObject(ByVal source As Object, ByVal e As CrystalDecisions.Web.HtmlReportRender.BeforeRenderObjectEvent) Handles CrystalReportViewer.BeforeRenderObject
        Dim oStream As IO.MemoryStream
        ' using System.IO

            oStream = DirectCast(MyCrystalSource.ReportDocument.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat), IO.MemoryStream)
            Response.Buffer = True
            Response.ContentType = "application/pdf"

End if

Open in new window