Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed ICC color profile in PDF

I am generating a PDF where all the graphics are drawn in \DeviceRGB in the sRGB color space. I would like to convert the PDF into a different Color Profile using an ICC profile and embed the ICC profile, but I can't find a good tool to do this.

I have tried ImageMagick, but that rasterizes the PDF which is undesirable, and I have tried using Ghostscript. But while that converts the colors, it doesn't embed the ICC profile.

Is there any tool or library (preferably Java or Scala) available for Linux that does what I want?

The Ghostscript commands I have tried are:

gs -o cmyk.pdf -sColorConversionStrategy=CMYK -sDEVICE=pdfwrite \
   -dOverrideICC=true -sOutputICCProfile=CoatedFOGRA27.icc \
   -dRenderIntent=3 in.pdf

and

gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -ColorConversionStrategy=CMYK \
   -dProcessColorModel=/DeviceCMYK -sOutputICCProfile=CoatedFOGRA27.icc \
   -sOutputFile=cmyk.pdf in.pdf 

and several variations of the above. I have tried both Ghostscript version 9.10 and 9.16.

like image 966
Thayne Avatar asked Jul 23 '15 15:07

Thayne


People also ask

How do you add a color block to a PDF?

Draw a rectangle the size of the area you want to fill. Right-click on the rectangle you just drew and choose Properties. On the Appearance tab, set the Style to No Border and the Fill Color to your desired shade. Click OK, and you'll have a colored block.

Should you embed color profile when exporting?

To be sure of preserving the color you see when you're editing, you need to embed the profile before saving the image. In simple terms, the ICC profile is a translator. It enables different apps and devices to interpret the color as you intended.


1 Answers

Use Ghostscript v9.16 or higher:

  • www.ghostscript.com/download/

Read its documentation about ICC color profile support, available here:

  • Ghostscript 9.15 Color Management (PDF)

Here's a possible command to convert the color space and embed the ICC profile:

gs -o cmyk-doc.pdf      \
   -sDEVICE=pdfwrite    \
   -dOverrideICC=true   \
   -sDefaultCMYKProfile=/path/to/mycmykprofile.icc \
   -sOutputICCProfile=/path/to/mydeviceprofile.icc \
   -dRenderIntent=3     \
   -dDeviceGrayToK=true \
    input-doc.pdf

(-dRenderIntent : possible arguments are 0 (Perceptual), 1 (Colorimetric), 2 (Saturation), and 3 (Absolute Colorimetric).)

Caveats

If you look at a PDF file on screen (or on paper, when printed) converted with above command and use a:

  • non-calibrated monitor/screen;
  • non-calibrated print device;
  • non-calibrated room illumination; or
  • PDF reader which cannot handle embedded ICC profiles, then

you may be disappointed. Using the wrong ICC profile or paper type that does not match the one expected by the output profile can also lead to issues.

like image 79
Kurt Pfeifle Avatar answered Sep 27 '22 16:09

Kurt Pfeifle