title: How to count color pages in a PDF/Word doc using Java
body: <p>I am looking to develop a desktop application using Java to <strong>count the number of colored pages</strong> in a <strong>PDF</strong> or <strong>Word</strong> file. This will be used as part of an overall system to help <em>calculate the cost of printing a document</em> in terms of how many pages there are (color/B&amp;W).</p>
  
  <p>Ideally, the user of the application would use a file dialog to select the desired PRF/Word file, the application could then count and output the number of colored pages, allowing the system to automatically calculate document cost accordingly. </p>
  
  <p><em>i.e 
  if A4 colored pages cost 50c per page to print, 
  and B&amp;W cost 10c per page, 
  calculate the total cost of the document per colored/B&amp;W pages.</em></p>
  
  <p>I am aware of the existing software <em>Rapid PDF Count</em> <a href="http://www.traction-software.co.uk/rapidpdfcount/" rel="nofollow">http://www.traction-software.co.uk/rapidpdfcount/</a>, but would be unsuitable as part on integration into a new system. I have also tried using GhostScript/Python as per this solution: <a href="http://root42.blogspot.de/2012/10/counting-color-pages-in-pdf-files.html" rel="nofollow">http://root42.blogspot.de/2012/10/counting-color-pages-in-pdf-files.html</a>, however this takes too long (5mins to count a 100 page pdf), and would be difficult to implement into a desktop app.</p>
  
  <p>Is there any method of counting the number of colored pages in a PDF or Word file using Java (or alternative language)</p>
  
  <p>Thanks</p>