Refine search
public void actionPerformed(ActionEvent ae) { PRINTER_JOB.setPageable(textEditor); try { if (PRINTER_JOB.printDialog()) { PRINTER_JOB.print(); } } catch (Exception e) { e.printStackTrace(); } } } // end ConsoleTextEditor.PrintAction
public void printComponenet(){ PrinterJob pj = PrinterJob.getPrinterJob(); pj.setJobName(" Print Component "); pj.setPrintable (new Printable() { public int print(Graphics pg, PageFormat pf, int pageNum){ if (pageNum > 0){ return Printable.NO_SUCH_PAGE; } Graphics2D g2 = (Graphics2D) pg; g2.translate(pf.getImageableX(), pf.getImageableY()); componenet_name.paint(g2); return Printable.PAGE_EXISTS; } }); if (pj.printDialog() == false) return; try { pj.print(); } catch (PrinterException ex) { // handle exception } }
printerjob.setPrintable(new Server(), pageFormat); // Server was my class's name, you use yours. printerjob.print(); // Actual print command } catch (PrinterException exception) { System.err.println("Printing error: " + exception);
HTMLPrinter target = new HTMLPrinter(editorPane); PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(target); try{ printJob.printDialog(); printJob.print(); }catch(Exception e){ e.printStackTrace(); }
/** * Prints with a print preview dialog. */ private static void printWithDialog(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); if (job.printDialog()) { job.print(); } }
PDDocument doc = PDDocument.load(new File("test.pdf")); PDFPrintable printable = new PDFPrintable(doc, Scaling.SHRINK_TO_FIT); PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(printable); job.print();
public class PrintingExample { public static void main(String[] args) { try { Barcode b = BarcodeFactory.createCode128("Hello"); PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(b); if (job.printDialog()) { job.print(); } } catch (Exception e) { e.printStackTrace(); } } }
if (silentPrint || printJob.printDialog()) printJob.print();
HashPrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); attr.add(new MediaPrintableArea(0f, 0f, w/72f, h/72f, MediaPrintableArea.INCH)); PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintService(ps); job.setPrintable(this); job.setJobName(jobName); job.print(attr); j.setVisible(false); j.dispose();
protected void doPrint(boolean useBook) { RectangleThingy rectangleThingy = new RectangleThingy(); System.out.println("doPrint("+useBook+")"); try { PrinterJob printJob = PrinterJob.getPrinterJob(); if (useBook) { Book book = new Book(); book.append(rectangleThingy, getMinimumMarginPageFormat(printJob)); printJob.setPageable(book); } else { printJob.setPrintable(rectangleThingy); } if (printJob.printDialog()) printJob.print(); } catch(PrinterException pe) { System.out.println("Error printing: " + pe); } }
if (job.printDialog(attr)) job.print(attr);
PageFormat format = new PageFormat(); format.setOrientation(PageFormat.REVERSE_LANDSCAPE); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(OrientationRequested.REVERSE_LANDSCAPE); aset.add(MediaSizeName.JAPANESE_POSTCARD); PrinterJob printerJob = PrinterJob.getPrinterJob(); printerJob.setPrintable(new ImagePrintable(sap.getGraphicImage())); printerJob.defaultPage(format); printerJob.print(aset);
if (pj.printDialog()) { PageFormat pf = pj.defaultPage(); Paper paper = pf.getPaper(); pj.setPrintable(new MyPrintable(), pf); try { pj.print(); } catch (PrinterException ex) { ex.printStackTrace();
if (job.printDialog(pras)) job.print(pras);
PrinterJob job = PrinterJob.getPrinterJob(); PageFormat pf = job.defaultPage(); Paper paper = pf.getPaper(); double margin = 20.; paper.setImageableArea(margin, paper.getImageableY(), paper.getWidth() - 2* margin, paper.getImageableHeight()); pf.setPaper(paper); job.setPrintable(table.getPrintable(JTable.PrintMode.FIT_WIDTH, null, null), job.validatePage(pf)); job.print();
PrinterJob printerJob = PrinterJob.getPrinterJob(); printerJob.setPrintable(new CustomPrintable("DATA TO PRINT")); boolean printOK = printerJob.printDialog(); if (printOK){} try { printerJob.print(); } catch (PrinterException e){ // Error } }
PrinterJob pj = PrinterJob.getPrinterJob(); //... if (pj.printDialog()) { try {pj.print();} catch (PrinterException exc) { System.out.println(exc); } } //...
public void print() { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(this); if (printJob.printDialog()) try { System.out.println("code here"); printJob.print(); } catch(PrinterException pe) { System.out.println("Error printing: " + pe); } }
PrinterJob pj = PrinterJob.getPrinterJob(); ... if (pj.printDialog()) { try {pj.print();} catch (PrinterException exc) { System.out.println(exc); } } ...
private void printToPrinter() { String printData = CalculationTextArea.getText() + "\n" + SpecificTextArea.getText(); PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(new OutputPrinter(printData)); boolean doPrint = job.printDialog(); if (doPrint) { try { job.print(); } catch (PrinterException e) { // Print job did not complete. } } }