We help IT Professionals succeed at work.

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

synapse88
synapse88 used Ask the Experts™
on
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?
Comment
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
Commented:
What version of Crystal?

I believe this example shows how to export
http://www.emoreau.com/Entries/Articles/2006/10/Crystal-Reports--Part-II.aspx

mlmcc
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.Clear()
            Response.Buffer = True
            Response.ContentType = "application/pdf"
            Response.BinaryWrite(oStream.ToArray())
            Response.[End]()

End if

Open in new window