Create Custom Print Dialogs and Print Directly from FlexReport

A FlexReport can be viewed on the screen or printed on paper. Usually, reports are created using FlexReport Designer and then printed using the Print option available in the designer's Preview Mode. However, some customers need to print the reports directly or using a custom print dialog so they can control how a document's content is to be printed, and specify the printer settings beforehand.

Before we go into the details of the code, let’s look at setting the following print options to customize the printing:

i. Printer Name

ii. Number of Copies

iii. Print Range

iv. PaperSource

v. PaperSize

Create an instance of C1PrintOptions to set the printer name, number of copies and print range:

C1PrintOptions options = new C1PrintOptions();
//setting PrinterName
options.PrinterSettings.PrinterName = printer;

//setting No. of Copies
options.PrinterSettings.Copies = 2;

//setting Print Range
options.PrinterSettings.PrintRange = PrintRange.SomePages;
options.PrinterSettings.FromPage = 1;
options.PrinterSettings.ToPage = 2;

Set PaperSource by specifying the desired source of the printer:

//setting PaperSource
PaperSource source = new PaperSource();
source.SourceName = “SourceName”;
options.PrinterSettings.DefaultPageSettings.PaperSource = source;

Finally, we'll set PaperSize under the DefaultPageSettings:

//setting PaperSize to A3
for (int i = 0; i <= options.PaperSizes.Count - 1; i++)
    if ((options.PaperSizes[i].Kind == PaperKind.A3))
        options.DefaultPageSettings.PaperSize = options.PaperSizes[i];

Now that we're done with the settings, let's look at the two approaches used for printing the reports.

How to create a custom print dialog in FlexReport

Using a custom print dialog is an excellent option if you need to print the reports through a dialog and change the default Printer Settings at the same time. For the case of printing through a dialog, the PrinterSettings instance is used. Additionally, the page range specification is slightly different than in the direct printing case. Thus, the dialog representing pages 5 to 6 in the range, that has slightly different code snippet, which is:

PrinterSettings options = new PrinterSettings();
//setting Print Range
options.PrintRange = PrintRange.SomePages;
options.FromPage = 5;
options.ToPage = 6;

Ensure that you set the dialog’s PrinterSettings to the instance of the PrinterSettings declared above. Then we can display the dialog and use FlexReport’s Print method to print the report when the Print button is clicked.

dialog.AllowSelection = true;
dialog.AllowSomePages = true;
dialog.PrinterSettings = options;
if (dialog.ShowDialog() == DialogResult.OK)

Tip: Set the AllowSelection and SomePages properties of the Print Dialog to true.

Here's how the dialog looks.

Custom print dialog in FlexReport

How to print directly from FlexReport

For the case of printing directly, the C1PrintOptions instance is used. When you want to print the reports directly without showing all the settings behind the printing process, the Print methods of FlexReport come to the rescue.

Here, the settings are similar as stated above. You just need to use the Print method wisely:


You can learn about the various overloads of the Print method in the documentation.

Do you have other printing requirements? Share in the comments!

Download the Printing from FlexReport Sample: C# / VB.NET

Try ComponentOne FlexReport

Esha Dhir

Associate Software Engineer
comments powered by Disqus