Solved

CrystalReportViewer for ASP.NET prints the toolbar

Posted on 2004-04-01
3
2,430 Views
Last Modified: 2007-12-19
I have read "How to Design a good Crystal Report" from ehanoi and I think the conclusion is that Crystal Report Viewer for .Net does not come with a print button and if the toolbar is shown then when you print the report the toolbar appears on the report. If you hide the toolbar then of course it won't show on the printed page but you cannot navigate the report. This is bad, but what is worse is that when you print a report such as letters for individuals, it will print only the one displayed on the browser. Please let me know if this is so and there is no work around it. I pretty much have exhausted all options
0
Comment
Question by:Yves Mellet
3 Comments
 
LVL 4

Accepted Solution

by:
kssaran earned 250 total points
ID: 10738457
Yes, You are right. But you can think of alternative in this way. When the user wants to print the report why dont u export the same report to a PDF File in the run time and parse it the new browser. Then user can take the print out from the PDF File, which will have only the output of the report.

Try the following code

    Dim strInvoiceNo As String
    Dim strSelectFormula As String
    Dim ServerName As String, UserId As String, Password As String

    Private Sub cmdShowReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShowReport.Click
        ExportReport("servername", "username", "password")
    End Sub

    Private Sub ExportReport(ByVal ServerName As String, ByVal UserId As String, ByVal Password As String)
    'To Export the Result into a PDF File and display the Same in the window
        Dim myReport As New SampleReport()
        strInvoiceNo = txtInvoiceNo.Text
        strSelectFormula = "{invoice_header.inh_invoiceno} = '" + strInvoiceNo + "'"
        myReport.RecordSelectionFormula = strSelectFormula
        'Set the logon credentials of the main report
        LogonToDatabase(myReport.Database.Tables, ServerName, UserId, Password)

        'Modify the sub-report properties

        Dim mySection As CrystalDecisions.CrystalReports.Engine.Section
        Dim myReportObject As CrystalDecisions.CrystalReports.Engine.ReportObject
        Dim mySubReport As CrystalDecisions.CrystalReports.Engine.SubreportObject
        Dim mySubReportDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument

        'Loop through each section of the main report

        For Each mySection In myReport.ReportDefinition.Sections
            'Drill down into the section to see if there are any sub-reports
            For Each myReportObject In mySection.ReportObjects
                If myReportObject.Kind = _
                    CrystalDecisions.[Shared].ReportObjectKind.SubreportObject Then
                    mySubReport = CType(myReportObject, _
                        CrystalDecisions.CrystalReports.Engine.SubreportObject)

                    'Get a reference to the sub-report object
                    'so we can change its properties
                    mySubReportDoc = mySubReport.OpenSubreport(mySubReport.SubreportName)
                    'Set the logon credentials
                    LogonToDatabase(mySubReportDoc.Database.Tables, ServerName, UserId, Password)
                End If
            Next
        Next
        Dim myExportExt As String, myExportType As String, myExportFile As String
        Dim strExportType As String
        strExportType = "PDF"

        If strExportType = UCase("Excel") Then
            myExportExt = ".xls"
            myExportType = "application/vnd.ms-excel"
        ElseIf strExportType = UCase("HTML") Then
            myExportExt = ".html"
            myExportType = "application/html"
        ElseIf strExportType = UCase("PDF") Then
            myExportExt = ".pdf"
            myExportType = "application/pdf"
        ElseIf strExportType = UCase("RichText") Then
            myExportExt = ".rtf"
            myExportType = "application/rtf"
        ElseIf strExportType = UCase("Word") Then
            myExportExt = ".doc"
            myExportType = "application/msword"
        End If

        Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
        Dim myDiskFileDestinationOptions As CrystalDecisions.Shared.DiskFileDestinationOptions

        'myExportFile = Server.MapPath(".") & "\" & Session.SessionID.ToString & myExportExt
        myExportFile = "c:\winnt\temp\" & Session.SessionID.ToString & myExportExt

        myDiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions()
        myDiskFileDestinationOptions.DiskFileName = myExportFile
        myExportOptions = myReport.ExportOptions

        With myExportOptions

            .DestinationOptions = myDiskFileDestinationOptions
            .ExportDestinationType = .ExportDestinationType.DiskFile

            If strExportType = UCase("Excel") Then
                .ExportFormatType = .ExportFormatType.Excel
            ElseIf strExportType = UCase("HTML") Then
                .ExportFormatType = .ExportFormatType.HTML40
            ElseIf strExportType = UCase("PDF") Then
                .ExportFormatType = .ExportFormatType.PortableDocFormat
            ElseIf strExportType = UCase("RichText") Then
                .ExportFormatType = .ExportFormatType.RichText
            ElseIf strExportType = UCase("Word") Then
                .ExportFormatType = .ExportFormatType.WordForWindows
            End If
        End With

        'Exports the report to PDF format
        myReport.Export()
        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = myExportType
        Response.WriteFile(myExportFile)
        Response.Flush()
        Response.Close()

        System.IO.File.Delete(myExportFile)
    End Sub

    Private Sub LogonToDatabase(ByVal ReportTables As CrystalDecisions.CrystalReports.Engine.Tables, ByVal ServerName As String, ByVal UserId As String, ByVal Password As String)
    ' To Supply Logon Information to each and every Tables used in the Report
        Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
        Dim myConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo()
        Dim myLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo()
        myConnectionInfo.UserID = UserId
        myConnectionInfo.Password = Password
        myConnectionInfo.ServerName = ServerName
        myLogonInfo.ConnectionInfo = myConnectionInfo
        For Each myTable In ReportTables
            myTable.ApplyLogOnInfo(myLogonInfo)
        Next
    End Sub

End Class


0
 
LVL 13

Expert Comment

by:EwaldL
ID: 10743899
you get a print button on the web viewer if you upgrade to cr 9 or 10 developer or advanced.
0
 

Author Comment

by:Yves Mellet
ID: 10828368
Thanks for the help kssaran and Ewaldl. Particularly you kssaran for sending me all that code. It worked!
I would also like to follow Ewaldl advice to upgrade to cr9. I have the Advance edition but it  doesn't say it is for .net.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now