Reputation: 83
I have a couple of sRGB PDF figures which I'm trying to convert to CMYK EPS for an accepted paper. Since I saw no posts explaining the entire procedure in one step, I decided to first do sRGB PDF -> CMYK PDF and then CMYK PDF -> CMYK EPS. This second step is where I get stuck, but I will include the entire procedure for completeness.
I illustrate my questions using the following figures, where the first one if the input. The three figures are in the zip file https://www.dropbox.com/s/7wr84bqhp3rzagg/figs.zip?dl=0
I will use these numbers for convenience for the rest of the question. After a couple of hours I was finally able to convert sRGB PDF (1) to CMYK PDF (2) by combining answers from Converting PDF to CMYK (with identify recognizing CMYK) . The hardest part was to let 'identify' detect that the new PDF was actually CMYK. I used Chris Hecker's hacky trick to get this conversion step to work. I then call identify with the command:
identify -format '%[colorspace]' figure_1_cmyk.pdf
and it says CMYK, so far so good. The next step should be easy I thought, just convert the CMYK PDF to CMYK EPS. But this is where I really get stuck. I am using the following bash script 'pdf2eps.sh' on (2) to get (3).
#!/bin/bash
gs \
-dNOPAUSE \
-dNOCACHE \
-dBATCH \
-dNOSUBSTDEVICECOLORS \
-sDEVICE=eps2write \
-sOutputFile="${1%%.pdf}.eps" \
"$1"
Both with and without the '-dNOSUBSTDEVICECOLORS' flag the resulting .eps file (3) somehow reverts back to sRGB as detected by 'identify'. You can check so yourself using the provided figures. I really have no idea left of what I can try, but I'm also very new to ghostscript. I would be very grateful if someone with more knowledge than me could show me how to get (3) to be CMYK.
Could it be that identify is just buggy? I don't know of other ways using linux tools to check if (3) is actually CMYK. If there are easier ways to get sRGB PDF to CMYK EPS with high quality I would be interested as well of course. The command line tool 'convert' doesn't give good results to me.
sincerely, Bram
P.S. Since requested in one of the answers, the code I use for the first step (RGB PDF -> CMYK PDF) is the following:
bash script
#!/bin/bash
gs \
-dPDFX \
-dBATCH \
-dNOPAUSE \
-dNOOUTERSAVE \
-dPDFSETTINGS=/prepress \
-dCompatibilityLevel=1.5 \
-sDEVICE=pdfwrite \
-sColorConversionStrategy=CMYK \
-sProcessColorModel=DeviceCMYK \
-dHaveTransparency=false \
-sOutputFile="${1%%.pdf}_cmyk.pdf" \
PDFX_def_fogra39_trickcmyk.ps \
"$1"
with added file 'PDFX_def_fogra39_trickcmyk.ps'
%!
% $Id$
% This is a sample prefix file for creating a PDF/X-3 document.
% Feel free to modify entries marked with "Customize".
% This assumes an ICC profile to reside in the file (ISO Coated sb.icc),
% unless the user modifies the corresponding line below.
systemdict /ProcessColorModel known {
systemdict /ProcessColorModel get dup /DeviceGray ne exch /DeviceCMYK ne and
} {
true
} ifelse
{ (ERROR: ProcessColorModel must be /DeviceGray or DeviceCMYK.)=
/ProcessColorModel cvx /rangecheck signalerror
} if
% Define entries to the document Info dictionary :
% /ICCProfile (/usr/share/color/icc/ISOcoated_v2_300_eci.icc) def % Customize or remove.
[ /GTS_PDFXVersion (PDF/X-3:2002) % Must be so (the standard requires).
/Title (Title) % Customize.
/Trapped /False % Must be so (Ghostscript doesn't provide other).
/DOCINFO pdfmark
% Define an ICC profile :
currentdict /ICCProfile known {
[/_objdef {icc_PDFX} /type /stream /OBJ pdfmark
[{icc_PDFX} <</N systemdict /ProcessColorModel get /DeviceGray eq {1} {4} ifelse >> /PUT pdfmark
[{icc_PDFX} ICCProfile (r) file /PUT pdfmark
} if
% Define the output intent dictionary :
[/_objdef {OutputIntent_PDFX} /type /dict /OBJ pdfmark
[{OutputIntent_PDFX} <<
/Type /OutputIntent % Must be so (the standard requires).
/S /GTS_PDFX % Must be so (the standard requires).
/OutputCondition (Commercial and specialty printing) % Customize
/Info (none) % Customize
/OutputConditionIdentifier (FOGRA39) % Customize
/RegistryName (http://www.color.org) % Must be so (the standard requires).
currentdict /ICCProfile known {
/DestOutputProfile {icc_PDFX} % Must be so (see above).
} if
>> /PUT pdfmark
[{Catalog} <</OutputIntents [ {OutputIntent_PDFX} ]>> /PUT pdfmark
[/_objdef {OutputIntent_PDFX} /type /dict /OBJ pdfmark
[{OutputIntent_PDFX} <<
/ColorSpace /DeviceCMYK % convince ImageMagick's identify that it's CMYK
/Type /OutputIntent % Must be so (the standard requires).
/S /GTS_PDFX % Must be so (the standard requires).
/OutputCondition (Commercial and specialty printing) % Customize
/Info (none) % Customize
/OutputConditionIdentifier (CGATS TR 003) % Customize
/RegistryName (http://www.color.org) % Must be so (the standard requires).
currentdict /ICCProfile known {
/DestOutputProfile {icc_PDFX} % Must be so (see above).
} if
>> /PUT pdfmark
[{Catalog} <</OutputIntents [ {OutputIntent_PDFX} ]>> /PUT pdfmark
Upvotes: 1
Views: 1540
Reputation: 31139
OK firstly you're using a slightly old version of Ghostscript (9.18) the current version is 9.20 and 9.21 will be released shortly.
Secondly; you can do the whole job in one step. You haven't stated the command line you are using to create a CMYK PDF but if you use eps2write instead of pdfwrite in that command line you should get a CMYK EPS instead of a CMYK PDF. The two devices actually share more than 99% of their code and most command line switches work identically with the two devices.
The NOSUBSTDEVICECOLORS switch is essentially obselete and really shouldn't be used at all now.
Finally; you haven't given a good reason why you think the EPS file is not CMYK. I don't find 'identify' to be a useful tool here. The only way to detect the colour space(s) in use in a PostScript program is to fully interpret it, and identify is not a PostScript interpreter! I would guess that its using Ghostscript to render the EPS, and the colour space of the image will depend on what Ghostscript device was used for rendering.
Looking inside your output file I see the colours are specified using:
0.875 0.765625 0 0 k
0.875 0.765625 0 0 K
/k and /K are defined as:
/k/setcmykcolor load def
/K/setcmykcolor load def
If the file used RGB colours then you would expect to see "r g b rg" or "r g b RG", neither of which are present in the body of the EPS file.
So yes, its identify which is at fault, though I don't particularly blame it for that, I believe its intended use really is for bitmap images, not high level page description languages. As I noted above if you take the command line you are using to create a CMYK PDF and instead set the device to eps2write you should get a CMYK EPS In a single step. Note that, because EPS is intended for inclusion in other programs, it cannot contain more than a single page, so if you start with a multi-page input, you should use the '%d' filename syntax to get multiple EPS files, one per page.
EDIT Much of the content here is superfluous, or potentially harmful when creating an intermediate file:
gs \
-dPDFX \
-dBATCH \
-dNOPAUSE \
-dNOOUTERSAVE \
-dPDFSETTINGS=/prepress \
-dCompatibilityLevel=1.5 \
-sDEVICE=pdfwrite \
-sColorConversionStrategy=CMYK \
-sProcessColorModel=DeviceCMYK \
-dHaveTransparency=false \
-sOutputFile="${1%%.pdf}_cmyk.pdf" \
PDFX_def_fogra39_trickcmyk.ps \
"$1"
Making a PDF/X limits the permitted construction of a PDF file, which means you are going to be falling back to lower level defaults when you don't necessarily need to. If you don't set PDF/X then you don't need the PDF/X_def.ps file either as all that does is set the defaults.
You don't need to set -dHaveTransparency=false, firstly because that's wrapped up in the PDF/X code, and secondly because PostScript doesn't support transparency, so if you go direct to EPS that is taken care of for you too.
You shouldn't use any PDFSETTINGS unless you have a good reason (and can explain it to me ;-)
Same for limiting the PDF level (and pdfwrite doesn't create PDFs using features above 1.5 anyway)
Don't use NOOUTERSAVE, all that does in this context is cost you performance....
With current code, if you set ColorConversionStrategy then it sets the ProcessColorModel for you, so you don't need to do that either.
I'd suggest this:
gs \
-dBATCH \
-dNOPAUSE \
-sDEVICE=eps2write \
-sColorConversionStrategy=CMYK \
-sOutputFile="${1%%.pdf}_cmyk.eps" \
"$1"
Upvotes: 1