Customizing PaperSize & PrinterSettings of C1Report

C1Report allows us to create and print reports as per our requirements. Generally, the size in which the report is created is A4/Letter. However, there may be certain situations when the page size of the default printer of the machine is other than A4/Letter (say it is set to envelope or label) or the user wants to display the report in some custom size and print the report in the same displayed size. This blog deals with both the requirements, i.e., 'Customizing the PaperSize' and 'Customizing the Printer Settings.'

Customize PaperSize

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.

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. Code:

C1Report1.Layout.PaperSize = PaperKind.Custom  
'the value is to be assigned in twips  
C1Report1.Layout.CustomHeight = " "  
C1Report1.Layout.CustomWidth = " "

C1Report Document: 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. Code:

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

Customize PrinterSettings

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.' Steps: 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. Code: C1Report:

Dim pd As PrintDialog = New PrintDialog()  
pd.PrinterSettings = C1Report1.Document.PrinterSettings  
If pd.ShowDialog() = DialogResult.OK Then  
End If

C1Report Document:

Dim pd As PrintDialog = New PrintDialog()  
pd.PrinterSettings = PrintDoc.PrinterSettings  
If pd.ShowDialog() = DialogResult.OK Then  
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. Download Sample


GrapeCity Developer Tools
comments powered by Disqus