List of usage examples for javax.print SimpleDoc SimpleDoc
public SimpleDoc(Object printData, DocFlavor flavor, DocAttributeSet attributes)
From source file:Main.java
public static void main(String args[]) throws Exception { String filename = args[0];// ww w .j a va 2 s . c o m DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob job = printService.createPrintJob(); PrintJobListener listener = new PrintJobAdapter() { public void printDataTransferCompleted(PrintJobEvent e) { System.out.println("Good-bye"); System.exit(0); } }; job.addPrintJobListener(listener); PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); FileInputStream fis = new FileInputStream(filename); DocAttributeSet das = new HashDocAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); Thread.sleep(10000); }
From source file:OneFourDialog.java
public static void main(String args[]) throws Exception { String filename = args[0];/* w ww . jav a 2 s . c o m*/ PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras); PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, DocFlavor.INPUT_STREAM.GIF, pras); if (service != null) { DocPrintJob job = service.createPrintJob(); PrintJobListener listener = new PrintJobAdapter() { public void printDataTransferCompleted(PrintJobEvent e) { System.exit(0); } }; job.addPrintJobListener(listener); FileInputStream fis = new FileInputStream(filename); DocAttributeSet das = new HashDocAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); Thread.sleep(10000); } }
From source file:PrintServiceTest.java
public static void main(String[] args) { DocFlavor flavor = DocFlavor.URL.GIF; PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null); if (args.length == 0) { if (services.length == 0) System.out.println("No printer for flavor " + flavor); else {//from w w w .j a va2 s .com System.out.println("Specify a file of flavor " + flavor + "\nand optionally the number of the desired printer."); for (int i = 0; i < services.length; i++) System.out.println((i + 1) + ": " + services[i].getName()); } System.exit(0); } String fileName = args[0]; int p = 1; if (args.length > 1) p = Integer.parseInt(args[1]); try { if (fileName == null) return; FileInputStream in = new FileInputStream(fileName); Doc doc = new SimpleDoc(in, flavor, null); DocPrintJob job = services[p - 1].createPrintJob(); job.print(doc, null); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (PrintException e) { e.printStackTrace(); } }
From source file:Main.java
public static void imprimirFactura(String factura) throws PrintException { PrintService service = PrintServiceLookup.lookupDefaultPrintService(); if (service == null) { throw new PrintException("No se encontro impresora conectada"); }/*ww w.ja v a2 s .c om*/ //Le decimos el tipo de datos que vamos a enviar a la impresora //Tipo: bytes Subtipo: autodetectado DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; DocPrintJob pj = service.createPrintJob(); byte[] bytes; bytes = factura.getBytes(); Doc doc = new SimpleDoc(bytes, flavor, null); pj.print(doc, null); }
From source file:ru.trett.cis.services.PrinterServiceImpl.java
@Override public String print(String file) throws ApplicationException, FileNotFoundException, PrintException { DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(MediaSizeName.ISO_A4); PrintService printServices = PrintServiceLookup.lookupDefaultPrintService(); if (printServices == null) throw new ApplicationException("Default printer not found"); LOGGER.info("Default printer is " + printServices.getName()); DocPrintJob printJob = printServices.createPrintJob(); FileInputStream fis = new FileInputStream(file); Doc doc = new SimpleDoc(fis, flavor, null); printJob.print(doc, aset);/*ww w . j a va2 s.co m*/ return printServices.getName(); }
From source file:JuliaSet3.java
public void printToService(PrintService service, PrintRequestAttributeSet printAttributes) { // Wrap ourselves in the PrintableComponent class defined by JuliaSet2. String title = "Julia set for c={" + cx + "," + cy + "}"; Printable printable = new PrintableComponent(this, title); // Now create a Doc that encapsulate the Printable object and its type DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; Doc doc = new SimpleDoc(printable, flavor, null); // Java 1.1 uses PrintJob. // Java 1.2 uses PrinterJob. // Java 1.4 uses DocPrintJob. Create one from the service DocPrintJob job = service.createPrintJob(); // Set up a dialog box to monitor printing status final JOptionPane pane = new JOptionPane("Printing...", JOptionPane.PLAIN_MESSAGE); JDialog dialog = pane.createDialog(this, "Print Status"); // This listener object updates the dialog as the status changes job.addPrintJobListener(new PrintJobAdapter() { public void printJobCompleted(PrintJobEvent e) { pane.setMessage("Printing complete."); }//w w w . j av a 2 s . c om public void printDataTransferCompleted(PrintJobEvent e) { pane.setMessage("Document transfered to printer."); } public void printJobRequiresAttention(PrintJobEvent e) { pane.setMessage("Check printer: out of paper?"); } public void printJobFailed(PrintJobEvent e) { pane.setMessage("Print job failed"); } }); // Show the dialog, non-modal. dialog.setModal(false); dialog.show(); // Now print the Doc to the DocPrintJob try { job.print(doc, printAttributes); } catch (PrintException e) { // Display any errors to the dialog box pane.setMessage(e.toString()); } }
From source file:org.obiba.onyx.print.PdfPrintingService.java
protected void print(Object source, DocFlavor flavor) throws PrintException { log.info("Starting print job"); DocPrintJob printJob = printService.createPrintJob(); printJob.print(new SimpleDoc(source, flavor, null), null); log.info("Print job finished"); }
From source file:Print.java
public static void printToService(PrintService service, String filename, PrintRequestAttributeSet attributes) throws IOException { // Figure out what type of file we're printing DocFlavor flavor = getFlavorFromFilename(filename); // Open the file InputStream in = new FileInputStream(filename); // Create a Doc object to print from the file and flavor. Doc doc = new SimpleDoc(in, flavor, null); // Create a print job from the service DocPrintJob job = service.createPrintJob(); // Monitor the print job with a listener job.addPrintJobListener(new PrintJobAdapter() { public void printJobCompleted(PrintJobEvent e) { System.out.println("Print job complete"); System.exit(0);//from w w w . jav a2 s. c o m } public void printDataTransferCompleted(PrintJobEvent e) { System.out.println("Document transfered to printer"); } public void printJobRequiresAttention(PrintJobEvent e) { System.out.println("Print job requires attention"); System.out.println("Check printer: out of paper?"); } public void printJobFailed(PrintJobEvent e) { System.out.println("Print job failed"); System.exit(1); } }); // Now print the document, catching errors try { job.print(doc, attributes); } catch (PrintException e) { System.out.println(e); System.exit(1); } }
From source file:net.sourceforge.fenixedu.util.report.ReportsUtils.java
private static void print(PrintService printService, byte[] pdf) throws PrintException { final DocPrintJob job = printService.createPrintJob(); final Doc doc = new SimpleDoc(pdf, DocFlavor.BYTE_ARRAY.PDF, null); final PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(new Copies(1)); aset.add(MediaSizeName.ISO_A4); aset.add(Sides.ONE_SIDED);//from w ww . j a v a 2 s.co m job.print(doc, aset); }
From source file:org.efaps.tests.Printer.java
/** * @param args//from ww w .j ava 2 s .c om */ public static void main(final String[] args) { final AttributeSet aset = new HashAttributeSet(); aset.add(new PrinterName("HP-LaserJet-100-colorMFP-M175nw", null)); final PrintService[] pservices = PrintServiceLookup.lookupPrintServices(null, aset); for (final PrintService serv : pservices) { System.out.println(serv); } try { final PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); // pras.add(new Copies(2)); final PrintService pservice = getPrintService4Name("HP-LaserJet-100-colorMFP-M175nw"); pservice.getSupportedDocFlavors(); final DocPrintJob job = pservice.createPrintJob(); final DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; final String filename = "/home/janmoxter/Downloads/Notas_de_Pedido_null.DOCX"; final FileInputStream fis = new FileInputStream(filename); final DocAttributeSet das = new HashDocAttributeSet(); final Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); } catch (final FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final PrintException e) { // TODO Auto-generated catch block e.printStackTrace(); } }