title: How to print PDF File in Java with Print Dialog
body: <p>I found a Java printing example <a href="https://examples.javacodegeeks.com/desktop-java/print/use-printing-service-in-java/" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Unfortunately, trying to execute I got a exception</p>
  
  <pre><code>Exception in thread "main" sun.print.PrintJobFlavorException: invalid flavor
  at sun.print.Win32PrintJob.print(Unknown Source)
  at application.UsePrintingServiceInJava.main(UsePrintingServiceInJava.java:55)
  </code></pre>
  
  <p>I also tried to print a png using <code>DocFlavor.INPUT_STREAM.PNG</code> flavor instead of the pdf, this works fine. May there be a problem with the printer itself or do I have to change the code?</p>
  
  <p>Moreover, if you have got a better solution to print a PDF file in Java, let me know.</p>