Example usage for java.awt.print PrinterJob defaultPage

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

Introduction

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

Prototype

public PageFormat defaultPage() 

Source Link

Document

Creates a new PageFormat instance and sets it to a default size and orientation.

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  ww  .j  a va  2  s .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);/*w w w  . j a v a2s  .  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();//from w w w .j a v a  2 s . c om

}

From source file:BasicPrint.java

public static void main(String[] args) {
    PrinterJob pjob = PrinterJob.getPrinterJob();
    PageFormat pf = pjob.defaultPage();
    pjob.setPrintable(new BasicPrint(), pf);
    try {/*from w w  w. j  a v  a 2 s .  c  om*/
        pjob.print();
    } catch (PrinterException e) {
    }
}

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 a 2s .  c  o  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();

    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  .j  a v  a 2 s .c  o m
    job.setJobName("My book");
    if (job.printDialog()) {
        try {
            job.print();
        } catch (PrinterException e) {
            System.out.println(e);
        }
    }
}

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);/*from w  w w .j  a va  2s  .  c  om*/
    try {
        pjob.print();
    } catch (PrinterException e) {
    }
}

From source file:io.github.mzmine.util.jfreechart.JFreeChartUtils.java

public static void printChart(ChartViewer chartNode) {

    // As of java 1.8.0_74, the JavaFX printing support seems to do poor
    // job. It creates pixelated, low-resolution print outs. For that
    // reason, we use the AWT PrinterJob class, until the JavaFX printing
    // support is improved.
    SwingUtilities.invokeLater(() -> {
        PrinterJob job = PrinterJob.getPrinterJob();
        PageFormat pf = job.defaultPage();
        PageFormat pf2 = job.pageDialog(pf);
        if (pf2 == pf)
            return;
        ChartPanel p = new ChartPanel(chartNode.getChart());
        job.setPrintable(p, pf2);/*ww  w .  ja va  2s.co  m*/
        if (!job.printDialog())
            return;
        try {
            job.print();
        } catch (PrinterException e) {
            e.printStackTrace();
            MZmineGUI.displayMessage("Error printing: " + e.getMessage());
        }
    });
}

From source file:playground.artemc.calibration.charts.CustomChartPanel.java

public void createPrintJob() {
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pf = job.defaultPage();
    PageFormat pf2 = job.pageDialog(pf);
    if (pf2 != pf) {
        job.setPrintable(this, pf2);
        if (job.printDialog()) {
            try {
                job.print();//ww  w. j a v a 2  s .  co m
            } catch (PrinterException e) {
                JOptionPane.showMessageDialog(this, e);
            }
        }
    }
}

From source file:PrintableComponent.java

/**
 * This method is not part of the Printable interface.  It is a method
 * that sets up the PrinterJob and initiates the printing.
 *///from  ww  w . j av  a  2s .  co m
public void print() throws PrinterException {
    // Get the PrinterJob object
    PrinterJob job = PrinterJob.getPrinterJob();
    // Get the default page format, then allow the user to modify it
    PageFormat format = job.pageDialog(job.defaultPage());
    // Tell the PrinterJob what to print
    job.setPrintable(this, format);
    // Ask the user to confirm, and then begin the printing process
    if (job.printDialog())
        job.print();
}