List of usage examples for java.awt.print PrinterException printStackTrace
public void printStackTrace()
From source file:org.sanjose.util.JRPrinterAWT.java
/** * *//* w ww .ja v a 2 s . c om*/ private boolean printPages(int firstPageIndex, int lastPageIndex, boolean withPrintDialog, PrintService pService) 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); try { printJob.setPrintService(pService); } catch (PrinterException e) { e.printStackTrace(); throw new JRException(e.getMessage()); } 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 (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:pdfreader.PDFReader.java
private void initComponents() { menuBar = new javax.swing.JMenuBar(); fileMenu = new javax.swing.JMenu(); openMenuItem = new javax.swing.JMenuItem(); createBookMark = new javax.swing.JMenuItem(); saveAsHtml = new javax.swing.JMenuItem(); toHtml = new javax.swing.JMenuItem(); saveAsList = new javax.swing.JMenuItem(); saveAsTable = new javax.swing.JMenuItem(); ExtractImageMenuItem = new javax.swing.JMenuItem(); saveAsImageMenuItem = new javax.swing.JMenuItem(); exitMenuItem = new javax.swing.JMenuItem(); printMenuItem = new javax.swing.JMenuItem(); viewMenu = new javax.swing.JMenu(); nextPageItem = new javax.swing.JMenuItem(); previousPageItem = new javax.swing.JMenuItem(); SaveRegionText = new javax.swing.JMenuItem(); SaveRegionTextallOnce = new javax.swing.JMenuItem(); listextract = new javax.swing.JMenuItem(); setTitle("Apurba PDF Processor"); addWindowListener(new java.awt.event.WindowAdapter() { @Override/*from w ww . j a v a2s. c o m*/ public void windowClosing(java.awt.event.WindowEvent evt) { exitApplication(); } }); documentScroller = new javax.swing.JScrollPane(); documentScroller.setViewportView(documentPanel); getContentPane().add(documentScroller, java.awt.BorderLayout.CENTER); getContentPane().add(bottomStatusPanel, java.awt.BorderLayout.SOUTH); fileMenu.setText("File"); openMenuItem.setText("Open"); // openMenuItem.setAccelerator(KeyStroke.getKeyStroke('o')); openMenuItem.setToolTipText("Open PDF file"); openMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { openMenuItemActionPerformed(evt); } }); fileMenu.add(openMenuItem); //<editor-fold defaultstate="collapsed" desc="comment"> ExtractImageMenuItem.setText("Extract Image"); ExtractImageMenuItem.setToolTipText("Extract Image"); ExtractImageMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { ExtImages(evt); } }); // fileMenu.add(ExtractImageMenuItem); createBookMark.setText("Create BookMark"); createBookMark.setToolTipText("Create BookMark"); createBookMark.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { try { createbookmarks(evt); } catch (IOException | COSVisitorException ex) { Logger.getLogger(PDFReader.class.getName()).log(Level.SEVERE, null, ex); } } }); // // fileMenu.add(createBookMark); saveAsHtml.setText("Save as HTML"); saveAsHtml.setToolTipText("Save as HTML"); saveAsHtml.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { try { converttoHTML(evt); } catch (IOException ex) { Logger.getLogger(PDFReader.class.getName()).log(Level.SEVERE, null, ex); } } }); // fileMenu.add(saveAsHtml); //</editor-fold> toHtml.setText("Save as Regular HTML"); toHtml.setToolTipText("Save as Regular HTML"); // openMenuItem.setAccelerator(KeyStroke.getKeyStroke('h')); toHtml.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { convertToStandardHtml(); } }); fileMenu.add(toHtml); //<editor-fold defaultstate="collapsed" desc="comment"> SaveRegionText.setText("Region Text"); SaveRegionText.setToolTipText("Region Text"); SaveRegionText.setAccelerator(KeyStroke.getKeyStroke('r')); SaveRegionText.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { try { regionText(evt); } catch (IOException | CryptographyException ex) { Logger.getLogger(PDFReader.class.getName()).log(Level.SEVERE, null, ex); } } }); // fileMenu.add(SaveRegionText); //</editor-fold> SaveRegionTextallOnce.setText("Save as EDGAR HTML"); SaveRegionTextallOnce.setToolTipText("Save as EDGAR HTML"); // SaveRegionTextallOnce.setAccelerator(KeyStroke.getKeyStroke('e')); SaveRegionTextallOnce.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { try { regionTextAllOnce(evt); } catch (IOException | CryptographyException ex) { Logger.getLogger(PDFReader.class.getName()).log(Level.SEVERE, null, ex); } } }); fileMenu.add(SaveRegionTextallOnce); //<editor-fold defaultstate="collapsed" desc="comment"> listextract.setText("List Extract"); listextract.setToolTipText("List Extract"); listextract.setAccelerator(KeyStroke.getKeyStroke('l')); listextract.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { listExtract(evt); } }); //fileMenu.add(listextract); saveAsTable.setText("Save as Table"); saveAsTable.setToolTipText("Save as Table"); saveAsTable.setAccelerator(KeyStroke.getKeyStroke('t')); saveAsTable.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { try { converttoTable(evt); } catch (IOException | CryptographyException ex) { Logger.getLogger(PDFReader.class.getName()).log(Level.SEVERE, null, ex); } } }); // fileMenu.add(saveAsTable); saveAsList.setText("Save as List"); saveAsList.setToolTipText("Save as List"); saveAsList.setAccelerator(KeyStroke.getKeyStroke('l')); saveAsList.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { try { converttoList(evt); } catch (IOException | CryptographyException ex) { Logger.getLogger(PDFReader.class.getName()).log(Level.SEVERE, null, ex); } } }); // fileMenu.add(saveAsList); printMenuItem.setText("Print"); printMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { try { if (document != null) { document.print(); } } catch (PrinterException e) { e.printStackTrace(); } } }); // fileMenu.add( printMenuItem ); saveAsImageMenuItem.setText("Save as image"); saveAsImageMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { if (document != null) { saveImage(); } } }); fileMenu.add(saveAsImageMenuItem); //</editor-fold> exitMenuItem.setText("Exit"); exitMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { exitApplication(); } }); fileMenu.add(exitMenuItem); menuBar.add(fileMenu); viewMenu.setText("View"); nextPageItem.setText("Next page"); nextPageItem.setAccelerator(KeyStroke.getKeyStroke('+')); nextPageItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { nextPage(); } }); viewMenu.add(nextPageItem); previousPageItem.setText("Previous page"); previousPageItem.setAccelerator(KeyStroke.getKeyStroke('-')); previousPageItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { previousPage(); } }); viewMenu.add(previousPageItem); menuBar.add(viewMenu); setJMenuBar(menuBar); java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); this.setAlwaysOnTop(false); // this.setSize(screenSize.width, screenSize.height); // setBounds(100, 100, 400, 400); // setBounds(0, 0, screenSize.width, screenSize.height-40); // this.setBounds(0, 0, 1366, 728); setBounds((screenSize.width - 700) / 2, (screenSize.height - 600) / 2, 700, 600); // pack(); }
From source file:processing.app.Editor.java
/** * Handler for File → Print.//from w w w. j av a 2 s . com */ public void handlePrint() { statusNotice(_("Printing...")); //printerJob = null; PrinterJob printerJob = PrinterJob.getPrinterJob(); if (pageFormat != null) { //System.out.println("setting page format " + pageFormat); printerJob.setPrintable(textarea, pageFormat); } else { printerJob.setPrintable(textarea); } // set the name of the job to the code name printerJob.setJobName(sketch.getCurrentCode().getPrettyName()); if (printerJob.printDialog()) { try { printerJob.print(); statusNotice(_("Done printing.")); } catch (PrinterException pe) { statusError(_("Error while printing.")); pe.printStackTrace(); } } else { statusNotice(_("Printing canceled.")); } //printerJob = null; // clear this out? }