i want to write an app to listen to the jobs in the printer queue.
depending on the doc name (or some content in the doc) i want to reroute this job to the correct printer. all printers are identical, so formating will not be an problem.
my "printspoller" might be an additional installed printer, same type.
i apreciate any help on this hannes
im able to count the jobs in queue via "queued-job-count" but could not find to get the props of the docs.
import java.io.*;
import java.util.Properties;
import javax.print.attribute.Attribute;
import javax.print.attribute.AttributeSet;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import java.util.Calendar;
import java.io.ByteArrayOutputStream;
public class App {
public static void main(String[] args) throws Exception {
//GET ALL PRINTER NAMES
System.out.println("Printers------------------");
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
for (PrintService avPrt : printServices) {
System.out.println("\n\nPrinter installed: " + avPrt.getName());
AttributeSet attributesPr = avPrt.getAttributes();
for (Attribute a : attributesPr.toArray()) {
String name = a.getName();
String value = attributesPr.get(a.getClass()).toString();
System.out.println(" " + name + ": " + value);
//is it the queue?
if (name.equals("queued-job-count")) {
Object queue = Integer.parseInt(value);
System.out.println(" jobs in queue : " + queue);
}
}
}
}
}
//my spooler printer
//-----------------------------
Printer installed:SpoolerPrinter
printer-info: SpoolerPrinter
pdl-override-supported: not-attempted
color-supported: not-supported
queued-job-count: 5
jobs in queue : 5 // i want to know the jobs with the doc name
printer-name: Sewoo_POS_PRINTER
printer-is-accepting-jobs: accepting-jobs
//my destination printers
//i want
Printer installed: InvoicePrinter
printer-info: InvoicePrinter
pdl-override-supported: not-attempted
color-supported: not-supported
queued-job-count: 0
jobs in queue : 0
printer-name: Sewoo_POS_PRINTER
printer-is-accepting-jobs: accepting-jobs
Printer installed: DeliveryNotePrinter
printer-info: DeliveryNotePrinter
pdl-override-supported: not-attempted
color-supported: not-supported
queued-job-count: 0
jobs in queue : 5
printer-name: InvoicePrinter
printer-is-accepting-jobs: accepting-jobs