Printing Drawing Documents

From Apache OpenOffice Wiki
Jump to: navigation, search

Printer and Print Job Settings

Printing is a common office functionality. Refer to Chapter Office Development for additional information. The Draw document implements the interface for printing. It consists of three methods:

 sequence< com::sun::star::beans::PropertyValue > getPrinter()
 void setPrinter( 
     [in] sequence< com::sun::star::beans::PropertyValue > aPrinter)
 void print( 
     [in] sequence< com::sun::star::beans::PropertyValue > xOptions)

To print to the standard printer without settings, use the snippet below with a given document xDoc:

 // query the XPrintable interface from your document
 XPrintable xPrintable = (XPrintable)UnoRuntime.queryInterface(XPrintable.class, xDoc);
 // create an empty printOptions array
 PropertyValue[] printOpts = new PropertyValue[0];
 // kick off printing

There are two groups of properties involved in general printing. The first one is used with setPrinter() and getPrinter(), and controls the printer, the second one is passed to print() and controls the print job.

The method getPrinter() returns a sequence of PropertyValue structs describing the printer containing the properties specified in the service It comprises the following properties:

Properties of
Name string - Specifies the name of the printer queue to be used.
PaperOrientation Specifies the orientation of the paper.
PaperFormat Specifies a predefined paper size or if the paper size is a user-defined size.
PaperSize Specifies the size of the paper in 1/100 mm.
IsBusy boolean - Indicates if the printer is busy.
CanSetPaperOrientation boolean - Indicates if the printer allows changes to PaperOrientation.
CanSetPaperFormat boolean - Indicates if the printer allows changes to PaperFormat.
CanSetPaperSize boolean - Indicates if the printer allows changes to PaperSize.

The PrintOptions offer the following choices for a print job:

Properties of
CopyCount short - Specifies the number of copies to print.
FileName string - If set, specifies the name of a file to print to.
Collate boolean - Advises the printer to collate the pages of the copies. If true, a whole document is printed prior to the next copy, otherwise copies for each page are completed together.
Pages string - Specifies the pages to print. It has the same format as in the print dialog of the GUI, for example, 1, 3, 4-7, 9.
Wait boolean - Advises that the print job should be performed synchronously, i.e. wait until printing is complete before returning from printing. Otherwise return is immediate and following actions (e.g. closing the corresponding model) may fail until printing is complete. Default is false.

The following method uses PrinterDescriptor and PrintOptions to print to a specific printer, and preselect the pages to print:

The following method uses both, PrinterDescriptor and PrintOptions, to print to a specific printer and preselect the pages to print:

 protected void printDocComponent(XComponent xDoc) throws java.lang.Exception {
     XPrintable xPrintable = (XPrintable)UnoRuntime.queryInterface(XPrintable.class, xDoc);
     PropertyValue[] printerDesc = new PropertyValue[1];
     printerDesc[0] = new PropertyValue();
     printerDesc[0].Name = "Name";
     printerDesc[0].Value = "5D PDF Creator"; 
     PropertyValue[] printOpts = new PropertyValue[1];
     printOpts[0] = new PropertyValue();
     printOpts[0].Name = "Pages";
     printOpts[0].Value = "1-4,7"; 

In Draw documents, one slide is printed as one page on the printer by default. In the example above, slide one through four and slide seven are printed.

Special Print Settings

The printed drawing view (drawings, notes, handout pages, outline), the print quality (color, grayscale), the page options (tile, fit to page, brochure, paper tray) and additional options (page name, date, time, hidden pages) can all be controlled. Settings describes how these settings are used.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages