## Printer

### Description

The Printer class gives you control over the printer, and also allows you to display the standard dialogs related to printing. This is an invisible, top-level object (i.e. it should not be created as a child of a window object).

To use a Printer object, you first create it as a top-level object. You can then if you wish call the `Setup` and `Job` methods to display the standard printer page-setup and print-job dialogs, allowing the user to set the printing parameters. Both of these methods return 1 if the user selected OK and 0 for Cancel.

Output to the printer or spool file begins when you `Open` the printer (this starts a new print job). You have control over the font and placement of the text using the `font` and `position` properties. Calling the `Print` method allows you to print text (either as a character vector, possibly with embedded carriage returns, or as a character matrix). Printing starts at the current position, and the `position` property is updated at the end of the `Print` method to reflect where the printing position has reached. If, during printing, the position reaches the bottom margin of the page, a page throw will automatically be generated and printing will resume at the top, left of the next page. You can fine-tune the line height and character pitch using the `lineheight` and `pitch` properties.

To draw graphics and arbitrary text on the printer page, you can use the `Draw` method. (If you have already used the `Draw` method to create the graphics in a window, you can retrieve a nested array of drawing commands from the window using the `Draw` `'State'` keyword, and then re-submit the same commands to the Printer object as the argument of the printer's `Draw` method).

The `Eject` method forces a page throw. When you have output all the text, you call the `Close` method which ends the print job and submits it to the printer. If you want to abort the print job, call the `Abort` method.

The `margin` property, a four-element vector, allows you to set or retrieve the Left/Right/Top/Bottom margins in the current `scale`. Other useful properties include `copies` (the number of copies which will be printed), and `orientation` (a boolean scalar, 0=Portrait, 1=Landscape). These are read-only once the print job has started using `Open`.

There are a number of read-only properties associated with a Printer object. These include `page` (the current page number), `size` (the page size), `handle` (the handle to the printer record, used in low-level programming), and `winptr` (the display context/port also for low-level programmng). Under Windows, the `fonts` property lists available printer fonts.

Note that, although it is possible to create more than one Printer object, only one can be used at a time. In general, we recommend that you do not create more than one Printer in your application.

#### Automatic (unattended) printing

If you want to print without user intervention (i.e. without displaying a dialog), you must set the parameters for the print job before calling the `Open` method. You can select the page orientation by setting the `orientation` property, and (except under MacOS), the number of copies by setting the `copies` property.

Under Windows only, if you have several printers accessible from your system, you can also select a particular one under program control. The `printers` read-only property returns a nested vector of the names of each available printer. The `printername` property allows you to select one of these, or query which one is selected.

### Example

         ’DEMO_Printer;TEXT;PRN
    [1]   © Sample function demonstrating use of the Printer object
    [2]   PRN„'Ś' ŚNEW 'Printer' Ş PRN.scale„3 Ş PRN.margin„72 72 72 72
    [3]   ©
    [4]   © Put up the printer select dialog, quit on cancel
    [5]   …(0=PRN.Setup)/0
    [6]   ©
    [7]   © (We could also display the Job dialog here)
    [8]   ©
    [9]   © Now open the printer to start the job, and print some text
    [10]  PRN.Open
    [11]  PRN.font„'Times' 36 1
    [12]  PRN.color„220
    [13]  PRN.Print('Quotation',ŚR)
    [14]  PRN.font„'Times' 18 0
    [15]  PRN.color„0
    [16]  PRN.Print('Let me not to the marriage of true minds',ŚR)
    [17]  PRN.Print('Admit impediments.  Love is not love',ŚR)
    [18]  PRN.Print('Which alters when it alteration finds,',ŚR)
    [19]  PRN.Print('Or bends with the remover to remove.',ŚR,ŚR)
    [20]  PRN.font„'Times' 9 2
    [21]  PRN.Print 'William Shakespeare'
    [22]  ©
    [23]  © Close printer to submit the job
    [24]  PRN.Close
         ’

### Properties

caption children class color copies data events font fonts handle lineheight margin methods name opened orientation page pitch position printers printername properties scale self size tie units winptr

### Methods

Abort Close Create Delete Draw Eject Job New Open Print Send Set Setup Trigger

### Callbacks

onClose onDestroy onOpen onSend

Topic: APLX Help : System Classes : List of Classes : Printer

[ Previous | Next | Contents | Index ]