Script (or some other means) to convert RGB to CMYK in PDF?
Asked Answered
M

4

15

Is it possible to write a script for Adobe Illustrator or some other tool that will read the contents of a number of PDF files and convert all the RGB colours to CMYK?

If so, could somebody please point out some of the steps involved, or where to find more information on this?

Motorcycle answered 5/8, 2010 at 19:10 Comment(0)
T
25

This answer is not for Illustrator, but for 'some other tool', namely Ghostscript (download gs871w32.exe or gs871w64.exe).

Ghostscript allows you to 're-distill' PDFs (without an intermediate conversion to PostScript, the dreaded 'refrying' detour). Try this command:

gswin32c.exe ^
    -o c:/path/to/output-cmyk.pdf ^
    -sDEVICE=pdfwrite ^
    -dUseCIEColor ^
    -sProcessColorModel=DeviceCMYK ^
    -sColorConversionStrategy=CMYK ^
    -sColorConversionStrategyForImages=CMYK ^
     input-rgb.pdf

And if you are able to wait for a few more weeks, Ghostscript 9.00 will be released. This new version will sport support of colormanagement (based on LCMS) with ICC profiles for the first time ever...

UPDATE: I updated above command because I missed to put in the option to also convert images.


Update 2

If color conversion does not work as desired and if you see a message like "Unable to convert color space to Gray, reverting strategy to LeaveColorUnchanged" then...

  1. your Ghostscript probably is a newer release from the 9.x version series, and
  2. your source PDF likely uses an embedded ICC color profile

In this case add -dOverrideICC to the command line and see if it changes the result as desired.

Turnbuckle answered 6/8, 2010 at 11:57 Comment(4)
I gave this a shot.. it seems to have done the trick. I'm not really familiar with colour conversions, so please bear with me on this. Is it possible to specify a map that each RGB should go to in CMYK? Or is it done by best guess? Or is there a more accurate/scientific approach this application takes that I obviously don't know of?Motorcycle
@DaveDev: so... it seems to have done the trick? But you still see no reason to "accept" the answer? ----------- The 'map' you are asking for -- in colormanagement world they call it an 'ICC profile'. And re. ICC profile support in Ghostscript: see the last paragraph of my response ;-)Turnbuckle
I'm seeing: "Use of -dUseCIEColor detected! Since the release of version 9.11 of Ghostscript we recommend you do not set -dUseCIEColor with the pdfwrite/ps2write device family."Pistole
@krlmlr: Thanks for adding your comment. The original answer was written more than 8 years ago and relates to Ghostscript version 8.71.Turnbuckle
S
2

On Linux Mint / Ubuntu, I have tried that (from this) using ICC Profiles (Ghostscript 9.18, which don't like "-dUseCIEColor"):

gs -o output.pdf -sDEVICE=pdfwrite -r2400 -dOverrideICC=true -sOutputICCProfile=/usr/share/color/icc/Fogra27L.icm -sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK -dRenderIntent=3 -dDeviceGrayToK=true input.pdf

It "seems" to work (-r2400 is useful; it's for the resolution, it can be changed or removed).

Maybe adding "-sDefaultRGBProfile=/usr/share/color/icc/colord/sRGB.icc" could be better for the input... I don't know (and I don't know where). Maybe an expert could explain the best way to use.

Thanks. Regards,

Smallminded answered 7/11, 2017 at 10:58 Comment(0)
G
1

ABCpdf will recolor to CMYK or any other color space or profile you can think of. See:

http://www.websupergoo.com/helppdf7net/source/8-abcpdf6.operations/3-recoloroperation/1-methods/recolor.htm

Grosso answered 2/3, 2011 at 6:59 Comment(2)
Unfortunately it converts all images into bitmaps, making the documents vastly bigger. A bit of a show-stopper for me, I'm afraid.Recondition
Have you tested my answer for this question.Agree
A
1

I have written and tested the following script in Illustrator CC 2017:

var folder = Folder.selectDialog();
if (folder) {
    var files = folder.getFiles("*.pdf")
    for (var i = 0; i < files.length; i++) {
        app.open(files[i]);
        var doc = app.activeDocument;
        app.executeMenuCommand('doc-color-cmyk');
        doc.close(SaveOptions.SAVECHANGES);
    }
}

This script will ask for a folder, so select the folder that have your PDF file in. It will convert all PDF files in the selected folder to CMYK.

Agree answered 8/9, 2017 at 10:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.