Custom Printer Settings in Active Report 7
Active Reports 7 is our award-winning .NET reporting tool that allow the users to completely control the report processing engine to fit their reporting needs. ActiveReports not just offers the unique reporting architecture but also provides unmanaged access to the print job, allowing tray selection and duplex printer management as the document is rendered to the printer. There are times when our users do not wish to use the default printer settings and want to print the report with their custom printer settings. Hence, this blog deals with some of the commonly asked user scenarios to implement custom printer settings in ActiveReports. Following three scenarios are covered in this blog:
- Silent Printing
- Passing custom settings to the Default PrintDialog
- Replacing Default PrintDialog with Custom PrintDialog
Let us take the scenarios one by one :
Silent Printing
Many a times the requirement is to print the report without allowing the end users to make any changes and print the report with pre-defined custom printer settings. In such a case, the printer settings can be set in the code. To avoid the PrintDialog, one can remove the Print Button from Viewer's Toolbar. Here is the sample code snippet that should be used :
'Hiding the default print button
Viewer1.Toolbar.ToolStrip.Items(2).Visible = False '2 is the index of the PrintButton in the ToolStrip
'Setting the custom Printer Settings
'Option 1 :
Viewer1.Document.Printer.PrinterName = "Microsoft XPS Document Writer"
Viewer1.Document.Printer.Landscape = True
Viewer1.Document.Print(False, False)
'Option 2 :
Report1.Document.Printer.PrinterName = "Microsoft XPS Document Writer" 'give the desired printer name
Report1.Document.Printer.Landscape = True
Report1.Document.Print(False, False)
Passing Custom Settings to Default PrintDialog
There are times, when our users do not want to disable the Default PrintDialog and instead want this PrintDialog to show the custom settings. In such a scenario, we will not hide the custom Print Button from the Toolbar and pass the custom setting to the default PrintDialog using the following code :
'Option 1 :
Viewer1.Document.Printer.PrinterSettings.PrinterName = "Microsoft XPS Document Writer" 'give the desired printer name
Viewer1.Document.Printer.Landscape = True
'Option 2 :
Report1.Document.Printer.PrinterSettings.PrinterName = "Microsoft XPS Document Writer" 'give the desired printer name
Report1.Document.Printer.Landscape = True
Replacing Default PrintDialog with Custom PrintDialog :
Simplest approach is to replace the default ‘Print’ toolbar button of the Viewer Control with the custom button. On its click event, show the custom PrintDialog. Once the user makes the changes and clicks 'OK', the settings are assigned to the Viewer.document/Report.document, to be printed.
'Replacing the default Print Button
Viewer1.Toolbar.ToolStrip.Items(2).Visible = False
Dim prnt_btn As New ToolStripButton
prnt_ btn.Image = Image.FromFile("..\\..\\Print.jpg")
AddHandler btn.Click, AddressOf test
Viewer1.Toolbar.ToolStrip.Items.Insert(2, prnt_btn)
'Assign custom properties
If Me.PrintDialog1.ShowDialog() = DialogResult.OK Then
'Option 1 :
Viewer1.Document.Printer.PrinterSettings = Me.PrintDialog1.PrinterSettings
Viewer1.Document.Print(False, False)
'Option 2 :
Report1.Document.Printer.PrinterSettings = Me.PrintDialog1.PrinterSettings
Report1.Document.Print(False, False)
Refer to the attached samples for the complete implementation : Download Sample : CSharp Download Sample : VB