Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c0c6fdca2f750df9a5fe1453147da5906a6993f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*******************************************************************************
 * Copyright (c) 2000, 2009 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.snippets;

/*
 * Printer example snippet: print in landscape mode
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 *
 * @since 3.5
 */
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.printing.*;

public class Snippet318 {

public static void main(String [] args) {
	final Display display = new Display();
	PrinterData printerData = new PrinterData();
	printerData.orientation = PrinterData.LANDSCAPE;
	Printer printer = new Printer(printerData);
	Point dpi = printer.getDPI();
	if (printer.startJob("SWT Printing Snippet")) {
		GC gc = new GC(printer);
		if (printer.startPage()) {
			int oneInch = dpi.x;
			gc.drawString("Hello World!", oneInch, 2 * oneInch);
			gc.drawString("Printed on " + printerData.name + " using SWT on " + SWT.getPlatform(), oneInch, oneInch * 5/2);
			printer.endPage();
		}
		gc.dispose();
		printer.endJob();
	}
	printer.dispose();
	display.dispose();
}

}

Back to the top