List of usage examples for java.awt.print Book append
public void append(Printable painter, PageFormat page)
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 av a 2 s. co 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);/* ww w. ja va 2 s . co m*/ try { pjob.print(); } catch (PrinterException 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);/*from ww w .j a va2 s .c om*/ pj.print(); }
From source file:JavaWorldPrintExample2.java
/** * Constructor: Example2/*from w ww. j a v a 2 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. j ava 2 s .c o 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 a2 s. co 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:BookTest.java
/** * Makes a book that contains a cover page and the pages for the banner. *//* www.j a v a 2s . c o m*/ public Book makeBook() { if (pageFormat == null) { PrinterJob job = PrinterJob.getPrinterJob(); pageFormat = job.defaultPage(); } Book book = new Book(); String message = text.getText(); Banner banner = new Banner(message); int pageCount = banner.getPageCount((Graphics2D) getGraphics(), pageFormat); book.append(new CoverPage(message + " (" + pageCount + " pages)"), pageFormat); book.append(banner, pageFormat, pageCount); return book; }