title: How can I select papertray
body: <p>How do I programatically select the papertray to use when I send a document to the printer? There is different papers in the trays (A5, A4, A4 with one tear off part or two tear off parts, Papers with logo and without logo).</p>
  
  <p>Today we use the <code>setpapertray</code> command directly in the postscript-file, but this is not very convenient especially since we plan to move to producing pdf-files instead.</p>
  
  <p>Any suggestions?</p>
  
  <p><strong>EDIT</strong>: Today we send the ps-documents directly to the printer with commands like</p>
  
  <pre><code>cat file.ps &gt; /dev/usb/lp0
  </code></pre>
  
  <p>or in programs just by opening the device and writing to it.</p>
  
  <p>So since we use postscript templates its easy to select the tray to use directly by putting a section like this in the template:</p>
  
  <pre><code>statusdict begin
  /manualfeed false def
  $paper_tray setpapertray
  end
  </code></pre>
  
  <p>Now we want to get rid of the ps-templates since they are hard to work with, and its not always safe to assume the printer is directly connected but could be at a external printerserver.</p>
  
  <p>Questions:</p>
  
  <ul>
  <li>Is it possible to embed the tray selection in a pdf-file in the same way?</li>
  <li>Is there another more convenient way to select tray for each document when printing multiple documents?</li>
  </ul>