List of usage examples for java.awt.print PrinterJob defaultPage
public PageFormat defaultPage()
From source file:org.fhaes.fhfilechecker.FrameViewHelp.java
public void btnPrint_actionPerformed(ActionEvent e) { // Get a PrinterJob PrinterJob job = PrinterJob.getPrinterJob(); // Ask user for page format (e.g., portrait/landscape) PageFormat pf = job.pageDialog(job.defaultPage()); // Specify the Printable is an instance of // PrintListingPainter; also provide given PageFormat job.setPrintable(new PrintListingPainter(out_file_name), pf); // Print 1 copy job.setCopies(1);// w ww . j ava2s . c o m // Put up the dialog box if (job.printDialog()) { // Print the job if the user didn't cancel printing try { job.print(); } catch (Exception ex) { /* handle exception */} } }
From source file:org.fhaes.fhfilechecker.FrameViewOutput.java
public void btnPrint_actionPerformed(ActionEvent e) { // Get a PrinterJob PrinterJob job = PrinterJob.getPrinterJob(); // Ask user for page format (e.g., portrait/landscape) PageFormat pf = job.pageDialog(job.defaultPage()); // Specify the Printable is an instance of // PrintListingPainter; also provide given PageFormat job.setPrintable(new PrintListingPainter(out_file_name), pf); // Print 1 copy job.setCopies(1);//from ww w . j a va 2 s . co m // Put up the dialog box if (job.printDialog()) { // Print the job if the user didn't cancel printing try { job.print(); } catch (Exception ex) { /* handle exception */} } }
From source file:com.alvermont.terraj.planet.ui.TerrainFrame.java
private void printItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_printItemActionPerformed {//GEN-HEADEREND:event_printItemActionPerformed final PrinterJob printJob = PrinterJob.getPrinterJob(); final PageFormat pf = printJob.pageDialog(printJob.defaultPage()); printJob.setPrintable(new ImagePrinter(image, pf), pf); if (printJob.printDialog()) { try {//from w w w .j a v a 2 s .com printJob.print(); } catch (Exception e) { log.error("Error printing", e); JOptionPane.showMessageDialog(this, "Error: " + e.getMessage() + "\nCheck log file for full details", "Error Printing", JOptionPane.ERROR_MESSAGE); } } }
From source file:BookTest.java
/** * Makes a book that contains a cover page and the pages for the banner. *///w ww.ja v a2 s . c om 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; }
From source file:JavaWorldPrintExample2.java
/** * Constructor: Example2/* www. j a v a 2 s . c om*/ * <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// w w w .ja v a 2 s.com * <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: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);//from w w w . j a va 2s. co 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:com.floreantpos.jasperreport.engine.print.JRPrinterAWT.java
/** * *///from w ww.ja v a 2s .c o m private boolean printPages(int firstPageIndex, int lastPageIndex, boolean withPrintDialog) throws JRException { boolean isOK = true; if (firstPageIndex < 0 || firstPageIndex > lastPageIndex || lastPageIndex >= jasperPrint.getPages().size()) { throw new JRException("Invalid page index range : " + firstPageIndex + " - " + lastPageIndex + " of " + jasperPrint.getPages().size()); } printerName = jasperPrint.getProperty("printerName"); pageOffset = firstPageIndex; PrinterJob printJob = PrinterJob.getPrinterJob(); // fix for bug ID 6255588 from Sun bug database initPrinterJobFields(printJob); PageFormat pageFormat = printJob.defaultPage(); Paper paper = pageFormat.getPaper(); printJob.setJobName(jasperPrint.getName()); switch (jasperPrint.getOrientationValue()) { case LANDSCAPE: { pageFormat.setOrientation(PageFormat.LANDSCAPE); paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); paper.setImageableArea(0, 0, jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); break; } case PORTRAIT: default: { pageFormat.setOrientation(PageFormat.PORTRAIT); paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); paper.setImageableArea(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); } } pageFormat.setPaper(paper); Book book = new Book(); book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1); printJob.setPageable(book); try { if (withPrintDialog) { if (printJob.printDialog()) { printJob.print(); } else { isOK = false; } } else { printJob.print(); } } catch (Exception ex) { throw new JRException("Error printing report.", ex); } return isOK; }
From source file:com.openbravo.pos.util.JRPrinterAWT411.java
/** * *///from w w w . j av a 2 s .co m private boolean printPages(int firstPageIndex, int lastPageIndex, PrintService service) throws JRException { boolean isOK = true; if (firstPageIndex < 0 || firstPageIndex > lastPageIndex || lastPageIndex >= jasperPrint.getPages().size()) { throw new JRException("Invalid page index range : " + firstPageIndex + " - " + lastPageIndex + " of " + jasperPrint.getPages().size()); } pageOffset = firstPageIndex; PrinterJob printJob = PrinterJob.getPrinterJob(); // fix for bug ID 6255588 from Sun bug database initPrinterJobFields(printJob); PageFormat pageFormat = printJob.defaultPage(); Paper paper = pageFormat.getPaper(); printJob.setJobName("JasperReports - " + jasperPrint.getName()); switch (jasperPrint.getOrientationValue()) { case LANDSCAPE: { pageFormat.setOrientation(PageFormat.LANDSCAPE); paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); paper.setImageableArea(0, 0, jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); break; } case PORTRAIT: default: { pageFormat.setOrientation(PageFormat.PORTRAIT); paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); paper.setImageableArea(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); } } pageFormat.setPaper(paper); Book book = new Book(); book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1); printJob.setPageable(book); try { if (service == null) { if (printJob.printDialog()) { printJob.print(); } else { isOK = false; } } else { printJob.setPrintService(service); printJob.print(); } } catch (Exception ex) { throw new JRException("Error printing report.", ex); } return isOK; }
From source file:com.openbravo.pos.util.JRPrinterAWT.java
/** * *//*w ww . j a v a 2s . c o m*/ public boolean printPages(int firstPageIndex, int lastPageIndex, PrintService service) throws JRException { boolean isOK = true; if (firstPageIndex < 0 || firstPageIndex > lastPageIndex || lastPageIndex >= jasperPrint.getPages().size()) { throw new JRException("Invalid page index range : " + firstPageIndex + " - " + lastPageIndex + " of " + jasperPrint.getPages().size()); } pageOffset = firstPageIndex; PrinterJob printJob = PrinterJob.getPrinterJob(); // fix for bug ID 6255588 from Sun bug database initPrinterJobFields(printJob); PageFormat pageFormat = printJob.defaultPage(); Paper paper = pageFormat.getPaper(); printJob.setJobName("JasperReports - " + jasperPrint.getName()); switch (jasperPrint.getOrientationValue()) { case LANDSCAPE: { pageFormat.setOrientation(PageFormat.LANDSCAPE); paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); paper.setImageableArea(0, 0, jasperPrint.getPageHeight(), jasperPrint.getPageWidth()); break; } case PORTRAIT: default: { pageFormat.setOrientation(PageFormat.PORTRAIT); paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); paper.setImageableArea(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight()); } } pageFormat.setPaper(paper); Book book = new Book(); book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1); printJob.setPageable(book); try { if (service == null) { if (printJob.printDialog()) { printJob.print(); } else { isOK = false; } } else { printJob.setPrintService(service); printJob.print(); } } catch (Exception ex) { throw new JRException("Error printing report.", ex); } return isOK; }