Really tough Crystal Question

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: GaryB (gb_at_nospam.com)
Date: 11/16/04


Date: Tue, 16 Nov 2004 10:14:46 -0800


(I know this is not the Crystal Forum but I get far better answers here :)

I have a working ASPX page that uses a CrystalReportViewer to print any web
datagrid Passed to it. On the page I have a button
that will convert the report to a PDF. The code pasted below works just
fine.

My goal, however, it to bypass the Crystal report altogether and just
directly print the PDF. Apparently, however, the line that says:
CrystalReportViewer1.ReportSource = myReport is the one that both creates
and prints the crystal report and it is therefore necessary for the function
PrintToPDFWithStream to work correctly.

Of course the report has to be created for my PDF function to work but is
there anyway to suppress the printing and trigger execution of
PrintToPDFWithStream after the report is created?

Hope someone can help.
Thanks,
Gary

   Private Sub Page_Load(ByVal .......
.
        Dim myReport As New
CrystalDecisions.CrystalReports.Engine.ReportDocument
        myReport = Session("ReportToPrint")
        Dim myDataSet As New DataSet
        myDataSet.ReadXml(Session("ReportFileString"))
        myReport.SetDataSource(myDataSet)
        PrepareReport(myReport.ReportDefinition.Sections) 'my function
        CrystalReportViewer1.ReportSource = myReport
End Sub

    Private Sub Button1_Click(ByVal sender .......
        Dim reportToPrint As New
CrystalDecisions.CrystalReports.Engine.ReportDocument
        reportToPrint = Session("ReportToPrint")
        PrintToPDFWithStream(reportToPrint)
    End Sub

    Private Function PrintToPDFWithStream(ByVal MyReport As
CrystalDecisions.CrystalReports.Engine.ReportDocument)
        Dim MyExportOptions As New CrystalDecisions.Shared.ExportOptions
        MyExportOptions.ExportFormatType =
CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat
        Dim MyExportRequestContext As New
CrystalDecisions.Shared.ExportRequestContext
        MyExportRequestContext.ExportInfo = MyExportOptions
        Dim MyStream As System.IO.Stream
        MyStream =
MyReport.FormatEngine.ExportToStream(MyExportRequestContext)
        Response.ClearHeaders()
        Response.ClearContent()
        Response.ContentType = "application/pdf"
        Dim myBuffer(MyStream.Length) As Byte
        MyStream.Read(myBuffer, 0, CType(MyStream.Length, Integer))
        Response.BinaryWrite(myBuffer)
        Response.End()
    End Function


Quantcast