4
votes

I am using the following code to output a Crystal Report to an ASP.NET application:

Dim rptDocument As New ReportDocument
Dim rptPath As String = Server.MapPath("Reports/Employees.rpt")

rptDocument.Load(rptPath)
Me.CrystalReportViewer1.ReportSource = rptDocument

Everything is working fine. My question is, is there a way to render the report as a PDF file instead of rendering to a crystalreportviewer?

I am using Visual Studio 2008 and Crystal Reports for Visual Studio 2008.

3

3 Answers

5
votes

Yes, you can use ExportToHttpResponse. Set the ExportFormatType to PortableDocFormat. Check out this tutorial.

0
votes

To very literally answer your Yes/No question, I believe the answer is yes. I reallize though you probably want to also know "How do I do it?". Some years ago I did this in VB.NET using the Crystal Reports runtime in a desktop application, but I do not remember nor have that code. Sorry.

0
votes

Well, if you can to view it as a PDF you would:

1.) Export the report

2.) Load the report in a "viewer" control of some kind or load the report and let Acrobat Reader do all the work.

With the runtime licences that Crystal give you for ASP.net development (which is crap BTW), using a PDF makes alot of since.

This is how I figured out how to export to PDF(there might be a better way..)

    Dim rptDocument As New ReportDocument
    Dim rptPath As String = Server.MapPath("Reports/Employees.rpt")
    Dim crExportOptions As ExportOptions
    Dim crDiskFileDestinationOptions As New DiskFileDestinationOptions()

    rptDocument.Load(rptPath)
    crDiskFileDestinationOptions.DiskFileName = "**Path**"
    crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
    crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
    crExportOptions.ExportDestinationOptions = crDiskFileDestinationOptions
    rptDocument.Export(crExportOptions)

    'Insert code to load the PDF you just created