title: Print to specific printer (IPP URI) in Java
body: <p>Is there any way in Java to print to a specific IPP printer? All of the sample code and tutorials I've found focus on how to print a particular type of document, using something like the following:</p>
  
  <pre><code>DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
  PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
  aset.add(MediaSizeName.ISO_A4);
  PrintService[] pservices =
               PrintServiceLookup.lookupPrintServices(flavor, aset);
  if (pservices.length &gt; 0) {
      DocPrintJob pj = pservices[0].createPrintJob();
      try {
          FileInputStream fis = new FileInputStream("test.ps");
          Doc doc = new SimpleDoc(fis, flavor, null);
          pj.print(doc, aset);
      } catch (FileNotFoundException fe) {
      } catch (PrintException e) { 
      }
  }
  </code></pre>
  
  <p>This snippet simply prints to the first printer found that is capable of printing the document. In my case, I want to lookup a printer by its URI, but <code>PrintServiceLookup</code> doesn't seem to support this. I've tried using a <code>PrintServiceAttributeSet</code>, instead of <code>PrintRequestAttributeSet</code>, and adding a <code>PrinterURI</code> attribute, but that doesn't return any printers. I suspect the lookup service is looking for a printer that can change its destination URI, rather than looking for the printer with that URI.</p>
  
  <p>As a last resort, I thought about just enumerating through all of the <code>PrintService</code>s returned by <code>lookupPrintServices</code>, but the URI is not in any of the attributes. The printer name is there, but I need the URI.</p>
  
  <p>For background, my webapp needs to print a barcode to a specific printer, based on the current user. Each user is associated with a printer URI, which points to a printer on a CUPS server. The printer URI is the only information I have, and I can't constrain the printer name to match the URI or a substring of the URI.</p>
  
  <p><strong>Edit:</strong> To clarify a bit, I don't need to render the data, I just need to copy a blob to a given printer. The part I can't figure out is how to identify a printer by its IPP URI.</p>