Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding color spaces in PDF from linux command line

Tags:

linux

image

pdf

I need to check if given PDF files are completely in CMYK color space. As you probably know, it is needed for printing.

Currently, it is done using GUI applications from Adobe, but it takes much time and we need to automate it with linux script.

I have tested many libraries, but each of them gave me invalid results or don't support newer PDF specs.

  • I haven't found solution for that in ghostscript
  • Exporting images from pdf is not good enough solution, since there are also paths and other media, which also need to be validated.
  • identify -verbose gives invalid results (bad colorspace, but also bad DPI).

As far as i know, PDF can have different color spaces for elements in document and I want to check if every element is in CMYK.

like image 540
rzelek Avatar asked Oct 20 '22 10:10

rzelek


1 Answers

You can do this by pdfimages:

pdfimages -list filename.pdf

For a file with CMYK images, the output resembles:

page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    5197  6732  cmyk    4   8  jpeg   no         5  0   600   601 32.3M  24%
   1     1 mask     5197  6732  -       1   1  jpeg   no         5  0   600   601 32.3M 775%

If all the images use an ICC profile, the output resembles:

page   num  type   width height color comp bpc  enc interp  object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
   1     0 image    5197  6732  icc     3   8  jpeg   no         8  0   600   601 7080K 6.9%
   1     1 mask     5197  6732  -       1   1  jpeg   no         8  0   600   601 7080K 166%
like image 174
Crantisz Avatar answered Oct 22 '22 00:10

Crantisz