Previous Document Next Document

Understanding the CorelDRAW object model : Working with documents : Printing documents


Printing documents

Using VBA to print documents is straightforward: almost all settings that are available in the Print dialog box are available to the Document.PrintSettings property. When these properties are set, printing the document is simply a matter of calling the Document.PrintOut method.

For example, the following VBA code prints three copies of pages 1, 3, and 4 to a level-3 PostScript printer:

With ActiveDocument.PrintSettings
.Copies = 3
.PrintRange = prnPageRange
.PageRange = "1, 3-4"
.Options.PrintJobInfo = True
With .PostScript
.DownloadType1 = True
.Level = prnPSLevel3
End With
End With
ActiveDocument.PrintOut

Each page in the Print dialog box has a corresponding object-model class that contains all settings for that page. The following table lists these classes.

Page in Print dialog box
Class in object model
General
PrintSettings
Layout
PrintSettings and PrintLayout
Separations
PrintSeparations and PrintTrapping
Prepress
PrintPrepress
PostScript
PrintPostScript
Misc
PrintOptions

 
You cannot set layout options in VBA. However, if necessary, you can open the Print dialog box by using the PrintSettings.ShowDialog method.

 
You can print only the selected objects in a document by setting the PrintSettings.PrintRange property to prnSelection.
 
You can use a specific printer in the Application.Printers collection by specifying it in the PrintSettings.Printer property.
 
You can save a printing profile by using the PrintSettings.Save method.
 
You can access a saved printing profile by using the PrintSettings.Load method, but be sure to specify the full path to the profile.
 
You can reset the print settings by using the PrintSettings.Reset method.

If you want, you can use event handlers to respond to events that are triggered by opening the Print dialog box:

 
Application.DocumentBeforePrint
 
Document.BeforePrint
 
GlobalMacroStorage.DocumentBeforePrint

You can also use event handlers to respond to events that are triggered by printing a document and closing the Print dialog box:

 
Application.DocumentAfterPrint
 
Document.AfterPrint
 
GlobalMacroStorage.DocumentAfterPrint

Finally, you can also use event handlers to respond to events that are triggered when the user responds to a request to print a document:

 
Application.QueryDocumentPrint
 
Document.QueryPrint
 
GlobalMacroStorage.QueryDocumentPrint

Previous Document Next Document Back to Top

Copyright 2013 Corel Corporation. All rights reserved.