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

后端 未结 7 1935
太阳男子
太阳男子 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 03:01

    I would try to do it like that, although there might be other easier solutions, and I'm curious to hear them, I just want to give it try:

    1. Loop through all pages
    2. Extract the pages to an image
    3. Verify the color range of the image

    For the page count, you can probably translate that without too much effort to Perl. It's basically a regex. It's also said that:

    r"(/Type)\s?(/Page)[/>\s]"

    You simply have to count how many times this regular expression occurs in the PDF file, minus the times you find the string "<>" (empty ages which are not rendered).

    To extract the image, you can use ImageMagick to do that. Or see this question.

    Finally, to get whether it is black and white, it depends if you mean literally black and white or grayscale. For black and white, you should only have, well, black and white in all the image. If you want to see grayscale, now, it's really not my speciality but I guess you could see if the averages of the red, the green and the blue are close to each other or if the original image and a grayscale converted one are close to each other.

    Hope it gives some hints to help you go further.

    0 讨论(0)
提交回复
热议问题