Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I value ImageMagick in general very much -- but don't trust <code>convert</code> to count the colors correctly with the command you're using...</p> <p>May I suggest a different method to discover if a PDF page uses color? It is based on a (relatively new) Ghostscript device called <code>inkcov</code> (you need Ghostscript v9.05 or newer). It displays the ink coverage of CMYK for each single page (for RGB colors, it does a silent conversion to CMYK internally).</p> <p>First, generate an example PDF with the help of Ghostscript:</p> <pre><code>gs \ -o test.pdf \ -sDEVICE=pdfwrite \ -g5950x2105 \ -c "/F1 {100 100 moveto /Helvetica findfont 42 scalefont setfont} def" \ -c "F1 (100% 'pure' black) show showpage" \ -c "F1 .5 .5 .5 setrgbcolor (50% 'rich' rgbgray) show showpage" \ -c "F1 .5 .5 .5 0 setcmykcolor (50% 'rich' cmykgray) show showpage" \ -c "F1 .5 setgray (50% 'pure' gray) show showpage" </code></pre> <p>While <strong>all</strong> the pages do appear to the human eye to not use any color at all, pages 2 and 3 do indeed mix their apparent gray values from color.</p> <p>Now check each page's ink coverage:</p> <pre><code>gs -o - -sDEVICE=inkcov test.pdf [...] Page 1 0.00000 0.00000 0.00000 0.02230 CMYK OK Page 2 0.02360 0.02360 0.02360 0.02360 CMYK OK Page 3 0.02525 0.02525 0.02525 0.00000 CMYK OK Page 4 0.00000 0.00000 0.00000 0.01982 CMYK OK </code></pre> <p>(A value of 1.00000 maps to 100% ink coverage for the respective color channel. So <code>0.02230</code> in the first line of the result means <code>2.23 %</code> of the page area is covered by black ink.) Hence the result given by Ghostscript's <code>inkcov</code> is exactly the expected one: </p> <ul> <li>pages 1 + 4 don't use any of C (cyan), M (magenta), Y (yellow) colors, but only K (black).</li> <li>pages 2 + 3 do use ink of C (cyan), M (magenta), Y (yellow) colors, but no K (black) at all.</li> </ul> <p>Now let's convert all pages of the original PDF to use the <code>DeviceGray</code> colorspace:</p> <pre><code>gs \ -o temp.pdf \ -sDEVICE=pdfwrite \ -sColorConversionStrategy=Gray \ -sProcessColorModel=DeviceGray \ test.pdf </code></pre> <p>...and check for the ink coverage again:</p> <pre><code>gs -q -o - -sDEVICE=inkcov temp.pdf 0.00000 0.00000 0.00000 0.02230 CMYK OK 0.00000 0.00000 0.00000 0.02360 CMYK OK 0.00000 0.00000 0.00000 0.02525 CMYK OK 0.00000 0.00000 0.00000 0.01982 CMYK OK </code></pre> <p>Again, exactly the expected result in case of succesful color conversions! (<em>BTW, your <code>convert</code> command returns <code>2</code> for me for both files, the [original] <code>test.pdf</code> as well as the [gray-converted] <code>temp.pdf</code></em> -- so this command cannot be right...) </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload