This post shows that how can we get installed printers list using PrintServiceLookup class
Implementations of this class provide lookup services for print services
package client; import javax.print.PrintService; import javax.print.PrintServiceLookup; public class GetInstalledPrinters { public static void main(String[] args) { String defPrinter; PrintService[] printService = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("List of Installed Printers- "); for (int i = 0; i < printService.length; i++) { String printerName = printService[i].getName(); System.out.println(i + 1 + ". " + printerName); } defPrinter = PrintServiceLookup.lookupDefaultPrintService().getName(); System.out.println("\nDefault Printer Name - " + defPrinter); } }
Print File with Default Printer-
package client; import java.awt.Desktop; import java.io.File; import java.io.IOException; public class DesktopPrint { public DesktopPrint() { super(); } public static void main(String[] args) { Desktop desktop = Desktop.getDesktop(); try { desktop.print(new File("D:/Export.txt")); } catch (IOException e) { e.printStackTrace(); } } }
The above mentioned code is awesome. i just executed now. opted perfect for my requirements. thank you for sharing useful content.
ReplyDeletewe provide oracle fusion financials training in ameerpet
it is this code can get list printer from the client pc? i make java web n deploy it on linux server, when run this code it list printer on the server not the client pc. how can i get list printer from client pc?
ReplyDeleteFor that check - Access client machine printer using PrinterJob in Oracle ADF
Deleteok thanks..
DeletePicking a printer can be confounding, in any case, in the present aggressive, regularly evolving scene. 123 hp setup
ReplyDelete