/* public void printData() { getJMenuBar().repaint(); try { PrinterJob prnJob = PrinterJob.getPrinterJob(); prnJob.setPrintable(m_panel); if (!prnJob.printDialog()) return; setCursor( Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); prnJob.print(); setCursor( Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); JOptionPane.showMessageDialog(this, "Printing completed successfully", "JPEGEditor2", JOptionPane.INFORMATION_MESSAGE); } catch (PrinterException e) { e.printStackTrace(); System.err.println("Printing error: "+e.toString()); } } */ public void printData(Image im) { Printer p = new Printer(im); try { java.awt.print.PrinterJob prnJob = java.awt.print.PrinterJob.getPrinterJob(); prnJob.setPrintable(p); if (!prnJob.printDialog()) { return; } setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR)); prnJob.print(); setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.DEFAULT_CURSOR)); javax.swing.JOptionPane.showMessageDialog( this, "Printing completed successfully", "JPEGEditor2", javax.swing.JOptionPane.INFORMATION_MESSAGE); } catch (java.awt.print.PrinterException e) { e.printStackTrace(); System.err.println("Printing_error:_" + e.toString()); } }
public void Print() { // If they didn't provide a mech exit if (Mechs.size() == 0) { return; } job.setJobName(jobName.trim()); // Here is where we will show the print dialog, determine if it's a single mech or multiples if (useDialog) { if (Mechs.size() == 1) { if (!PrintDialog((PrintMech) Mechs.get(0))) return; } else { if (!BatchDialog()) return; } } // start building the print objects necessary GeneratePrints(); job.setPageable(pages); boolean DoPrint = job.printDialog(); if (DoPrint) { try { job.print(); } catch (PrinterException e) { System.err.println(e.getMessage()); System.out.println(e.getStackTrace()); } Mechs.clear(); } }
/** 打印 */ private void print() { try { table.print(); } catch (PrinterException e) { logger.warn("打印机未准备好. - " + e.getMessage() + TMFrame.class.getName()); } }
private void imprimirButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_imprimirButtonActionPerformed try { stocksMensualesProductosTerminadosTable.print(JTable.PrintMode.FIT_WIDTH); } catch (java.awt.print.PrinterException e) { JOptionPane.showMessageDialog( this, e.getMessage(), "Error al imprimir", JOptionPane.ERROR_MESSAGE); } } // GEN-LAST:event_imprimirButtonActionPerformed
private void cmd_printActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_cmd_printActionPerformed MessageFormat header = new MessageFormat("Report Print"); MessageFormat footer = new MessageFormat("page{0,number,integer}"); try { table1.print(JTable.PrintMode.NORMAL, header, footer); } catch (java.awt.print.PrinterException e1) { System.err.format("cannot print %s%n", e1.getMessage()); } } // GEN-LAST:event_cmd_printActionPerformed
private void defaultPrintPage(InvoicePagePrint pageprintdocumnet) { PrintService[] service = PrinterJob.lookupPrintServices(); // list // of // printers int count = service.length; PrintService printSvc = null; for (int i = 0; i < count; i++) { System.out.println("Service name: " + service[i].getName()); if (service[i].getName().indexOf("PDFcamp") != -1) { printSvc = service[i]; i = count; } } // TSP650 PageFormat format = new PageFormat(); Paper paper = new Paper(); double paperWidth = 3.25; double paperHeight = 11.69; double leftMargin = 0.19; double rightMargin = 0.25; double topMargin = 0; double bottomMargin = 0.01; paper.setSize(paperWidth * 72.0, paperHeight * 72.0); paper.setImageableArea( leftMargin * 72.0, topMargin * 72.0, (paperWidth - leftMargin - rightMargin) * 72.0, (paperHeight - topMargin - bottomMargin) * 72.0); format.setPaper(paper); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(OrientationRequested.PORTRAIT); PrinterJob printerJob = PrinterJob.getPrinterJob(); try { printerJob.setPrintService(printSvc); } catch (PrinterException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // Printable printable = new ReceiptPrintTest(); format = printerJob.validatePage(format); // printerJob.setPrintable(printable, format); printerJob.setPrintable(pageprintdocumnet, format); try { printerJob.print(aset); } catch (Exception e) { e.printStackTrace(); } }
private PrintableBase doPrintAutoImpl( Container cont, PrinterJob job, StreamPrintService ps, int pOrientation, Paper paper, int offscrnImageType, int dpi, int numSamples, int tileWidth, int tileHeight, boolean resizeWithinPrintTest) { try { PageFormat pageFormat = job.defaultPage(); if (null != paper) { /** * Paper paper = new Paper(); paper.setSize(500,500); // Large Address Dimension * paper.setImageableArea(20, 20, 450, 420); */ pageFormat.setPaper(paper); } pageFormat.setOrientation(pOrientation); // PageFormat.LANDSCAPE or PageFormat.PORTRAIT job.setPrintService(ps); final PrintableBase printable; if (0 < offscrnImageType) { printable = new OffscreenPrintable( job, cont, dpi, numSamples, tileWidth, tileHeight, offscrnImageType, getPrintFilename( offscrnImageType, dpi, numSamples, tileWidth, tileHeight, "png", resizeWithinPrintTest)); } else { printable = new OnscreenPrintable(job, cont, dpi, numSamples, tileWidth, tileHeight); } printable.job.setPrintable(printable, pageFormat); doPrintImpl(printable, resizeWithinPrintTest); return printable; } catch (PrinterException pe) { pe.printStackTrace(); return null; } }
public void PrintBattleforce() { if (battleforces.size() == 0) { return; } pages = new Book(); page.setPaper(paper); if (jobName.isEmpty()) { jobName = "BattleForce"; } if (battleforces.size() == 1) { BattleForce bf = ((BattleforcePrinter) battleforces.get(0)).getBattleforce(); if (!bf.ForceName.isEmpty()) { jobName = bf.ForceName.trim(); } } job.setJobName(jobName); if (useDialog) { for (int i = 0; i < battleforces.size(); i++) { BattleforcePrinter bf = (BattleforcePrinter) battleforces.get(i); dlgPrintBattleforce pForce = new dlgPrintBattleforce((javax.swing.JFrame) Parent, true, bf.getBattleforce()); pForce.setLocationRelativeTo((javax.swing.JFrame) Parent); pForce.setVisible(true); if (!pForce.Result) { return; } bf.setType(pForce.Sheet); } } for (int i = 0; i < battleforces.size(); i++) { pages.append((BattleforcePrinter) battleforces.get(i), page); } job.setPageable(pages); boolean DoPrint = job.printDialog(); if (DoPrint) { try { job.print(); } catch (PrinterException e) { System.err.println(e.getMessage()); System.out.println(e.getStackTrace()); } } }
public static void print(JTextPane textPane) { PrinterJob job = PrinterJob.getPrinterJob(); PrintableHandler printable = new PrintableHandler(textPane); job.setPrintable(printable); boolean print = job.printDialog(); if (print) { try { job.print(); } catch (PrinterException ex) { ex.printStackTrace(); } } }
/** Handles the "Print" user action. Shows a printer dialog and prepares the page for printing */ public void print() { PrinterJob pj = PrinterJob.getPrinterJob(); pj.setPrintable(this); pj.setJobName(Messages.getString("GCUPrintJob")); if (pj.printDialog()) { try { pj.print(); } catch (PrinterException e) { JOptionPane.showMessageDialog( this, Messages.format("PrinterException", e.getLocalizedMessage()), // $NON-NLS-1$ Messages.getString("Main.16"), JOptionPane.ERROR_MESSAGE); // $NON-NLS-1$ } } }
@Override public void stopRenderer() throws IOException { super.stopRenderer(); try { printerJob.print(); } catch (PrinterException e) { e.printStackTrace(); throw new IOException( Messages.getInstance() .getString( "PrintComponent.ERROR_0003_UNABLE_TO_PRINT", e.getClass().getName(), e.getMessage())); // $NON-NLS-1$ } }
private void btImprimirActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btImprimirActionPerformed // TODO add your handling code here: btNovo.setEnabled(false); btEditar.setEnabled(true); btImprimir.setEnabled(true); btExcluir.setEnabled(false); btSalvar.setEnabled(true); btSair.setEnabled(true); tbPart.setEnabled(false); try { tbPart.print(); } catch (PrinterException ex) { JOptionPane.showMessageDialog(this, "Não foi possível imprimir\n" + ex.getMessage()); } } // GEN-LAST:event_btImprimirActionPerformed
/* * Calls up printing prompt for gnomon. */ public void printGnomon() { PrinterJob pjob = PrinterJob.getPrinterJob(); PageFormat preformat = pjob.defaultPage(); PageFormat postformat = pjob.pageDialog(preformat); // If user does not hit cancel then print. if (preformat != postformat) { // Set print component pjob.setPrintable( new SundialPrint(frame), postformat); // this is what's needed to integrate it if (pjob.printDialog()) { try { pjob.print(); } catch (PrinterException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
@Override public void actionPerformed(ActionEvent arg0) { // Background this, as it takes a while. JabRefExecutorService.INSTANCE.execute( () -> { try { PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new JobName(entry.map(BibEntry::getCiteKey).orElse("NO ENTRY"), null)); previewPane.print(null, null, true, null, pras, false); } catch (PrinterException e) { // Inform the user... we don't know what to do. JOptionPane.showMessageDialog( PreviewPanel.this, Localization.lang("Could not print preview") + ".\n" + e.getMessage(), Localization.lang("Print entry preview"), JOptionPane.ERROR_MESSAGE); LOGGER.info("Could not print preview", e); } }); }
public void actionPerformed(ActionEvent ae) { if (ae.getSource() == b) { PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(this); boolean ok = job.printDialog(); if (ok) { try { job.print(); } catch (PrinterException pe) { System.out.println(pe); pe.printStackTrace(); } } } if (ae.getSource() == back) { new remindersub(); f.dispose(); } }
@Override public void actionPerformed(ActionEvent e) { switch (e.getActionCommand()) { case "CHANGE": pf = PrinterJob.getPrinterJob().pageDialog(pf); setMediaSizeInfo(); pages.setPageFormat(pf); break; case "PRINT": PrinterJob pjob = PrinterJob.getPrinterJob(); pjob.setPageable(new MyPageable(pages.getNumberOfPages(), pf, p)); if (pjob.printDialog() == false) return; try { pjob.print(); } catch (PrinterException e1) { JOptionPane.showMessageDialog( this, "Druckfehler: " + e1.getMessage(), "Fehler", JOptionPane.WARNING_MESSAGE); } break; case "CANCEL": setVisible(false); break; } }
public void printPage(String size) { double width = 0.0; double height = 0.0; double margin = 0.0; PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); try { PrinterJob pj = PrinterJob.getPrinterJob(); if (pj.printDialog()) { PageFormat pf = pj.defaultPage(); Paper paper = pf.getPaper(); if (size.equals("3r")) { width = 5d * 72d; height = 3.5d * 72d; margin = 0d * 72d; aset.add(MediaSizeName.JIS_B7); } else if (size.equals("4r")) { width = 6d * 72d; height = 4d * 72d; margin = 0d * 72d; aset.add(MediaSizeName.JAPANESE_POSTCARD); } else if (size.equals("5r")) { width = 7d * 72d; height = 5d * 72d; margin = 0d * 72d; aset.add(MediaSizeName.NA_5X7); } else if (size.equals("6r")) { width = 8d * 72d; height = 6d * 72d; margin = 0d * 72d; aset.add(MediaSizeName.JAPANESE_DOUBLE_POSTCARD); } else if (size.equals("8r")) { width = 10d * 72d; height = 8d * 72d; margin = 0d * 72d; aset.add(MediaSizeName.NA_8X10); } paper.setSize(width, height); paper.setImageableArea(margin, margin, width - (margin * 2), height - (margin * 2)); System.out.println("Before- " + dump(paper)); pf.setOrientation(PageFormat.LANDSCAPE); pf.setPaper(paper); System.out.println("After- " + dump(paper)); System.out.println("After- " + dump(pf)); dump(pf); PageFormat validatePage = pj.validatePage(pf); System.out.println("Valid- " + dump(validatePage)); Book pBook = new Book(); pBook.append(this, pf); pj.setPageable(pBook); aset.add(OrientationRequested.LANDSCAPE); try { pj.setPrintable(this); pj.print(aset); } catch (PrinterException ex) { ex.printStackTrace(); } } } catch (Exception exp) { exp.printStackTrace(); } }
@Override public boolean performFinish() { // create the document Rectangle suggestedPageSize = getITextPageSize(page1.getPageSize()); Rectangle pageSize = rotatePageIfNecessary(suggestedPageSize); // rotate if we need landscape Document document = new Document(pageSize); try { // Basic setup of the Document, and get instance of the iText Graphics2D // to pass along to uDig's standard "printing" code. String outputFile = page1.getDestinationDir() + System.getProperty("file.separator") + //$NON-NLS-1$ page1.getOutputFile(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile)); document.open(); Graphics2D graphics = null; Template template = getTemplate(); int i = 0; int numPages = 1; do { // sets the active page template.setActivePage(i); PdfContentByte cb = writer.getDirectContent(); Page page = makePage(pageSize, document, template); graphics = cb.createGraphics(pageSize.getWidth(), pageSize.getHeight()); // instantiate a PrinterEngine (pass in the Page instance) PrintingEngine engine = new PrintingEngine(page); // make page format PageFormat pageFormat = new PageFormat(); pageFormat.setOrientation(PageFormat.PORTRAIT); java.awt.print.Paper awtPaper = new java.awt.print.Paper(); awtPaper.setSize(pageSize.getWidth() * 3, pageSize.getHeight() * 3); awtPaper.setImageableArea(0, 0, pageSize.getWidth(), pageSize.getHeight()); pageFormat.setPaper(awtPaper); // run PrinterEngine's print function engine.print(graphics, pageFormat, 0); graphics.dispose(); document.newPage(); if (i == 0) { numPages = template.getNumPages(); } i++; } while (i < numPages); // cleanup document.close(); writer.close(); } catch (DocumentException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } catch (PrinterException e) { e.printStackTrace(); } return true; }