|
||||||
OpenOffice Macros: Printing a DocumentHow to Print OpenOffice.org Documents by Using a Macro
One of the most fundamental thing that any OpenOffice user will want to do is to print a document. This turorial shows exactly how to do this - automatically from a macro
Anyone writing OpenOffice.org Basic Macros will need to print documents - automatically; and when they do that they might well expect to use a simple print statement. They, of course, won't be disappointed because that's exactly what they will find. Unfortunately life (and OpenOffice Basic) is never quite as simple as that (and if it was then this would be a very short article) Printing an OpenOffice Document from a MacroPrinting an OpenOffice.org document from a macro is simple - as long as the print function is handled correctly - and that means supplying the correct parameters; so a macro to print a document would be: Sub PrintMe thisComponent.Print (Array ()) End Sub Anyone new to creating macros may wonder what this means, but it's quite simple:
And the result of running this macro? The current document is sent directly to the default printer. Adding Printer Parameters to a MacroIn the above example an empty array is passed to the document's print method, causing the document to be sent directly to the printer; and it won't take long for any macro developer to work out that this array is the means by which they can send parameters to the printer - parameters to modify the way in which the document is to be printed, such as:
So then it's just a matter of knowing what the parameters are and how to add them to the array. Printing More Than One Copy of a DocumentThe best way for a new user to understand how to add a printer parameter is to see an actual example, in this case how to print more than one copy: Sub PrintMe Dim PrintProperty(0) as New com.sun.star.beans.PropertyValue PrintProperty(0).Name = "CopyCount" PrintProperty(0).Value = 2 thisComponent.Print (PrintProperty) End Sub This time the code is used to:
From this it's obvious how the parameters should be manipulated:
And all of this can be made clearer by looking at another example. Printing Defined PagesIf more than one parameter is to be used then the size of the array must be increased accordingly: Dim PrintProperty(1) as New com.sun.star.beans.PropertyValue PrintProperty(0).Name = "CopyCount" PrintProperty(0).Value = 2 PrintProperty(1).Name = "Pages" PrintProperty(1).Value = "1;3-5;9" thisComponent.Print (PrintProperty) In this example,
Printing to a FileThe default when printing is to print to a printer (no surprise there then), however it is possible to print directly to a file:
Collating the Pages to be PrintedIf multiple copies need to be printed and collated then:
ConclusionThe parameters available to OpenOffice.org's print method are not extensive, but that means that is very simple to use; and a user will find it easy to access its limited number of parameters:
Most imporantly, a user is able to print an OpenOffice document automatically - just by running a simple macro.
The copyright of the article OpenOffice Macros: Printing a Document in Office/Business Software is owned by Mark Alexander Bain. Permission to republish OpenOffice Macros: Printing a Document in print or online must be granted by the author in writing.
Comments
Nov 28, 2008 1:35 PM
Guest :
1 Comment:
|
||||||
|
|
||||||
|
|
||||||