The class allows you to output documents directly to printers or to print and save the documents in a file (PDF or PostScript).
The class can be created. To create a new Printer object:
Dim hPrinter As Printer hPrinter = New Printer() [ As "EventName" ]
The Printer class has these constants:
Constant | Numeric value | Description |
---|---|---|
Custom | 0 | User-defined paper size. The paper size is defined via the PaperHeight and PaperWidth properties. |
A3 | 1 | Paper size: 297 × 420 mm. |
A4 | 2 | Paper size: 210 × 297 mm or 8.26 × 11.69 inches. |
A5 | 3 | Paper size: 148 × 210 mm. |
B5 | 4 | Paper size: 182 × 257 mm or 7.17 × 10.13 inches. |
Executive | 6 | Paper size: 7.5 × 10 inches or 191 × 254 mm. |
Legal | 7 | Paper size: 8.5 × 14 inches or 216 × 356 mm. |
Letter | 5 | Paper size: 8.5 × 11 inches or 216 × 279 mm. |
Horizontal | 1 | Both sides of a sheet of paper are used for printing. The paper is flipped over its horizontal edge. |
Vertical | 2 | Both sides of a sheet of paper are used for printing. The paper is turned over its vertical edge. |
Portrait | 0 | The height of the page is greater than its width (portrait format). |
Landscape | 1 | The width of the page is greater than its height (landscape format). |
Simplex | 0 | Only single-sided printing (simplex). |
Table 23.6.1.0.1 : Constants of the Printer class (gb.qt4)
The Printer class has these properties:
Property | Data type | Description |
---|---|---|
CopyCount | Integer | Returns or sets the number of copies to be printed. |
CollateCopies | Boolean | Returns or specifies whether or not multiple copies should be collated into one document. |
Count | Integer | Returns or specifies the number of pages of the document to be printed. By default, the printed document consists of one page. |
Duplex | - | Returns or sets the duplex printing mode. This property can have one of the following 3 values: Printer.Simplex: Only one-sided printing (simplex). Printer.Horizontal: Both sides of a sheet of paper are used for printing. The paper is rotated over its horizontal edge. Printer.Vertical: Both sides of each sheet of paper are used for printing. The paper is rotated over the vertical edge. |
FirstPage | Integer | Returns or specifies the first page to be printed. If this property is set to zero, the entire document is printed. |
LastPage | Integer | Returns or specifies the last page to be printed. If this property is set to zero, the document is printed up to the last page. |
FullPage | Integer | Returns or specifies whether the page should be drawn within the margins (FullPage is FALSE) or on the entire page (FullPage is TRUE). By default, this property is FALSE and (standard) margins are used. |
GrayScale | Boolean | Returns or specifies whether the print is in greyscale or full colour. |
Name | String | Return or specify the printer name. The printer name identifies the printing device to which the document to be printed is sent. |
NumCopies | Integer | Return/set the number of copies to be printed. |
Orientation | Integer | Returns or defines the print orientation. This property can have one of the following values Printer.Portrait (0): The height of the page is greater than its width. This is the default value. Printer.Landscape (1): The width of the page is greater than its height. |
OutputFile | String | Returns or sets the path of the PDF or PostScript output file. |
Page | Integer | Returns the current page that needs to be printed. |
Paper | - | Return or specification of the paper type for printing. This property can have one of the following values Printer.A4, Printer.A3, Printer.B5, Printer.Letter, Printer.Executive or Printer.Legal. Attention: This property returns Paper.Custom if the Printer.PaperWidth or Printer.PaperHeight properties have been defined! |
PaperHeight | Integer | Returns or sets the custom paper height in millimetres. |
PaperWidth | Integer | Returns or sets the custom paper width in millimetres. |
Resolution | Integer | Return or set the printer resolution in DPI (Dots Per Inches). |
ReverseOrder | Boolean | Return or specify whether the document pages should be printed in reverse order. |
Table 23.6.1.0.2 : Properties of the Printer (gb.qt4) class
The Printer class (gb.qt4/5) also has these two static properties:
Example
If Printer.List.Count = 0 Then sMessage = "<b><font size='+1', color='DarkRed'>" sMessage &= ("P R I N T - M O D U S") sMessage &= "</b></font><hr>" sMessage &= "->> " & ("No installed printer was detected.") & "<br>" sMessage &= "->> " & ("The program will be ended!") Message.Error(sMessage) Quit Else Print "Standard-Printer = "; Printer.Default Endif
This allows you to read out some of the default values or the defined properties of the printer:
Print "DruckerName = "; hPrinter.Name Print "CollateCopies = "; hPrinter.CollateCopies Select Case hPrinter.Duplex Case 0 Print "Duplex = 0: Single sided (simplex) printing only." Case 1 Print "Duplex = 1: Both sides of each sheet of paper are used for printing. The paper is turned over its horizontal edge." Case Else Print "Duplex = 2: Both sides of each sheet of paper are used for printing. The paper is turned over its vertical edge." End Select Print "FullPage = "; hPrinter.FullPage Print "GrayScale = "; hPrinter.GrayScale Print "NumCopies = "; hPrinter.NumCopies If hPrinter.Orientation = 0 Then Print "Orientation = "; "Portrait" Else Print "Orientation = "; "Landscape" Endif If hPrinter.OutputFile <> Null Then Print "OutputFile = "; hPrinter.OutputFile Else Print "OutputFile = NULL (Printout on the installed printer)" Endif Print "Paper (2=DINA4) = "; hPrinter.Paper Print "PaperHeight (mm) = "; hPrinter.PaperHeight Print "PaperWidth (mm) = "; hPrinter.PaperWidth Print "Resolution (DPI) = "; hPrinter.Resolution Print "ReverseOrder = "; hPrinter.ReverseOrder
This is the output in the console of the IDE:
DruckerName = FS-1030D CollateCopies = True Duplex = 1: Both sides of each sheet of paper are used for printing. The paper is turned over its horizontal edge. FullPage = True GrayScale = True NumCopies = 1 Orientation = Portrait OutputFile = NULL (Printout on the installed printer) Paper (2=DINA4) = 2 PaperHeight (mm) = 297 PaperWidth (mm) = 210 Resolution (DPI) = 300 ReverseOrder = False
The Printer class has these methods:
Method | Return type | Description |
---|---|---|
Cancel() | - | Cancels the current print job. |
Configure() | Boolean | Opens the printer configuration dialogue. This method returns TRUE if the user has cancelled the dialogue and FALSE otherwise. |
Boolean | The print process is started. A local event loop is executed during the process and the method returns when printing is complete. This method returns TRUE if the user has cancelled the print process or if an error has occurred. FALSE is returned if everything was OK. |
Table 23.6.1.0.3 : Methods of the Printer class (gb.qt4)
The Printer class has these events:
Event | Description |
---|---|
Begin() | This event is triggered when the printing process begins. |
End() | This event is triggered when printing is complete. |
Draw() | This event is triggered for each (new) page that needs to be printed. |
Paginate() | This event is triggered so that you can paginate (add page numbers to) your document in the background. If you do not define an event handler, this event is not triggered. You must then define the Count property within the Begin() event handler. Otherwise - if you handle this event - the event handler will be called again and again until you explicitly define the Count property. |
Table 23.6.1.0.4 : Events of the Printer class (gb.qt4/5)