hi friends ,
My task is to find the network printers Queue Status like how many printjob are over how many in queue and find the jobs names also.
i was build a
java program which find the Queuejobs number and printer name and colorprinter or not. But my program was work in local system, not in network system.And this program not show the printjob names.
i want a code for this task becoz iam fresher.i attech my program below see it.
by.......
Urs Friend,
Ramakrishna.
My program
package
test;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import java.io.*;
/*
import javax.print.event.*;
*/
public class PrintStatus {
// A utility method to look up printers that can support the specified
// attributes and return the one that matches the specified name.
public static PrintService getNamedPrinter(
String name,
PrintRequestAttributeSet attrs) {
PrintService[ ] services =
PrintServiceLookup.lookupPrintServices(null, attrs);
if (services.length > 0) {
if (name == null) return services[0];
else {
for(int i = 0; i < services.length; i++) {
if (services[i].getName( ).equals(name)) return services[i];
}
}
}
return null;
}
// List details about the named printer
public static void queryPrinter(String printerName,
PrintRequestAttributeSet attributes) {
// Find the named printer
PrintService service = getNamedPrinter(printerName, attributes);
if (service == null) {
System.out.println(printerName + ": no such printer capable of " +
"handling the specified attributes");
return;
}
// Print status and other information about the printer
System.out.println(printerName + " status:");
Attribute[ ] attrs = service.getAttributes( ).toArray( );
System.out.println("Attributes length----------" + attrs.length);
for(int i = 0; i < attrs.length; i++)
System.out.println("\t" + attrs[i].getName( ) + ": " + attrs[i]);
}
public static void main(String[ ] args) throws IOException {
if( args.length == 0 ) {
System.out.println("Usage: java PrintStatus <printer-name1> [<printer-name2> ...]");
return;
}
String printerName;
PrintRequestAttributeSet attributes = null;
for( int i = 0 ; i < args.length ; i++ )
{
printerName = args[i];
queryPrinter(printerName, attributes);
}
}
public static void main1(String[ ] args) throws IOException {
String printerName;
PrintRequestAttributeSet attributes = null;
printerName = "printer470";
/* // printer470, printer4550
attributes = new HashPrintRequestAttributeSet();
attributes.add(Chromaticity.COLOR);
*/
queryPrinter(printerName, attributes);
}
}