PrintService pservice = ... // acquire print service of your printer DocPrintJob job = pservice.createPrintJob(); String commands = ""; commands += "\u001B\u0045\u000A"; // plain commands += "Hello "; commands += "\u001B\u0045\u000D"; // bold commands += "ESCP!"; DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; Doc doc = new SimpleDoc(commands.getBytes(), flavor, null); job.print(doc, null);
@Override public DocPrintJob createPrintJob() { return delegate.createPrintJob(); }
char[] printdata = "hello world\n".toCharArray(); DocFlavor flavor = DocFlavor.CHAR_ARRAY.TEXT_PLAIN; PrintService pservice = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob pjob = pservice.createPrintJob(); Doc doc= new SimpleDoc(printdata, flavor, null); job.print(doc, null);
PrintService pservice = ... // acquire print service of your printer DocPrintJob job = pservice.createPrintJob(); String commands = "^XA\n\r^MNM\n\r^FO050,50\n\r^B8N,100,Y,N\n\r^FD1234567\n\r^FS\n\r^PQ3\n\r^XZ"; DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; Doc doc = new SimpleDoc(commands.getBytes(), flavor, null); job.print(doc, null);
public static void main(String[] args) throws IOException { FileInputStream in = new FileInputStream("test.pdf"); Doc doc = new SimpleDoc(in, DocFlavor.INPUT_STREAM.AUTOSENSE, null); PrintService service = PrintServiceLookup.lookupDefaultPrintService(); try { service.createPrintJob().print(doc, null); } catch (PrintException e) { e.printStackTrace(); } }
byte[] bytes = bos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream( bytes ); // First identify the default print service on the system PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); // prepare the flvaor you are intended to print DocFlavor docFlavor = DocFlavor.BYTE_ARRAY.PDF; // prepare the print job DocPrintJob printJob = printService.createPrintJob(); // prepare the document, with default attributes, ready to print Doc docToPrint = new SimpleDoc( bais, docFlavor, null ); // now send the doc to print job, with no attributes to print printJob.print( docToPrint, null );
PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob printJob = printService.createPrintJob(); PDDocument pdDocument = PDDocument.load(new File("doc.pdf")); PDFPageable pdfPageable = new PDFPageable(pdDocument); SimpleDoc doc = new SimpleDoc(pdfPageable, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); printJob.print(doc, null);
PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob printerJob = defaultPrintService.createPrintJob(); File pdfFile = new File("yourfile"); SimpleDoc simpleDoc = null; try { simpleDoc = new SimpleDoc(pdfFile.toURL(), DocFlavor.URL.AUTOSENSE, null); } catch (MalformedURLException ex) { ex.printStackTrace(); } try { printerJob.print(simpleDoc, null); } catch (PrintException ex) { ex.printStackTrace(); }
PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); if(service != null) { DocFlavor docFlawor = DocFlavor.INPUT_STREAM.PDF; PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); DocPrintJob job = printService.createPrintJob(); Doc pdf = new SimpleDoc(new URL(url).openStream(), docFlawor, null); job.print(pdf, printRequestAttributeSet); }
PrintService service = PrintServiceLookup.lookupDefaultPrintService(); FileInputStream in = new FileInputStream(new File("C:*PATH_TO_STRING_HERE")); PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; Doc doc = new SimpleDoc(in, flavor, null); DocPrintJob job = service.createPrintJob(); PrintJobWatcher pjw = new PrintJobWatcher(job); job.print(doc, pras);
static void print(Printable printable, PrintService service) throws PrintException, IOException { Path outputFile = Files.createTempFile( Paths.get(System.getProperty("user.home")), null, ".xps"); Doc doc = new SimpleDoc(printable, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null); PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); attributes.add(new Destination(outputFile.toUri())); DocPrintJob job = service.createPrintJob(); job.print(doc, attributes); }
PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob printJob = printService.createPrintJob(); PageFormat pageFormat = PrinterJob.getPrinterJob().defaultPage(); PDDocument pdDocument = PDDocument.load(new File("doc.pdf")); PDFPrintable pdfPrintable = new PDFPrintable(pdDocument); Book book = new Book(); book.append(pdfPrintable, pageFormat); SimpleDoc doc = new SimpleDoc(book, DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); printJob.print(doc, null);
public void print() throws PrintException, IOException { String defaultPrinter = PrintServiceLookup.lookupDefaultPrintService().getName(); System.out.println("Default printer: " + defaultPrinter); PrintService service = PrintServiceLookup.lookupDefaultPrintService(); InputStream is = new ByteArrayInputStream(printableAmounts.getBytes("UTF8")); PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; Doc doc = new SimpleDoc(is, flavor, null); DocPrintJob job = service.createPrintJob(); PrintJobWatcher pjw = new PrintJobWatcher(job); job.print(doc, pras); pjw.waitForDone(); is.close(); }
public static void main(String[] args) { try { FileInputStream fis = new FileInputStream("c:\\N0018902726.pdf"); DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; DocAttributeSet das = new HashDocAttributeSet(); Doc pdfDoc = new SimpleDoc(fis, flavor, null); PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob printJob = printService.createPrintJob(); printJob.print(pdfDoc, new HashPrintRequestAttributeSet()); fis.close(); } catch (Exception e) { System.out.println("EXCEPTIOn : " +e.getMessage()); } }
private void transmit(InputStream is) throws PrintException { InputStreamDoc doc = new InputStreamDoc(is); DocPrintJob dpj = service.createPrintJob(); dpj.print(doc, null); }
private void transmit(InputStream is) throws PrintException { InputStreamDoc doc = new InputStreamDoc(is); DocPrintJob dpj = service.createPrintJob(); dpj.print(doc, null); }
private boolean printData(PrintService printService , String printText) { try { SimpleDoc doc; doc = new SimpleDoc(printText.getBytes(), javax.print.DocFlavor.BYTE_ARRAY.AUTOSENSE, null); DocPrintJob job = printService.createPrintJob(); job.print(doc, new HashPrintRequestAttributeSet()); System.out.println("Job sent to printer succesfully"); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
PDDocument doc = PDDocument.load(new FileInputStream(System.getProperty("java.io.tmpdir") + "\\pdf.pdf")); //read pdf file. String printerNameDesired = "VENDOR THERMAL PRINTER"; javax.print.PrintService[] service = PrinterJob.lookupPrintServices(); DocPrintJob docPrintJob = null; int count = service.length; for (int i = 0; i < count; i++) { if (service[i].getName().equalsIgnoreCase(printerNameDesired)) { docPrintJob = service[i].createPrintJob(); i = count; } } PrinterJob pjob = PrinterJob.getPrinterJob(); pjob.setPrintService(docPrintJob.getPrintService()); pjob.setJobName("job"); doc.silentPrint(pjob);
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras); PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); PrintService service = ServiceUI.printDialog(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(), 200, 200, printService, defaultService, flavor, pras); if (service != null) { DocPrintJob job = service.createPrintJob(); FileInputStream fis = new FileInputStream(doc); DocAttributeSet das = new HashDocAttributeSet(); Doc document = new SimpleDoc(fis, flavor, das); job.print(document, pras); }
Doc document = new SimpleDoc(jTextArea1.getText(), DocFlavor.STRING, new HashDocAttributeSet()); PrinterJob pj = PrinterJob.getPrinterJob(); if (pj.printDialog()) { PrintService ps = pj.getPrintService(); DocPrintJob dpj = ps.createPrintJob(); dpj.print(document, new HashPrintRequestAttributeSet()); }