I know how to get the list of available printers, I want users to be able to select from a list and set that to the default for the session
Using Windows 7
I know that this is easily done I just want to create a simple java program a: To increase my knowledge b: Teachers here are very adverse to playing with printing properties
Thanks for your help in advance
You know how to get list of all printers then you want set a default printer.
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) {
}
}
}
This program works in Eclipse.
import java.awt.print.PageFormat;
import java.awt.print.PrinterJob;
public class PrinterSetup
{
public static void main(String[] args) throws Exception
{
PrinterJob pjob = PrinterJob.getPrinterJob();
PageFormat pf = pjob.defaultPage();
pjob.setPrintable(null, pf);
if (pjob.printDialog()) {
pjob.print();
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With