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);
public void setPrintJob(DocPrintJob job) { // Add a listener to the print job job.addPrintJobListener( new PrintJobAdapter() { public void printJobCanceled(PrintJobEvent printJobEvent) { allDone(); } public void printJobCompleted(PrintJobEvent printJobEvent) { allDone(); } public void printJobFailed(PrintJobEvent printJobEvent) { allDone(); } public void printJobNoMoreEvents(PrintJobEvent printJobEvent) { allDone(); } void allDone() { synchronized (PrintJobWatcher.this) { done = true; PrintJobWatcher.this.notify(); } } }); }
InputStream is = new BufferedInputStream(new FileInputStream("D://giulio.provasi//Desktop//"+i+".txt")); PrintService service = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob job = service.createPrintJob(); Doc doc = new SimpleDoc(is, DocFlavor.INPUT_STREAM.AUTOSENSE, null); job.addPrintJobListener(pjDone); job.print(doc, null);
import java.io.FileInputStream; import javax.print.Doc; import javax.print.DocFlavor; import javax.print.DocPrintJob; import javax.print.PrintService; import javax.print.PrintServiceLookup; import javax.print.SimpleDoc; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.standard.Copies; public class Main { static public void main(String args[]) throws Exception { PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras); if (pss.length == 0) throw new RuntimeException("No printer services available."); PrintService ps = pss[0]; System.out.println("Printing to " + ps); DocPrintJob job = ps.createPrintJob(); FileInputStream fin = new FileInputStream("YOurImageFileName.PNG"); Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null); job.print(doc, pras); fin.close(); } }
URI printerURI = new URI("ipp://SERVER:631/printers/PRINTER_NAME"); IppPrintService svc = new IppPrintService(printerURI); InputStream stream = new BufferedInputStream(new FileInputStream("image.epl")); DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; Doc myDoc = new SimpleDoc(stream, flavor, null); DocPrintJob job = svc.createPrintJob(); job.print(myDoc, null);
InputStream in = new FileInputStream(file); DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF; // find the printing service AttributeSet attributeSet = new HashAttributeSet(); attributeSet.add(new PrinterName("FX", null)); attributeSet.add(new Copies(1)); PrintService[] services = PrintServiceLookup.lookupPrintServices( DocFlavor.INPUT_STREAM.PDF, attributeSet); //create document Doc doc = new SimpleDoc(in, flavor, null); // create the print job PrintService service = services[0]; DocPrintJob job = service.createPrintJob(); // monitor print job events PrintJobWatcher watcher = new PrintJobWatcher(job); System.out.println("Printing..."); job.print(doc, null); // wait for the job to be done watcher.waitForDone(); System.out.println("Job Completed!!");
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); }
PrintServiceLookup.lookupDefaultPrintService().getName(); System.out.println("Default printer: " + defaultPrinter); PrintService service = PrintServiceLookup.lookupDefaultPrintService(); PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); Doc doc = new SimpleDoc(is, flavor, null); DocPrintJob job = service.createPrintJob(); job.print(doc, pras); pjw.waitForDone(); is.close(); job.addPrintJobListener(new PrintJobAdapter() { public void printJobCanceled(PrintJobEvent pje) { allDone();
Doc myDoc = new SimpleDoc(bais, psInFormat, docAttributeSet); if (printServices.length > 0) { printer = printServices[0]; Debug.logInfo("Using printer: " + printer.getName(), module); if (!printer.isDocFlavorSupported(psInFormat)) { return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentPrinterNotSupportDocFlavorFormat", UtilMisc.toMap("psInFormat", psInFormat, "printerName", printer.getName()), locale)); PrintRequestAttributeSet praset = new HashPrintRequestAttributeSet(); List<Object> printRequestAttributes = UtilGenerics.checkList(serviceContext.remove("printRequestAttributes")); if (UtilValidate.isNotEmpty(printRequestAttributes)) { for (Object pra : printRequestAttributes) { Debug.logInfo("Adding PrintRequestAttribute: " + pra, module); praset.add((PrintRequestAttribute) pra); DocPrintJob job = printer.createPrintJob(); job.print(myDoc, praset); } catch (PrintException | IOException | TemplateException | GeneralException | SAXException | ParserConfigurationException e) { Debug.logError(e, "Error rendering [" + contentType + "]: " + e.toString(), module);
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 );
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(MediaSizeName.NA_LETTER); pj.print(doc, aset);
public CancelablePrintJob cancelablePrint() throws PrintException { // make sure we have a service, if not we assign the default printer if (printService == null && services != null && services.length > 0 && services[0] != null) { printService = services[0]; } if (printService != null) { // calculate total pages being printed calculateTotalPagesToPrint(); DocPrintJob printerJob = printService.createPrintJob(); printerJob.print( new SimpleDoc(this, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null), printRequestAttributeSet); return (CancelablePrintJob) printerJob; } else { return null; } }
DocPrintJob printJob = service.createPrintJob(); Doc doc; DocAttributeSet docAttrSet = new HashDocAttributeSet(); PrintRequestAttributeSet printReqAttr = new HashPrintRequestAttributeSet(); doc = new SimpleDoc(is, DocFlavor.INPUT_STREAM.AUTOSENSE, docAttrSet); PrintJobWatcher pjDone = new PrintJobWatcher(printJob); printJob.print(doc, printReqAttr); pjDone.waitForDone(); job.addPrintJobListener(new PrintJobAdapter() { public void printJobCanceled(PrintJobEvent pje) { allDone();
DocPrintJob printJob = printService.createPrintJob(); HashPrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); attributes.add(new PageRanges(1)); printJob.print(pdfDoc, attributes);
PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class); sPrinterName = ((PrinterName) attr).getValue(); if (sPrinterName.toLowerCase().indexOf(printerName) >= 0) { throw new ZebraPrintNotFoundException("Zebra printer not found : " + printerName); DocPrintJob job = psZebra.createPrintJob(); Doc doc = new SimpleDoc(by, flavor, null); job.print(doc, null);
DocPrintJob job = services[0].createPrintJob(); job.print(doc, attributes);
PrintService ps = PrinterJob.getPrinterJob().getPrintService(); DocFlavor[] myFlavors = ps.getSupportedDocFlavors(); ps.addPrintServiceAttributeListener(PrintTest.this); DocPrintJob docJob = ps.createPrintJob(); docJob.addPrintJobAttributeListener(PrintTest.this, null); docJob.addPrintJobListener(PrintTest.this); try { docJob.print(PrintTest.this,null); PrinterStateReasons psr = pje.getPrintJob().getPrintService().getAttribute(PrinterStateReasons.class); if (psr != null) { Set<PrinterStateReason> errors = psr.printerStateReasonSet(Severity.REPORT); PrinterStateReasons psr = pje.getPrintJob().getPrintService().getAttribute(PrinterStateReasons.class); if (psr != null) { Set<PrinterStateReason> errors = psr.printerStateReasonSet(Severity.REPORT);
DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT; PrintRequestAttributeSet aset = new HashPrintRequestHashAttributeSet(); aset.add(MediaSizeName.ISO_A4); PrintService[] pservices = PrintServiceLookup.lookupPrintServices(flavor, aset); if (pservices.length > 0) { DocPrintJob pj = pservices[0].createPrintJob(); // InputStreamDoc is an implementation of the Doc interface // Doc doc = new InputStreamDoc("test.ps", flavor); try { pj.print(doc, aset); } catch (PrintException e) { } }
DocPrintJob printJob = service.createPrintJob(); printJob.addPrintJobListener(monitor); Doc doc = new SimpleDoc(is, flavor, null); printJob.print(doc, null); monitor.waitForJobCompletion();
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()); }