title: Findout if the page is b&w or color in PDF using java
body: <p>Related to this: <a href="https://stackoverflow.com/questions/641427/how-do-i-know-if-pdf-pages-are-color-or-black-and-white">How do I know if PDF pages are color or black-and-white?</a></p>
  
  <p>I need to know if the current page is a color or black&amp;white one using java.</p>
  
  <p>I tried using PDFBox, doing the following:</p>
  
  <pre><code>public void checkColor(final File pdfFile) {
      PDDocument document;
      try {
          document = PDDocument.load(pdfFile);
  
          List&lt;PDPage&gt; pages = document.getDocumentCatalog().getAllPages();
          for (int i = 0; i &lt; pages.size(); i++) {
              System.out.println();
              PDPage page = pages.get(i);
              //BufferedImage image = page.convertToImage();
              BufferedImage image = page.convertToImage(BufferedImage.TYPE_INT_RGB, 72);
  
              parseColor(image, i);
          }
  
          printPages();
  
      } catch (IOException ex) {
          Logger.getLogger(PdfBoxParser.class.getName()).log(Level.SEVERE, null, ex);
      }
  }
  public static boolean isColorPixel(final int pixel) {
      //took from some post from stackoverflow
      System.out.print(pixel);
      System.out.print(",");
      int alpha = (pixel &gt;&gt; 24) &amp; 0xff;
      int red = (pixel &gt;&gt; 16) &amp; 0xff;
      int green = (pixel &gt;&gt; 8) &amp; 0xff;
      int blue = (pixel) &amp; 0xff;
      // gray: R = G = B
      boolean gray = (red == green &amp;&amp; green == blue);
      return gray;
  }
  
  protected void parseColor(BufferedImage pImage, int pPageNumber) {
      int thresholdColor = Main.COLOR_THRESHOLD_PER_PAGE;
      for (int h = 0; h &lt; pImage.getHeight(); h++) {
          for (int w = 0; w &lt; pImage.getWidth(); w++) {
              int pixel = pImage.getRGB(w,h);
              boolean color = Main.isColorPixel(pixel);
              if (color) {
                  thresholdColor--;
                  if (thresholdColor == 0) {
                  //do something like store this page number...
                  .
                  .
                  .
  </code></pre>
  
  <p>Problem is, i tried various PDFs (ebooks, one-page pdfs, etc) and every "final int pixel" returns "-1", along with a bunch of warnings (org.apache.pdfbox.util.PDFStreamEngine processOperator unsupported/disabled operation: i/EMC/BMC/ri). Can this be solved?</p>