title: Cannot print to PDF printer from Java
body: <p>I want to print the string <code>&quot;Hello world&quot;</code> to PDF. This is my code:</p>
  <pre><code>import java.io.ByteArrayInputStream;
  import java.io.InputStream;
  
  import javax.print.Doc;
  import javax.print.DocFlavor;
  import javax.print.DocPrintJob;
  import javax.print.PrintService;
  import javax.print.PrintServiceLookup;
  import javax.print.ServiceUI;
  import javax.print.SimpleDoc;
  import javax.print.attribute.HashPrintRequestAttributeSet;
  import javax.print.attribute.PrintRequestAttributeSet;
  import javax.print.event.PrintJobAdapter;
  import javax.print.event.PrintJobEvent;
  
  public class App {
  
      public static void main(String[] args) throws Exception {
          DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
  
          PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null);
  
          PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
          PrintService service = ServiceUI.printDialog(null, 200, 200, services, null, flavor, pras);
  
          // prints the famous hello world! plus a form feed
          InputStream is = new ByteArrayInputStream(&quot;hello world!\f&quot;.getBytes(&quot;UTF8&quot;));
  
          Doc doc = new SimpleDoc(is, flavor, null);
          DocPrintJob job = service.createPrintJob();
  
          job.print(doc, pras);
      }
  }
  </code></pre>
  <p>When the 'Print' dialog is shown I select &quot;Foxit Reader PDF Printer&quot;. The print job seems to be submitted, but I don't know where to find the printed PDF file. In theory, the printer should ask about the location of the PDF file (because when printing from Paint and Notepad it asks). But there are no dialogs. The job is silent.</p>
  <p>How to make my code show the standard Windows &quot;Save as&quot; dialog when printing to PDF?</p>