This blog deals with both the requirements, i.e., 'Customizing the PaperSize' and 'Customizing the Printer Settings.'
There are two ways to customize the report's papersize:
- Set the 'DefaultPageSettings.PaperSize' property of the C1Report Document.
- Set the 'Layout.Papersize' property of C1Report.
The following are the steps to customize the C1Report's papersize:
1. Set the 'Layout.PaperSize' property to 'PaperKind.Custom.'
2. Define the custom size by setting the 'Layout.CustomHeight' and 'Layout.CustomWidth' properties of the C1Report.
C1Report1.Layout.PaperSize = PaperKind.Custom 'the value is to be assigned in twips C1Report1.Layout.CustomHeight = " " C1Report1.Layout.CustomWidth = " "
The following are the steps to customize the C1Report Document's (PrintDocument) papersize:
1. Create an instance of PrintDocument and assign the C1Report to it.
2. Create an instance of 'PaperSize' (say 'MyCustomPapersize') and assign custom height and width values to it.
3. Set the 'DefaultPageSettings.PaperSize' property to this custom papersize.
Dim PrintDoc As New PrintDocument Dim cps As New PaperSize PrintDoc = C1Report1.Document 'define the custom paper size as per requirements 'the value is to be assigned in points cps = New PaperSize("MyCustomPaperSize", "CustomHeight", "CustomWidth") 'assign custom papersize to printdocument PrintDoc.DefaultPageSettings.PaperSize = cps
Many of our customers have asked us queries in which they face issues while printing the report with changed printer settings. Even after changing the printer settings of the report just before printing, the same is not reflected in the printed report and the printing of the report takes place as per the default settings. This mainly happens as the changes have been made in the report's printer settings. However, the same has not been passed to the printer; hence, the printing takes place with the default settings of the printer.
In order to print the report with the custom settings, we need to make use of the 'Custom PrintDialog' which will be displayed on the click event of the 'Print' button of the 'C1PrintPreviewControl.'
1. Delete the default 'Print' toolbar button from the C1PrintPreviewControl.
2. Add a custom toolbar button in the C1PrintPreviewControl. You may refer to the following blog for the steps of the same:
Adding Custom Button Preview Controls
3. On the 'Click' event of this button, assign the C1Report's/ C1Report Document's printersettings to the printersettings of the 'Custom PrintDialog.'
4. Show the 'Custom PrintDialog.'
5. Finally, print the report.
Dim pd As PrintDialog = New PrintDialog() pd.PrinterSettings = C1Report1.Document.PrinterSettings If pd.ShowDialog() = DialogResult.OK Then C1Report1.Document.Print() End If
Dim pd As PrintDialog = New PrintDialog() pd.PrinterSettings = PrintDoc.PrinterSettings If pd.ShowDialog() = DialogResult.OK Then PrintDoc.Print() End If
Using the above steps, this is how the C1Report will look with a custom PaperSize of 500x650. Implementation is given in the attached sample.