I seem to be unable to find whether Ghostscript is able to simply detect whether job is color or grayscale. I use Ghostscript for conversion of print jobs to PNG, but I also need to have information about color of the job, so I don't have to search it pixel by pixel again.
相关问题
- Correctly parse PDF paragraphs with Python
- Set BaseUrl of an existing Pdf Document
- How to create PNG images with more than 72dpi usin
- DBGrid - How to set an individual background color
- How can I get all text from a PDF in Swift?
相关文章
- Where does this quality loss on Images come from?
- Emacs/xterm color annoyance on Linux
- Read 16-bit PNG image file using Python
- Converting svg to png with inkscape command line f
- Python Sendgrid send email with PDF attachment fil
- matplotlib bwr-colormap, always centered on zero
- C# Saving huge images
- C# MVC website PDF file in stored in byte array, d
A (relatively new) Ghostscript device called
inkcov
(you need Ghostscript v9.05 or newer) can reliably detect whether a PDF page uses color or not.It displays the ink coverage for the CMYK inks, separately for each single page (for RGB colors, it does a silent conversion to CMYK color space internally).
To investigate and demonstrate its functions, first generate an example PDF with the help of Ghostscript:
While all 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. But none of the colors is directly visible (unless your monitor is grossly mis-adjusted).
Look at the resulting PDF pages (converted to PNG for easier display via the web):
In the Prepress industry, 'rich' blacks or shades of gray are frequently used. The idiom 'rich' black or gray is used to express the fact that these shades are not made from purely black toner or ink, but have mixed-in components of color to make them appear more brilliant and more saturated.
Now check each page's ink coverage:
(A value of 1.00000 maps to 100% ink coverage for the respective color channel. So
0.05040
in the first line of the result means5.04 %
of the page area is covered by black ink.) Hence the result given by Ghostscript'sinkcov
is exactly the expected one:Now let's convert all pages of the original PDF to use the
DeviceGray
colorspace:...and check for the ink coverage again:
Again, exactly the expected result in case of succesful color conversions!
A new output device has rendered this answer outdated, see the Accepted Answer.
Until 2011, the file needed to be rasterised to see an output. Since the PDF/PS is a description of what the file looks looks like which gets rendered whilst rasterised. Even if you could do this with ghostscipt I am sure it would need to rasterize/interpret the file first then look at the output, so if you have the png's you might as well do this yourself, which will be less cpu intensive than processing the file again with GS.