Printing Your Report

Now, if you have already done some report integration with Windows applications, you may have noticed that the Web Forms Viewer is missing one very important icon—the Print button. When a Crystal Report is viewed on the Web, it is actually rendered in static HTML 3.2 or HTML 4.0, with all of the report elements represented in HTML code and syntax.

This makes things difficult when it comes time to print your report. In a case where you were just using the plain old viewer with little or no modification, imagine if you were to click the print button from your browser to print your report.

Figure 5-22

It is not going to be very pretty to say the least; if your application uses single-page reports or discrete parts of a report, you may be happy with this, but for the rest of us, there has to be a better solution. So in answer to this limitation in HTML and the way reports are presented in a browser window, we have to come up with some creative solutions to actually print our report to a printer.

The following sections detail the different ways a report can be printed from the Web, as well as some of the advantages and drawbacks of each method. Because we are looking at new functionality within Crystal Reports .NET, we are going to create a new project specifically for this section.

From within Visual Studio, select File ^ New ^ Project and from Visual Basic Projects, select ASP .NET Web Application and call this new application web_viewer_print. This application is included with the download code. To use the downloaded version a virtual directory should again be created for it in its downloaded location.

Once you have clicked OK, the development environment will open with the default form that we will be using in the section.

We also need to add a report to work with in this section, so select Project ^ Add Existing Item. Change the drop-down list to show All Files and specify *.rpt for the file name to filter the list to show only the available reports. The web_printing_report.rpt file is in the code download path Crystal.NET2003\ Chapter05\web_printing_report.rpt.

Once you have selected the web_printing_report.rpt report, click Open and this report will be added to your project in the Solution Explorer. We will be looking at the different methods for printing this report in the following sections.

Now, simply drag a ReportDocument component onto the form, which should offer you web_viewer_printing.web_printing_report as first choice in the drop-down box. Select it and drag a CrystalReportViewer onto the Web Form. Now, to bind the ReportDocument component to the viewer, merely enter the following code in the Web Form's Page_Init event, as we have done more than once in this chapter:

CrystalReportViewer1.ReportSource = New web_printing_report()

Compile and run the application to check that everything is working. We are now ready to start looking at printing this report.

Printing from the Browser

The simplest method for printing a report is to print directly from the browser. You have already seen how well this works, but there are some tricks that we can use to improve the way the report prints if we are forced to use this method.

First, you can disable the DisplayGroupTree property if the report is likely to be printed. Do this by setting it to False in the Properties window, or you could do this programmatically by inserting the following code into the Page_Load event:

CrystalReportViewer1.DisplayGroupTree = False

The viewer object model provides a property called SeparatePages that by default is set to True, meaning that the report is chunked up into individual HTML pages based on the report pagination. When this property is set to False, the report itself becomes one long page, which can then be printed just like any other Web page. You can set this property through the property page of the Crystal Report Viewer, as shown in Figure 5-23.

Or you can also set this option programmatically:

CrystalReportViewer1.SeparatePages = False

Another trick is to actually turn off the toolbar and all of the icons so that the output on the page is close to what you would like to see when the report is printed.

CrystalReportViewer1.DisplayToolbar = False

</> web viewer method Microsoft Visual Basic .NET [design] WebForml.aspx SUDS

File Edit View Project Build Debug Data Format Table Frames Tools Window Help ffi-ft-G^yS&l^]®, ► Debug - & adonet_sample

» »

Toolbox * X

Start Page WebForml.aspx | product_listing_bytype.rpt | prpduct_listing_bytype.rpt | WebForml.aspx.vb |

Was this article helpful?

0 0

Post a comment