Change Paper Size and Orientation in Crystal Reports .NET

Design tip of the sporadic time interval:

If you need to change the size or orientation of a Crystal Report, you can do this in the VS IDE by right-clicking your report and navigating Designer >> Printer Setup.  On the first tab, you can choose the paper size and orientation.  Hit OK to return to the IDE, and the report canvas will automatically resize to what you just specified.

I don’t recommend setting any of the advanced printer options in your report unless you know the people printing the report will be using the same printer (such as a network printer).  Also, if you can’t fit your report on letter (or A4 for the metric world), the user is probably going to have to change the paper in the printer, which will more than likely cause some grumbling.

If your report is too wide for landscape, consider grouping the data into a more hierarchical report (not every report can be grouped, but many can).  Not only will this improve the readability, but it’ll help fit the report on a standard paper size.

Right-click in the whitespace on your report, not on a section heading.  You get different menus when you right-click on a section head.

If changing the printer information in your report generates printer errors (such as “Invalid Printer Specified“) when viewed on other machines, try changing the printer information at run time.  Here is a knowledgebase article that will help:

How to Change Printers at Runtime using Crystal Reports for Visual Studio .NET

If you want to set up a report for 8.5×14, you need to select a printer capable of printing 8.5×14 paper.  The location to choose the paper size depends on the printer driver.  In most HP printers, there is a tab called “Paper“.

Crystal Reports .NET Programming
If you’re new to Crystal Reports, or just to CR .NET, this is the book you need. Part how-to, part programming reference, lots of simple examples in both C# and VB.NET.





Updating Crystal Reports .NET if You Change the XSD

One method of creating Crystal Reports is to use an ADO.NET Dataset (for good advice please read Reporting Off ADO.NET Datasets).  To create the report from a dataset, you have to model the dataset in an XML Schema Document, which has the .XSD extension.  You use the XSD as the ‘source’ of your report at design time, and at runtime, set the data source to the ADO.NET dataset in memory.

From time to time, requirements for your reports change, and you have to change the dataset.  If you used an XSD to design your report, you need to follow these steps to update your report:

1) Update your XSD.  Either make the changes manually, or re-create the entire document, whichever is easier.
2) Open your report in design view in VS .NET.
3) Open the Field Explorer, and right-click on “Database Fields”.
4) Choose “Set Location…” from the menu.
5) Choose the data source you wish to update in the “Current Data Source” dropdownlist.  You can choose either the entire dataset, or just a single table (in many cases, there will only be one table per dataset, so either choice is as good as the other in this case).
6) In the “Replace with” window, expand “More Data Sources”, then “ADO.NET (XML)”.
7) Double-click “Make New Connection”.  You may see your dataset listed, however, I have found from experience that sometimes you need to overwrite the cached version.
8) In the new window, browse to your XSD and choose “Finish”.  Leave “Use Visual Studio Data Class” unchecked.
9) If you have a table chosen in the “Current Data Source” dropdownlist, highlight the replacement table you just added, and click “Replace”.  If you have a dataset chosen, highlight the replacement dataset and click “Replace”.  If the “Replace” button is not activated, you need to make sure you have the correct structure chosen in both places.
10) Click “Close”.  You may be asked to remap fields if any field changed its data type.  To map the fields, un-check “match type”, and match fields one by one, clicking “Map” after each selection.  Do this until all the fields that need to be re-mapped have been re-mapped.
11) You should now see all yoru changes reflected in the Fields Viewer (you may have to expand “Database Fields”).

SQL Server Reporting Services and Crystal Reports: A Competitive Analysis

Brian Bischof, author of Crystal Reports .NET Programming, has posted a comparison of SQL Server Reporting Services and Crystal Reports:

During 2004, Microsoft grabbed the attention of the Visual Studio .NET community by announcing a new reporting product: SQL Server Reporting Services (SSRS). Not only did they promise to give programmers a new reporting tool, but it was going to be free as well. Suddenly everyone was comparing Reporting Services to Crystal Reports – the report designer that has been bundled with VB since VB 3 and integrated into Visual Studio .Net (and will also be included in the next release of Visual Studio .Net 2005).

The goal of this paper is to illustrate differences between SSRS and the current version of Crystal Reports, Crystal Reports XI (version 11). Each product has its strengths and weaknesses and these are highlighted here. It’s important to evaluate each product and consider which one works best for your application’s reporting requirements.


Open PDF Outside of Browser

This question has passed my threshold of answering as forum posts, so it’s going on the blog:

Does anyone know how to export a crystal report into a seperate adobe reader instead of embedding the reader into the current browser window?

I am successful in exporting to pdf and excel, but it would be great if I could bring up a “save as or open” prompt.

Any ideas would be greatly appreciated.

The “save as or open” prompt is something the browser does automatically when it encounters a file type it can’t open itself (either unknown file type or viewer program unknown).  There is a setting in Acrobat Reader you can use to override this, but it’s one the clint has to make–you can’t script it.  For Reader 6, go to Edit >> Preferences >> Internet, and uncheck “Display PDF In Browser”.

