In Java PrintService class give the list of printers available in the operating system. Here i have mentioned the sample code with JAVA which capable to retrieve printer services from operating system.
import javax.print.PrintServiceLookup;
public class GetPrinters
{
public static void main(String args[])
{
PrintService [] ps = PrinterJob.lookupPrintServices();
String response = "Number of print services: " + ps.length + "\n";
response += "\nAvailable Printers";
String printer = "\n";
int count = 0;
for( ; count < ps.length; count++)
{
printer += "\n" + ps [count].getName();
}
response += printer;
try
{
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
String defaultPrinter = "\nDefault Printer : " + service.getName();
response += defaultPrinter;
}
catch(Exception e)
{
response += e.getMessage();
}
System.out.println(response);
}
}
import java.awt.print.PrinterJob;
import javax.print.PrintService;import javax.print.PrintServiceLookup;
public class GetPrinters
{
public static void main(String args[])
{
PrintService [] ps = PrinterJob.lookupPrintServices();
String response = "Number of print services: " + ps.length + "\n";
response += "\nAvailable Printers";
String printer = "\n";
int count = 0;
for( ; count < ps.length; count++)
{
printer += "\n" + ps [count].getName();
}
response += printer;
try
{
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
String defaultPrinter = "\nDefault Printer : " + service.getName();
response += defaultPrinter;
}
catch(Exception e)
{
response += e.getMessage();
}
System.out.println(response);
}
}
After executing this class it will return the printer services.
Print Services |
Comments
Post a Comment