1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.printing;
17 import org.eclipse.swt.*;
18 import org.eclipse.swt.graphics.*;
21 * Instances of this class are descriptions of a print job
22 * in terms of the printer, and the scope and type of printing
23 * that is desired. For example, the number of pages and copies
24 * can be specified, as well as whether or not the print job
25 * should go to a file.
27 * Application code does <em>not</em> need to explicitly release the
28 * resources managed by each instance when those instances are no longer
29 * required, and thus no <code>dispose()</code> method is provided.
33 * @see Printer#getPrinterList
34 * @see PrintDialog#open
35 * @see <a href="http://www.eclipse.org/swt/snippets/#printing">Printing snippets</a>
36 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
39 public final class PrinterData extends DeviceData {
43 * On Windows systems, this is the name of the driver (often "winspool").
44 * On Mac OSX, this is the destination type ("Printer", "Fax", "File", or "Preview").
45 * On X/Window systems, this is the name of a display connection to the
46 * Xprt server (the default is ":1").
47 * On GTK+, this is the backend type name (eg. GtkPrintBackendCups).
49 // TODO: note that this api is not finalized for GTK+
53 * the name of the printer
54 * On Windows systems, this is the name of the 'device'.
55 * On Mac OSX, X/Window systems, and GTK+, this is the printer's 'name'.
60 * the scope of the print job, expressed as one of the following values:
62 * <dt><code>ALL_PAGES</code></dt>
63 * <dd>Print all pages in the current document</dd>
64 * <dt><code>PAGE_RANGE</code></dt>
65 * <dd>Print the range of pages specified by startPage and endPage</dd>
66 * <dt><code>SELECTION</code></dt>
67 * <dd>Print the current selection</dd>
70 public int scope = ALL_PAGES;
73 * the start page of a page range, used when scope is PAGE_RANGE.
74 * This value can be from 1 to the maximum number of pages for the platform.
76 public int startPage = 1;
79 * the end page of a page range, used when scope is PAGE_RANGE.
80 * This value can be from 1 to the maximum number of pages for the platform.
82 public int endPage = 1;
85 * whether or not the print job should go to a file
87 public boolean printToFile = false;
90 * the name of the file to print to if printToFile is true.
91 * Note that this field is ignored if printToFile is false.
93 public String fileName;
96 * the number of copies to print.
97 * Note that this field may be controlled by the printer driver
98 * In other words, the printer itself may be capable of printing
99 * multiple copies, and if so, the value of this field will always be 1.
101 public int copyCount = 1;
104 * whether or not the printer should collate the printed paper
105 * Note that this field may be controlled by the printer driver.
106 * In other words, the printer itself may be capable of doing the
107 * collation, and if so, the value of this field will always be false.
109 public boolean collate = false;
112 * The orientation of the paper, which can be either PORTRAIT
117 public int orientation = PORTRAIT;
120 * Single-sided or double-sided printing, expressed as one of the
123 * <dt><code>SWT.DEFAULT</code></dt>
124 * <dd>the default duplex value for the printer</dd>
125 * <dt><code>DUPLEX_NONE</code></dt>
126 * <dd>single-sided printing</dd>
127 * <dt><code>DUPLEX_LONG_EDGE</code></dt>
128 * <dd>double-sided printing as if bound on the long edge</dd>
129 * <dt><code>DUPLEX_SHORT_EDGE</code></dt>
130 * <dd>double-sided printing as if bound on the short edge</dd>
133 * The default value is <code>SWT.DEFAULT</code>, meaning do not set a value;
134 * use the printer's default duplex setting.
135 * A printer's default value is typically single-sided,
136 * however it can default to double-sided in order to save paper.
141 public int duplex = SWT.DEFAULT;
144 * <code>scope</code> field value indicating that
145 * all pages should be printed
147 public static final int ALL_PAGES = 0;
150 * <code>scope</code> field value indicating that
151 * the range of pages specified by startPage and endPage
154 public static final int PAGE_RANGE = 1;
157 * <code>scope</code> field value indicating that
158 * the current selection should be printed
160 public static final int SELECTION = 2;
163 * <code>orientation</code> field value indicating
164 * portrait paper orientation
168 public static final int PORTRAIT = 1;
171 * <code>orientation</code> field value indicating
172 * landscape paper orientation
176 public static final int LANDSCAPE = 2;
179 * <code>duplex</code> field value indicating
180 * single-sided printing.
182 * This is also known as simplex printing.
187 public static final int DUPLEX_NONE = 0;
190 * <code>duplex</code> field value indicating
191 * double-sided printing for binding on the long edge.
193 * For portrait orientation, the long edge is vertical.
194 * For landscape orientation, the long edge is horizontal.
196 * This is also known as duplex printing.
201 public static final int DUPLEX_LONG_EDGE = 1;
204 * <code>duplex</code> field value indicating
205 * double-sided printing for binding on the short edge.
207 * For portrait orientation, the short edge is horizontal.
208 * For landscape orientation, the short edge is vertical.
210 * This is also known as duplex tumble printing.
215 public static final int DUPLEX_SHORT_EDGE = 2;
218 * private, platform-specific data
219 * On Windows, this contains a copy of the DEVMODE struct
220 * returned from the <code>PrintDialog</code>.
221 * On GTK, this contains a copy of the print_settings and page_setup
222 * returned from the <code>PrintDialog</code>.
223 * On OS X Cocoa, this contains a copy of the PrintSettings and PageFormat
224 * returned from the <code>PrintDialog</code>.
225 * This field is not currently used on the X/Window System.
230 * Constructs an instance of this class that can be
231 * used to print to the default printer.
233 * @see Printer#getDefaultPrinterData
235 public PrinterData() {
239 * Constructs an instance of this class with the given
240 * printer driver and printer name.
242 * @param driver the printer driver for the printer
243 * @param name the name of the printer
248 public PrinterData(String driver, String name) {
249 this.driver = driver;
254 * Returns a string containing a concise, human-readable
255 * description of the receiver.
257 * @return a string representation of the receiver
260 public String toString() {
261 return "PrinterData {" + "driver = " + driver + ", name = " + name + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$