User Tools

Site Tools


Sidebar

Multimedia

k23:k23.6:k23.6.3:start

23.6.3 Printer class (gb.form.print)

This class allows you to print documents on printers or save them in a file (PDF, PostScript). This class Printer (gb.form.print) is a new implementation of the class Printer (gb.qt4). Four (margin) properties and the Preview() method have been added.

The class can be created. How to create a new Printer object:

Dim hformPrinter As Printer
hformPrinter = New Printer() [ As "EventName" ]

23.6.3.1 Constants

The Printer (gb.form.print) class has the same constants as the Printer (gb.qt4) class, which are described in the 'Printer (gb.qt4) class' section.

23.6.3.2 Properties

The Printer (gb.form.print) class has the same properties as the Printer (gb.qt4) class, which are described in the 'Printer (gb.qt4) class' section.

The new implementation of the Printer (gb.form.print) class has been extended by 4 properties:

PropertyData typeDescription
Margin.TopIntegerReturn or specification of the top margin in millimetres.
Margin.RightIntegerReturn or set the right margin in millimetres.
Margin.BottomIntegerReturn or set the bottom margin in millimetres.
Margin.LeftIntegerReturn or specification of the left page margin in millimetres.

Table 23.6.3.2.1 : Additional properties of the Printer (gb.form.print) class

Like the Printer class (gb.qt4), the Printer class (gb.form.print) has these two static properties:

  • Default: Returns the name of the default printer.
  • List: Returns the list of printers.

23.6.3.3 Methods

The Printer class (gb.form.print) has the same methods as the Printer class (gb.qt4). However, the 'Preview()' method has been added to the new implementation:

MethodReturn typeDescription
Cancel()-Cancels the current print job.
Configure()BooleanOpens the printer configuration dialogue. This method returns TRUE if the user has cancelled the dialogue and FALSE otherwise.
Print()-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.
Preview()-Opens a print preview as a modal form.

Table 23.6.3.3.1 : Methods of the Printer class (gb.form.print)

23.6.3.4 Events

The Printer (gb.form.print) class has the same events as the Printer (gb.qt4) class.

EventDescription
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.
PaginateThis event is triggered so that you can paginate 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.3.4.1 : Events of the Printer class (gb.form.print)

23.6.3.5 Example

The following section presents an adaptation of the source code print programme from the Gambas IDE. It uses the margin property for all 4 margins and the print preview. In the preview, you can still make some changes to the design and layout of the print pages and then print the text directly to the selected printer or print it to a PDF file.

BILD_PREVIEW

Figure 23.6.3.5.1: Print preview

BILD-EDITOR

Figure 23.6.3.5.2: Text editor

Notes:

  • In the download area you will find the source code archive for the sample project.
  • You will find 9 different text files in the 'examples' folder in the project folder, which you can use to try out the print programme.

Download

Project

download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k23/k23.6/k23.6.3/start.txt · Last modified: 09.03.2024 by emma

Page Tools