title: Giving multiple documents to a Java PrintService print job?
body: <p>I'm using the following method to print pdf documents to my printer.  It works fine if I want to print something just one time, but it takes much longer to print something multiple times.</p>
  
  <pre><code>public static void print() 
  {
      DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
      PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null);
      FileInputStream psStream = null;
      try 
      {
          psStream = new FileInputStream(System.getProperty("user.home")+"\\My Documents\\document.txt");
      } 
      catch (FileNotFoundException e)
      {
          System.out.println(e);
      }
      if (psStream == null) 
          return;
  
      if (services.length &gt; 0) 
      {
          PrintService myService = null;
          for (PrintService service : services) 
          {
              System.out.println(service.getName());
              if (service.getName().contains("printer_name")) 
              {
                  myService = service;
                  break;
              }
          }
          DocPrintJob printJob = myService.createPrintJob();
          Doc document = new SimpleDoc(psStream, flavor, null);
  
          try 
          {
              printJob.print(document, null);
          } catch (PrintException e) 
          {
              System.out.println(e);
          }
      } else 
      {
          System.out.println("No PDF printer available.");
      }
  }
  </code></pre>
  
  <p>So if I want to print a document five times and I put <code>print()</code> in a loop, then there's a pretty long delay between each printing of the document.  This kind of makes sense to me because the connection to the printer has to be reestablished for each document, and the document has to be resent.  Is there any way to maybe give a print job the same document multiple times using this API?</p>
  
  <p>I guess it's worth noting that I've tried putting the <code>printJob.print(document,null)</code> command in a loop which generated a <code>PrintException: already printing</code>.  Maybe if there was a way to make it wait until the current document is done before sending the next it could work?  At a loss here.  Thanks.</p>
  
  <p>@mthmulders: I tried the following and only one copy printed.  Anything I did wrong?</p>
  
  <pre><code>    Doc document = new SimpleDoc(psStream, flavor, null);
      PrintRequestAttributeSet set = new HashPrintRequestAttributeSet();
      set.add(new Copies(5));
  
      try 
      {
          printJob.print(document, set);
      } catch (PrintException e) 
      {   
          System.out.println(e);
      }
  </code></pre>