Documente Academic
Documente Profesional
Documente Cultură
NET
Export and Print a Crystal Report
Overview
This white paper will walk you through creating a .NET Windows
application using Crystal Reports for Visual Studio .NET.
In the first section, you will create a basic Visual Basic .NET Windows
application that loads a report and previews it in the
CrystalReportViewer control. The next section explains how to export
the report to a portable document file (PDF) through code. The final
section explains how to print the application’s report to a printer through
code.
Contents
INTRODUCTION ............................................................................................ 2
CREATE A SIMPLE APPLICATION .................................................................. 2
Add a Crystal Report to the Project.............................................................3
Run the Project ............................................................................................4
EXPORT THE REPORT TO PDF ..................................................................... 5
Add an Export Button .................................................................................5
Add Exporting Code ....................................................................................5
Run the Project ............................................................................................6
PRINT THE REPORT TO A PRINTER ............................................................... 6
Add a Print Button......................................................................................6
Add Printing Code.......................................................................................7
Run the Project ............................................................................................7
FINDING MORE INFORMATION ...................................................................... 8
1/27/2005 1:54 PM Copyright © 2005 Business Objects. All rights reserved. Page 1
CR for VS .NET Export and Print a Report
Introduction
Crystal Reports for Visual Studio .NET extends the powerful reporting
capability of Crystal Reports on the Microsoft .NET platform. You can
use the Crystal Report Designer in Visual Studio .NET to create a new
Crystal Report or modify an existing Crystal Report. You can then keep
the report on a local computer, as is the case with this example, or
publish it as a Report Web Service on a web server. You can host the
report with the CrystalReportViewer control.
Figure 1
1/27/2005 1:54 PM Copyright © 2005 Business Objects. All rights reserved. Page 2
crnet_exportandprintreport.pdf
CR for VS .NET Export and Print a Report
Figure 2
5. Change the Files of Type: drop-down box to All Files (*.*), click
World Sales Report.rpt then click the Open button.
Figure 3
1/27/2005 1:54 PM Copyright © 2005 Business Objects. All rights reserved. Page 3
crnet_exportandprintreport.pdf
CR for VS .NET Export and Print a Report
If the compiler found any errors/warnings in the project, a task is created for each item,
NOTE and the Task List window will list all the tasks (errors/warnings).
2. On the Debug menu, click Start Without Debugging. This loads the
project and runs it without loading any of the debugging features.
The application runs faster if the debugging controls are not loaded.
When the application is run, you will see the World Sales Report in the
The CrystalReportViewer
control used to be called the CrystalReportViewer control (Figure 4).
Windows Form Viewer.
Figure 4
1/27/2005 1:54 PM Copyright © 2005 Business Objects. All rights reserved. Page 4
crnet_exportandprintreport.pdf
CR for VS .NET Export and Print a Report
Figure 5
To avoid confusion you may want to disable the export button on the
NOTE CrystalReportViewer. To do this, in the Properties window for the CrystalReportViewer,
change the ShowExportButton property to False.
1/27/2005 1:54 PM Copyright © 2005 Business Objects. All rights reserved. Page 5
crnet_exportandprintreport.pdf
CR for VS .NET Export and Print a Report
As you enter the ExportFormatType you will see a drop-down list of all the possible export
formats. Try exporting to these other formats as well. Remember to change the extension
NOTE of the DiskFileName value to the appropriate extension. For instance is you choose the
Excel format type, change the DiskFileName value to “C:\exported.xls”.
1/27/2005 1:54 PM Copyright © 2005 Business Objects. All rights reserved. Page 6
crnet_exportandprintreport.pdf
CR for VS .NET Export and Print a Report
Figure 6
To avoid confusion you may want to disable the print button on the CrystalReportViewer.
NOTE To do this, in the Properties window for the CrystalReportViewer, change the
ShowPrintButton property to False.
1/27/2005 1:54 PM Copyright © 2005 Business Objects. All rights reserved. Page 7
crnet_exportandprintreport.pdf
CR for VS .NET Export and Print a Report
You can also learn how to create a .NET Windows application using
Crystal Reports for Visual Studio .NET by following our sample
applications. Search for the files:
vbnet_win_samples.exe
and
vbnet_web_samples.exe
at:
http://support.businessobjects.com/search
www.businessobjects.com
Business Objects owns the following U.S. patents, which may cover products that are offered and sold by Business
Objects: 5,555,403, 6,247,008 B1, 6,578,027 B2, 6,490,593 and 6,289,352. Business Objects, the Business Objects
logo, Crystal Reports, and Crystal Enterprise are trademarks or registered trademarks of Business Objects SA or its
affiliated companies in the United States and other countries. All other names mentioned herein may be trademarks
of their respective owners. Product specifications and program conditions are subject to change without notice.
Copyright © 2005 Business Objects. All rights reserved.
1/27/2005 1:54 PM Copyright © 2005 Business Objects. All rights reserved. Page 8
crnet_exportandprintreport.pdf