When i Debug this program the services array is empty??
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javax.print.D
This is because there was no PrintService found corresponding to the specified DocFlavor and Attribute Set. It may be hard to find a printer which supports PostScript unless your printer hardware is pretty up to date. You can check what all DocFlavors are supported like this:
DocFlavor[] docFalvor = prnSvc.getSupportedDocFlavors();
for (int i = 0; i < docFalvor.length; i++) {
System.out.println(docFalvor[i].getMimeType());
}
For locating a specific Print Service you can do something like this:
PrintService prnSvc = null;
/* locate a print service that can handle it */
PrintService[] pservices =
PrintServiceLookup.lookupPrintServices(null, null);
if (pservices.length > 0) {
int ii=0;
while(ii < pservices.length)
{
System.out.println("Named Printer found: "+pservices[ii].getName());
if (pservices[ii].getName().endsWith("YourPrinterName")) {
prnSvc = pservices[ii];
System.out.println("Named Printer selected: " + pservices[ii].getName() + "*");
break;
}
ii++;
}