Printer: startJob(String jobName) : Printer « org.eclipse.swt.printing « Java by API






Printer: startJob(String jobName)


import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.printing.PrintDialog;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.printing.PrinterData;
import org.eclipse.swt.widgets.Shell;

public class MainClass {

  public static void main(String[] a) {
    Shell s = new Shell();
    PrintDialog printDialog = new PrintDialog(s, SWT.NONE);
    printDialog.setText("Print");
    PrinterData printerData = printDialog.open();
    if(!(printerData==null))
    {
        Printer p = new Printer(printerData);
        p.startJob("PrintJob");    
        p.startPage();
        Rectangle trim = p.computeTrim(0, 0, 0, 0);
        Point dpi = p.getDPI();
        int leftMargin = dpi.x + trim.x; 
        int topMargin = dpi.y / 2 + trim.y; 
        GC gc = new GC(p);
        Font font = gc.getFont(); 
        String printText= "www.java2s.com";
        Point extent = gc.stringExtent(printText);
        gc.drawString(printText, leftMargin, topMargin + 
                font.getFontData()[0].getHeight());
        p.endPage();
        gc.dispose();
        p.endJob();
        p.dispose();
    }

  }
}

           
       








Related examples in the same category

1.new Printer(PrinterData printerData)
2.Printer: computeTrim(int x, int y, int width, int height)
3.Printer: getDPI()
4.Printer: startPage()