How do I know if PDF pages are color or black-and-white?

后端 未结 7 1947
太阳男子
太阳男子 2021-01-30 02:02

Given a set of PDF files among which some pages are color and the remaining are black & white, is there any program to find out among the given pages which are color and whi

7条回答
  •  故里飘歌
    2021-01-30 02:40

    Newer versions of Ghostscript (version 9.05 and later) include a "device" called inkcov. It calculates the ink coverage of each page (not for each image) in Cyan (C), Magenta (M), Yellow (Y) and Black (K) values, where 0.00000 means 0%, and 1.00000 means 100% (see Detecting all pages which contain color).

    For example:

    $ gs -q -o - -sDEVICE=inkcov file.pdf 
    0.11264  0.11605  0.11605  0.09364 CMYK OK
    0.11260  0.11601  0.11601  0.09360 CMYK OK
    

    If the CMY values are not 0 then the page is color.

    To just output the pages that contain colors use this handy oneliner:

    $ gs -o - -sDEVICE=inkcov file.pdf |tail -n +4 |sed '/^Page*/N;s/\n//'|sed -E '/Page [0-9]+ 0.00000  0.00000  0.00000  / d'
    

提交回复
热议问题