Example usage for java.awt.print PrinterJob getPrinterJob

List of usage examples for java.awt.print PrinterJob getPrinterJob

Introduction

In this page you can find the example usage for java.awt.print PrinterJob getPrinterJob.

Prototype

public static PrinterJob getPrinterJob() 

Source Link

Document

Creates and returns a PrinterJob which is initially associated with the default printer.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {

    PrinterJob pjob = PrinterJob.getPrinterJob();

    PageFormat pf = pjob.defaultPage();
    pf.setOrientation(PageFormat.LANDSCAPE);

    pf = pjob.pageDialog(pf);/*from   w  w w .ja v a 2s  .c o m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    PrinterJob pjob = PrinterJob.getPrinterJob();
    PageFormat pf = pjob.defaultPage();
    pjob.setPrintable(null, pf);//from   ww w  . ja v a  2  s  .c o m

    if (pjob.printDialog()) {
        pjob.print();
    }

}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    PrinterJob pjob = PrinterJob.getPrinterJob();
    PageFormat pf = pjob.defaultPage();

    pf.setOrientation(PageFormat.PORTRAIT);
    pf.setOrientation(PageFormat.LANDSCAPE);

    // pjob.setPrintable(printable, pf);

    pjob.print();/*  ww w .  j ava2 s . c om*/

}

From source file:PrintBook.java

public static void main(String[] args) {
    PrinterJob pjob = PrinterJob.getPrinterJob();
    Book book = new Book();

    PageFormat landscape = pjob.defaultPage();
    landscape.setOrientation(PageFormat.LANDSCAPE);
    book.append(new Printable1(), landscape);

    PageFormat portrait = pjob.defaultPage();
    portrait.setOrientation(PageFormat.PORTRAIT);
    book.append(new Printable2(), portrait, 5);

    pjob.setPageable(book);/*  w  ww  . ja va2  s . c o m*/
    try {
        pjob.print();
    } catch (PrinterException e) {
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    try {//from   ww w .  j  ava2  s. c o  m
        PrinterJob pjob = PrinterJob.getPrinterJob();
        pjob.setJobName("Graphics Demo Printout");
        pjob.setCopies(1);
        pjob.setPrintable(new Printable() {
            public int print(Graphics pg, PageFormat pf, int pageNum) {
                if (pageNum > 0) // we only print one page
                    return Printable.NO_SUCH_PAGE; // ie., end of job

                pg.drawString("www.java2s.com", 10, 10);

                return Printable.PAGE_EXISTS;
            }
        });

        if (pjob.printDialog() == false) // choose printer
            return;
        pjob.print();
    } catch (PrinterException pe) {
        pe.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    PrinterJob pj = PrinterJob.getPrinterJob();
    Book book = new Book();
    PageFormat defaultFormat = new PageFormat();
    defaultFormat = pj.defaultPage(defaultFormat);
    PageFormat landscapeFormat = new PageFormat();
    landscapeFormat.setOrientation(PageFormat.LANDSCAPE);
    PagePrinter[] page = new PagePrinter[2];
    int pageWidth = (int) defaultFormat.getImageableWidth();
    int pageHeight = (int) defaultFormat.getImageableHeight();
    Font font = new Font("Helvetica", Font.BOLD, 18);
    page[0] = new PagePrinter();
    page[0].addPrintElement(new MyItem("AAA", font, 100, pageHeight / 2));
    page[0].addPrintElement(new MyItem("line", 0, pageHeight, pageWidth, pageHeight));

    page[1] = new PagePrinter();
    page[1].addPrintElement(new MyItem("rectangle", 100, 100, pageWidth - 200, pageHeight - 200));
    page[1].addPrintElement(new MyItem("oval", 120, 120, pageWidth - 240, pageHeight - 240));

    book.append(page[0], defaultFormat);
    book.append(page[1], landscapeFormat);

    pj.setPageable(book);/*from w ww .j  av a 2 s  . c  o m*/
    pj.print();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    PrinterJob pj = PrinterJob.getPrinterJob();

    PageFormat pf = pj.defaultPage();
    Paper paper = new Paper();
    double margin = 36; // half inch
    paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2, paper.getHeight() - margin * 2);
    pf.setPaper(paper);/*from w w w .j  a  v  a2  s  .  co  m*/

    pj.setPrintable(new MyPrintable(), pf);
    if (pj.printDialog()) {
        try {
            pj.print();
        } catch (PrinterException e) {
            System.out.println(e);
        }
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    PrinterJob job = PrinterJob.getPrinterJob();

    job.setPrintable(new PrintDemo1());

    job.setCopies(2);//ww w  .ja  va2  s  .c o m
    job.setJobName("Printable");

    if (job.printDialog()) {
        try {
            job.print();
        } catch (PrinterException e) {
            System.out.println(e);
        }
    }

    System.exit(0);
}

From source file:MainClass.java

public static void main(String[] args) {
    PrinterJob job = PrinterJob.getPrinterJob();

    PageFormat pf = job.defaultPage();
    pf.setOrientation(PageFormat.LANDSCAPE);

    Book bk = new Book();
    bk.append(new paintCover(), pf);
    bk.append(new paintContent(), job.defaultPage(), 1);

    job.setPageable(bk);//  w  ww. ja va  2s . c  om
    job.setJobName("My book");
    if (job.printDialog()) {
        try {
            job.print();
        } catch (PrinterException e) {
            System.out.println(e);
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new Main());
    if (job.printDialog()) {
        try {/*from www. j a  va2 s  .com*/
            job.print();
        } catch (PrinterException e) {
        }
    }
    System.exit(0);
}