Example usage for java.awt.print PageFormat setOrientation

List of usage examples for java.awt.print PageFormat setOrientation

Introduction

In this page you can find the example usage for java.awt.print PageFormat setOrientation.

Prototype

public void setOrientation(int orientation) throws IllegalArgumentException 

Source Link

Document

Sets the page 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);// w w  w. j av a2 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();

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

    // pjob.setPrintable(printable, pf);

    pjob.print();//from ww  w.ja  v a 2s  .c  o m

}

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

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);/*  w  w w .  j ava  2s .  c  o m*/
    pj.print();
}

From source file:JavaWorldPrintExample2.java

/**
 * Constructor: Example2//from   w w  w. j  av  a2  s . co m
 * <p>
 *  
 */
public JavaWorldPrintExample2() {

    //--- Create a new PrinterJob object
    PrinterJob printJob = PrinterJob.getPrinterJob();

    //--- Create a new book to add pages to
    Book book = new Book();

    //--- Add the cover page using the default page format for this print
    // job
    book.append(new IntroPage(), printJob.defaultPage());

    //--- Add the document page using a landscape page format
    PageFormat documentPageFormat = new PageFormat();
    documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
    book.append(new Document(), documentPageFormat);

    //--- Tell the printJob to use the book as the pageable object
    printJob.setPageable(book);

    //--- Show the print dialog box. If the user click the
    //--- print button we then proceed to print else we cancel
    //--- the process.
    if (printJob.printDialog()) {
        try {
            printJob.print();
        } catch (Exception PrintException) {
            PrintException.printStackTrace();
        }
    }
}

From source file:JavaWorldPrintExample3.java

/**
 * Constructor: Example3/*from  ww  w. ja v a2  s.co m*/
 * <p>
 *  
 */
public JavaWorldPrintExample3() {

    //--- Create a new PrinterJob object
    PrinterJob printJob = PrinterJob.getPrinterJob();

    //--- Create a new book to add pages to
    Book book = new Book();

    //--- Add the cover page using the default page format for this print
    // job
    book.append(new IntroPage(), printJob.defaultPage());

    //--- Add the document page using a landscape page format
    PageFormat documentPageFormat = new PageFormat();
    documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
    book.append(new Document(), documentPageFormat);

    //--- Add a third page using the same painter
    book.append(new Document(), documentPageFormat);

    //--- Tell the printJob to use the book as the pageable object
    printJob.setPageable(book);

    //--- Show the print dialog box. If the user click the
    //--- print button we then proceed to print else we cancel
    //--- the process.
    if (printJob.printDialog()) {
        try {
            printJob.print();
        } catch (Exception PrintException) {
            PrintException.printStackTrace();
        }
    }

}

From source file:JavaWorldPrintExample4.java

/**
 * Constructor: Example4/*from ww  w  .  j a v a2s . c o  m*/
 * <p>
 *  
 */
public JavaWorldPrintExample4() {

    //--- Create a new PrinterJob object
    PrinterJob printJob = PrinterJob.getPrinterJob();

    //--- Create a new book to add pages to
    Book book = new Book();

    //--- Add the cover page using the default page format for this print
    // job
    book.append(new IntroPage(), printJob.defaultPage());

    //--- Add the document page using a landscape page format
    PageFormat documentPageFormat = new PageFormat();
    documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
    book.append(new Document(), documentPageFormat);

    //--- Tell the printJob to use the book as the pageable object
    printJob.setPageable(book);

    //--- Show the print dialog box. If the user click the
    //--- print button we then proceed to print else we cancel
    //--- the process.
    if (printJob.printDialog()) {
        try {
            printJob.print();
        } catch (Exception PrintException) {
            PrintException.printStackTrace();
        }
    }
}

From source file:JuliaSet2.java

public void print() {
    // Java 1.1 used java.awt.PrintJob.
    // In Java 1.2 we use java.awt.print.PrinterJob
    PrinterJob job = PrinterJob.getPrinterJob();

    // Alter the default page settings to request landscape mode
    PageFormat page = job.defaultPage();
    page.setOrientation(PageFormat.LANDSCAPE); // landscape by default

    // Tell the PrinterJob what Printable object we want to print.
    // PrintableComponent is defined as an inner class below
    String title = "Julia set for c={" + cx + "," + cy + "}";
    Printable printable = new PrintableComponent(this, title);
    job.setPrintable(printable, page);//  ww w.j  a v  a 2 s  . c  o m

    // Call the printDialog() method to give the user a chance to alter
    // the printing attributes or to cancel the printing request.
    if (job.printDialog()) {
        // If we get here, then the user did not cancel the print job
        // So start printing, displaying a dialog for errors.
        try {
            job.print();
        } catch (PrinterException e) {
            JOptionPane.showMessageDialog(this, e.toString(), "PrinterException", JOptionPane.ERROR_MESSAGE);
        }
    }
}

From source file:PrintCanvas3D.java

void print() {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    PageFormat pageFormat = printJob.defaultPage();
    pageFormat.setOrientation(PageFormat.LANDSCAPE);
    pageFormat = printJob.validatePage(pageFormat);
    printJob.setPrintable(this, pageFormat);
    if (printJob.printDialog()) {
        try {/*from   www.  j ava  2  s  .  co  m*/
            printJob.print();
        } catch (PrinterException ex) {
            ex.printStackTrace();
        }
    }
}