If this doesn’t solve your problem, try reading CodeSnip: Opening Crystal Reports in a New Window in ASP.NET.

Set Number Of Copies When Automatically Printing Crystal Reports .NET

These questions were received as a private comment in response to my Automatically Printing Crystal Reports in ASP.NET article:

Very useful and interesting article. Thanks a lot. I wanted to use this in a .Net app. Can we determine the number of copies to be printed dynamically using the second method(javascript)? Say If the user clicks on the print button (HTML submit button), the application would pre-determine how many copies can be printed for that user and automatically print them?
Also, the second window was opening in full size for me instead of 0 height and width. Please let me know what I’m doing wrong here?
Again…this is a wonderful article.

To the best of my knowledge, I don’t think you can set the number of copies to print through JavaScript.  When printing from a browser, all print settings are handled through the browser’s print dialog, and I don’t know of any way to script that without getting into ActiveX and trust permissions.

It’s tough to tell what’s going on in the second question because there are a couple of code snippets that open new windows.  My best guess would be that the script string isn’t being renered correctly.  View the source of the parent page, and look for the rendered script string.  Make sure it’s correct after it’s rendered.

A Crystal Reports job failed because a free license could not be obtained in the time allocated.

“A Crystal Reports job failed because a free license could not be obtained in the time allocated. More licenses can be purchased direct from Crystal Decisions or through the Crystal Decisions Online Store.”

This error can be due to a number of factors.  If you have deployed your application on a server and get this message, it means you possibly entered the wrong keycode when you registered Crystal Reports .NET 2003.  You can follow these instructions from Business Objects to reset the keycode:  You will have to register your CR .NET again when you open a report in Visual Studio.

Something else to check is that all the versions of the referenced components are correct.  In my recent case, I was preparing for a demonstration on my laptop.  I had installed CR 10 before installing Visual Studio 2003.  When I created my demo project in Visual Studio, all of the referenced Crystal Decisions components were 9.1.5000.0 except for CrystalDecisions.CrystalReports.Engine.  That component was version 10.0.3300.0.  By deleting this incorrect reference, and adding the correct version, the error was resolved.

Setting Parameters in Crystal Reports .NET

I see this question quite often in the Crystal Reports forum at ASP.NET.  My advice is always to download the web samples at:

Visual Basic .NET Web Samples

C# .NET Web Sample Applications

Then, follow the Readme file to install the “Discrete Parameters” example.  This has been my guide, and it works great.

Additional help and tutorials are in the CR SDK:

Crystal Reports .NET SDK – Additional Conceptual Documentation and Tutorials

This file contains additional conceptual information and tutorials for using Crystal Reports in Visual Studio .NET (including a developer reference). This documentation applies to Crystal Reports 9 & 10 and Crystal Reports for Visual Studio .NET 2002 & 2003. Sample applications built using these tutorials are available for download (

Crystal Reports .NET SDK – Sample Applications from Tutorials

This file contains C# and VB .NET Windows and web sample applications. These samples were built using the tutorials provided in the ‘Crystal Reports .NET SDK – Additional Documentation and Tutorials’ ( These sample applications applies to: Crystal Reports 9 & 10 and Crystal Reports for Visual Studio .NET 2002 & 2003.  

A number of methods out there use the CrystalReportViewer control to set parameters.  That’s great unless you need to export your report to PDF (or XLS or RTF).  This is a code snippet I use, which sets parameter values directly on the Report Document object:

  rptCount = New ReportDocument

  ”Get the collection of parameters from the report
  crParameterFieldDefinitions = rptCount.DataDefinition.ParameterFields
  ”Access the specified parameter from the collection
  crParameter1 = crParameterFieldDefinitions.Item(“Param1”)
  crParameter2 = crParameterFieldDefinitions.Item(“Param2″)

  ”Get the current values from the parameter field.  At this point
  ”there are zero values set.
  crParameter1Values = crParameter1.CurrentValues
  crParameter2Values = crParameter2.CurrentValues

  ”Set the current values for the parameter field
  crDiscrete1Value = New ParameterDiscreteValue
  crDiscrete1Value.Value = Request.Form(“param1value“)

  crDiscrete2Value = New ParameterDiscreteValue
  crDiscrete2Value.Value = Request.Form(“param2value“)

  ”Add the first current value for the parameter field

  ”All current parameter values must be applied for the parameter field.

Once you get used to working with parameters, you can “automagically” display them on your web pages.  This series of articles shows you how to get a list of parameters from your report file, and display them on your web form, where you can prompt for inputs:

Automagically displaying a Crystal Reports Parameters – Part I
Automagically displaying a Crystal Reports Parameters – Part II
Automagically displaying a Crystal Reports Parameters – Part III

If you’re new to Crystal Reports .NET, get this book:

Crystal Reports .NET Programming

It is both an introduction to Crystal Reports .NET, as well as a object model programming guide/reference.  Examples are in both VB.NET and C#.