title: How to get how many pages a file will take when sent to a printer in Java?
body: <p>I am working on a project where I get a file and then print it using <code>desktop.print(file);</code>
  However, if this file is very large, say 50 pages, then I will not want to send the job to the printer.</p>
  
  <p>Is there a way to get the number of pages that a file will take to be printed before I start the job?</p>
  
  <p>Here is the part of the code where I do this:</p>
  
  <pre><code>File file = new File(filePath);         
  try {
      desktop.print(file);
  } catch (IOException e) {
      System.out.println("error in trying to print");
      e.printStackTrace();
  }
  </code></pre>