import javax.print.*; class Test { public static void main (String [] args) { PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("Number of print services: " + printServices.length); for (PrintService printer : printServices) System.out.println("Printer: " + printer.getName()); } }
for (int i = 0; !printerFound && i < printService.length; i++) if (printService[i].getName().contains(printerName))
@Override public String getName() { return delegate.getName(); }
PrintService defaultPrinter = PrintServiceLookup.lookupDefaultPrintService(); String printerName = defaultPrinter.getName();
PrintService service = PrintServiceLookup.lookupDefaultPrintService(); if (service != null) { String printServiceName = service.getName(); System.out.println("Print Service Name is " + printServiceName); } else { System.out.println("No default print service found"); }
System.out.println("Print services: " + printServices.length); for (PrintService printer : printServices) System.out.println("Printer: " + printer.getName());
PrinterJob pj = PrinterJob.getPrinterJob(); PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("Number of printers configured: " + printServices.length); for (PrintService printer : printServices) { System.out.println("Printer: " + printer.getName()); if (printer.getName().equals("***MYPRINTER***")) { try { pj.setPrintService(printer); } catch (PrinterException ex) { } } }
PrintService service = PrintServiceLookup.lookupDefaultPrintService(); int count = 0; for (DocFlavor docFlavor : service.getSupportedDocFlavors()) { if (docFlavor.toString().contains("pdf")) { count++; } } if (count == 0) { System.err.println("PDF not supported by printer: " + service.getName()); System.exit(1); } else { System.out.println("PDF is supported by printer: " + service.getName()); }
import javax.print.PrintService; import javax.print.PrintServiceLookup; public class CheckInstalledPrinter { public static void main (String [] args) { PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("Total Services :: " + printServices.length); for (PrintService printer : printServices) System.out.println("Printer Name :: " + printer.getName()); } }
String printerName = combobox.getSelectedItem().toString(); for (PrintService p: PrintServiceLookup.lookupPrintServices(null, null)) { if (p.getName().equals(printerName)) { doc.print(p.getAttributes()); break; } }
import javax.print.*; class Test { public static void main (String [] args) { PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("Number of print services: " + printServices.length); for (PrintService printer : printServices) System.out.println("Printer: " + printer.getName()); }
@Override protected void notifyLocalChange(int indx, ClarionObject value) { if (indx==Propprint.DEVICE && job!=null && !value.toString().trim().equals(job.getPrintService().getName())) { job=null; } super.notifyLocalChange(indx, value); }
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);
private boolean print(PrintService printService, InputStream inputStream, PrintRequestAttributeSet attributes) throws PrintException { try { PDDocument pdf = PDDocument.load(inputStream); PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintService(printService); job.setPageable(new PDFPageable(pdf)); job.print(attributes); pdf.close(); } catch (PrinterException e) { logger.error("Error when printing PDF file using the printer {}", printService.getName(), e); throw new PrintException("Printer exception", e); } catch (IOException e) { logger.error("Error when loading PDF from input stream", e); throw new PrintException("Input exception", e); } return true; }
public static void main(String args[]) throws Exception { PDDocument document = PDDocument.load(new File("C:/temp/example.pdf")); PrintService myPrintService = findPrintService("My Windows printer Name"); PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); job.setPrintService(myPrintService); job.print(); } private static PrintService findPrintService(String printerName) { PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); for (PrintService printService : printServices) { if (printService.getName().trim().equals(printerName)) { return printService; } } return null; }
public TableModel produce( final DataRow parameters, final DataFactoryContext dataFactoryContext ) throws ReportDataFactoryException { final PrintService[] services = PrintServiceLookup.lookupPrintServices( DocFlavor.SERVICE_FORMATTED.PAGEABLE, null ); final TypedTableModel tt = new TypedTableModel(); tt.addColumn( "Printer ID", String.class ); tt.addColumn( "Printer Name", String.class ); for ( int i = 0; i < services.length; i++ ) { final PrintService service = services[i]; final PrinterName displayName = service.getAttribute( PrinterName.class ); if ( displayName != null ) { tt.addRow( new Object[] { service.getName(), displayName.getValue() } ); } else { tt.addRow( new Object[] { service.getName(), service.getName() } ); } } return tt; } }
public void print() { PrinterJob printerJob = PrinterJob.getPrinterJob(); PrintService[] printService = PrinterJob.lookupPrintServices(); for (int i = 0; i < printService.length; i++) { System.out.println(printService[i].getName()); if (printService[i].getName().compareTo(printerName) == 0) { try { printerJob.setPrintService(printService[i]); setDoubleBuffered(false); setSize(getPreferredSize()); addNotify(); validate(); print(printerJob); } catch (PrinterException e) { e.printStackTrace(); } } } }
public ClarionPrinter() { CWin.getInstance(); services=PrinterJob.lookupPrintServices(); defaultService=PrintServiceLookup.lookupDefaultPrintService(); if (getJob()!=null) { setProperty(Propprint.DEVICE,getJob().getPrintService().getName()); } }
private String doPrinterDialog(final ClarionString title,final Integer mode) { Object lock=new Object(); ClarionEventQueue.getInstance().setRecordState(false,"Entering printDialog",lock); PrintService ps = printDialog(title!=null?title.toString():null, mode,null,50,50,services, getJob()==null? null : getJob().getPrintService(), null,getAttribute()); ClarionEventQueue.getInstance().setRecordState(true,"Exiting printDialog",lock); if (ps==null) return null; String name = ps.getName(); ClarionString cs = new ClarionString(name); setProperty(Propprint.DEVICE,cs); return name; }