List of usage examples for java.awt.print PrinterJob print
public abstract void print() throws PrinterException;
From source file:org.gumtree.vis.core.internal.SWTChartComposite.java
/** * Creates a print job for the chart.//from w ww .j av a 2 s . c om */ @Override public void createChartPrintJob() { final PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); pf.setOrientation(PageFormat.LANDSCAPE); // PageFormat pf2 = job.pageDialog(pf); PageFormat pf2 = job.defaultPage(); pf2.setOrientation(PageFormat.LANDSCAPE); if (pf2 != pf) { Printable print = new MyPrintable(); job.setPrintable(print, pf2); if (job.printDialog()) { getDisplay().asyncExec(new Runnable() { public void run() { try { job.print(); } catch (PrinterException e) { MessageBox messageBox = new MessageBox(getShell(), SWT.OK | SWT.ICON_ERROR); messageBox.setMessage(e.getMessage()); messageBox.open(); } } }); } } // PrintDialog dialog = new PrintDialog(getShell()); // // Prompts the printer dialog to let the user select a printer. // PrinterData printerData = dialog.open(); // // if (printerData == null) // the user cancels the dialog // return; // // Loads the printer. // final Printer printer = new Printer(printerData); // getDisplay().asyncExec(new Runnable(){ // // public void run() { // print(printer); // printer.dispose(); // }}); }
From source file:JavaWorldPrintExample3.java
/** * Constructor: Example3// www . ja v a2s .c om * <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);/* w w w . j a va 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:org.gumtree.vis.awt.CompositePanel.java
@Override public void createChartPrintJob() { setCursor(StaticValues.WAIT_CURSOR); PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); PageFormat pf2 = job.pageDialog(pf); if (pf2 != pf) { job.setPrintable(this, pf2); try {// w ww. j av a 2 s . c o m job.print(); } catch (PrinterException e) { JOptionPane.showMessageDialog(this, e); } finally { setCursor(StaticValues.defaultCursor); } } setCursor(StaticValues.defaultCursor); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
public void print(PrinterJob job) throws PrinterException { // do something before is_printing = true;//from ww w. j a v a2s. com job.print(); // do something after is_printing = false; }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Creates a print job for the chart.//from w ww . ja va2 s . c om */ public void createChartPrintJob() { 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(); } catch (PrinterException e) { JOptionPane.showMessageDialog(this, e); } } } }
From source file:com.floreantpos.jasperreport.engine.print.JRPrinterAWT.java
/** * *///from w w w . jav a 2 s.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.sshtools.sshterm.SshTermSessionPanel.java
/** * *//*from www. j ava 2 s . c o m*/ public void printScreen() { try { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(terminal, pageFormat); if (job.printDialog()) { setCursor(Cursor.getPredefinedCursor(3)); job.print(); setCursor(Cursor.getPredefinedCursor(0)); } } catch (PrinterException pe) { JOptionPane.showMessageDialog(this, pe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:com.openbravo.pos.util.JRPrinterAWT411.java
/** * *///from www . ja va 2 s . com 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
/** * *//*from w w w.j av a 2 s .co 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; }