Hi everyone this is my first question at the site .
i use : NetBeans IDE 7.0.1 and i want to print a PDF with java , but i dont know where is the mistake in my code , please help me .
there is a good code which one print a GIF used the 5-th printer.
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras);
if (pss.length == 0) throw new RuntimeException("No printer services available.");
PrintService ps = pss[5];
System.out.println("Printing to " + ps);
DocPrintJob job = ps.createPrintJob();
FileInputStream fin = new FileInputStream("a.gif");
Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);
job.print(doc, pras);
fin.close();
But i dont know whats wrong the following code which try to print a PDF at the same printer(5th)
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.PDF, pras);
if (pss.length == 0) throw new RuntimeException("No printer services available.");
PrintService ps = pss[5];
System.out.println("Printing to " + ps);
DocPrintJob job = ps.createPrintJob();
FileInputStream fin = new FileInputStream("test.PDF");
Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.PDF, null);
job.print(doc, pras);
fin.close();
this is the program answer : " Exception in thread "main" java.lang.RuntimeException: No printer services available. "
If you have any idea please write it Thanks