Java Utililty Methods Printer Usage

List of utility methods to do Printer Usage

Description

The list of methods to do Printer Usage are organized into topic(s).

Method

doubleconvertPageFormatUnit(int oldUnit, int newUnit, double value)
convert Page Format Unit
return new MediaSize(0, (float) value, oldUnit).getY(newUnit);
PrintRequestAttributeSetcreatePrintRequestAttributeSet(int width, int height)
create Print Request Attribute Set
final PrintRequestAttributeSet result = new HashPrintRequestAttributeSet();
result.add(MediaSizeName.ISO_A4);
result.add(OrientationRequested.PORTRAIT);
result.add(new MediaPrintableArea(0, 0, width, height, MediaPrintableArea.MM));
return result;
PrintServicefindPrintService(String printerName)
find Print Service
PrintService printService = null;
if (printerName == null || printerName.isEmpty()) {
    printService = PrintServiceLookup.lookupDefaultPrintService();
} else {
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    for (PrintService service : services) {
        String prtName = service.getName();
        if (prtName.contains(printerName)) {
...
PrintServiceget_print_service(String printerName, HashPrintRequestAttributeSet aset)
geprinservice
PrintService[] pservices = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE,
        aset);
if (pservices == null)
    return null;
for (int i = 0; i < pservices.length; i++) {
    if (pservices[i] != null && pservices[i].toString() != null
            && pservices[i].getName().trim().equals(printerName.trim()))
        return pservices[i];
...
String[]getArrayOfPrinterNames()
get Array Of Printer Names
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
String printers[] = new String[services.length];
for (int i = 0; i < services.length; i++) {
    printers[i] = services[i].getName();
return printers;
TgetAttribute(PrintService ps, Class category)
get Attribute
if (ps == null || !isGoodPrinterName(ps.getName()))
    return null;
return ps.getAttribute(category);
PrintService[]getAvailablePrinters()
get Available Printers
final PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(new Copies(1));
return PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.PNG, printRequestAttributeSet);
StringgetDefaultPrinterName()
get Default Printer Name
if (bWaitForPrinterServer)
    return defaultPrinterName;
bWaitForPrinterServer = true;
if (defaultPrinterName == null) {
    long t = System.currentTimeMillis() / 1000;
    if ((t - lastQueryTime) < 120) {
        bWaitForPrinterServer = false;
        return defaultPrinterName;
...
StringgetDefaultPrinterName()
get Default Printer Name
if (PrintServiceLookup.lookupDefaultPrintService() != null) {
    return PrintServiceLookup.lookupDefaultPrintService().getName();
return ""; 
PrintRequestAttributeSetgetDefaultPrintRequestAttributes()
Return Default Print Request Attributes
return s_prats;