A bash script to convert the color palette of a PDF into CMYK
It happens that you have to print for job or personal pleasure, one or more posters in a big format and like me you don't use famous commercial software and you aren't a professional illustrator. But how can the color palette of your document fit the request of the typography? This post tries to show a simple conversion of a PDF from RGB to CMYK, using ghostscript library and imagemagick in a handy bash script.
Firstly I want to highlight again that I am not an experience illustrator or graphic and probably the solution that I share with you it is not a good professional practice. However I think that it works and let you still use software like Gimp and Inkscape that at the moment do not support completely the CMYK color model.
Secondly, some people on Internet consider the CMYK conversion an useless practice for projects that not require offset but only a small amount of prints. Nevertheless the typographies always suggest the original file in CMYK.
For my business it is a querelle that does not bring me any advantage, but I had to produce 7 forex by 100x70 cm and magically this had became a problem. I generally use Gimp and Inkscape that work very well in RGB for my site. In this case I should have needed to try different software, like Scribus. Or I could have followed this guide to bring my Inkscape work into Scribus and then convert it. It works but generally I have to export in ps and process it in Scribus, loosing a lot of time and sometimes effects on texts. Too work and too complicated.
My solution is a simple script in bash that I execute after saving my work in PDF. In this manner I can still use my favorite software and create another PDF with CMYK color palette and two little jpegs, useful if I have to share a preview to my colleagues. The following are two jpegs (for the PDFs check the download section below):
Relating only to the images, Imagemagick offers useful commands to convert the colorspace of them, look this section: Image Profiles. For example if you have to put a target color profile like fogra27[fn]Imagemagick supports ICC and TXT profiles. I downloaded the fogra27 from this site: FOGRA27[/fn], you can type in a shell:
convert yourFile.pdf -profile FOGRA27L.txt yourFile_fogra27L.pdf
Instead with my script, you can:
- check if the input file (yourFile.pdf) has already the colorspace in CMYK
- convert it into a new PDF (yourFile_cmyk.pdf) with the colorspace in CMYK
- create two jpegs:
- yourFile.jpg with the original colorspace
- yourFile_cmyk.jpg with the colorspace in CMYK
- reduce the size of the jpegs by:
- reduction=70 #<-- percent in size (change if you want)
- quality=85 #<-- from 1 to 100 (change if you want, 100 is the best)
- print the colorspace for all the generated files
Requirement
You need to install:
- Imagemagick
- Ghostscript
Usage
Simply open a terminal and launch it after adding the input PDF file, in this way:
bash pdf2cmyk yourFile.pdf
Or:
./pdf2cmyk yourFile.pdf
Download
Get the zip or clone my repository from GitHub: github.com/rainnic/bash-scripts/tree/master/pdf2cmyk
References
Here are a few references which I used to write my script:
Comments
RGB To CMYK PDF
Hello,
Thank you for providing the bash script for the rgb to cmyk. It's working great.
I have one issue with the ghostscript. I have one PDF in which there are two images which has applied the filter effects. When I am trying to convert the RGB pdf to CMYK pdf, filter effected images are missing in the newly created CMYK pdf. Input pdf is converted from SVG to PDF.
Please provide me the solution.
Re: RGB To CMYK PDF
Hi Ajay, I had a similar problem in the past with Inkscape and I have solved enabling the "Rasterize filter effects" in the Save as window.
RGB To CMYK PDF
I am using the Inkscape command line tool for converting SVG to RGB PDF. So how can enable the "Rasterize filter effects". Also is there any facility with ghost script for converting SVG to CMYK PDF ?
Thank you
Re: RGB To CMYK PDF
I have tried with the following command line: inkscape input.svg -A output.pdf --export-dpi=300 -t -T and it works (Inkscape version 0.91). For the second question, I have no idea... I am sorry!
Thank you for answer and
Thank you for answer and support.
I have one more query.
When I am checking the converted CMYK PDF in Tools -> Print Production -> Output Preview -> Show(CMYK) in Adobe PDF, white color objects are disappeared. Means white color objects are not display in CMYK color mode.
Have u any idea about it?
Thanks in advance.
Ajay
Re: White color objects disappeared in Print Production preview
I don't have this feature on my Adobe Reader so I might suppose the white color objects simply disappear in Print Production preview, why should white colors be printed in a sheet of paper?
Re: Hello...
Hi, I suggest you to change my script adding the text in bold:
# Create a new pdf terminating in "_cmyk" with the CMYK colorspace gs -o ${1%%.pdf}_cmyk.pdf \ -sDEVICE=pdfwrite \ -dPDFSETTINGS=/prepress \ -dEncodeColorImages=false \ -dEncodeGrayImages=false \ -dEncodeMonoImages=false \ -sProcessColorModel=DeviceCMYK \ -sColorConversionStrategy=CMYK \ -sColorConversionStrategyForImages=CMYK \ $1
Hope it helps!
It's working. You are a…
It's working. You are a life saver.
Thank you very much.
Hello Nicola, …
Hello Nicola,
Need one more your help.
Is there any option in ghostscript that we can achieve SPOT / Pantone color output from RGB PDF ?
Thanks in advance.
Thanks,
Ajay
Re: achieve SPOT/Pantone color output from RGB PDF
Hello Ajay, in this case I can't help you because I don't understand your question: it's too specify and overtakes my little knowledge of ghostscript and advanced printing. However I suggest you two useful discussions on stackoverflow: Embed ICC color profile in PDF and CMYK Overprinting and Knockout in Ghostscript.
PDF DPI issue
Hello Nicola,
I am facing one more problem with Ghostscript.
My problem is that when I am converting RGB PDF(Which converted from SVG to PDF from inkscape and it includes filter on SVG clipart which is in 600DPI) to CMYK PDF, DPI of clipart obejct is converted 30 DPI..
Can u have idea that why there is such type of DPI issue with Ghostscript conversion.
I am using below command
gs -o ${1%%.pdf}_cmyk.pdf \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
-dEncodeColorImages=false \
-dEncodeGrayImages=false \
-dEncodeMonoImages=false \
-sProcessColorModel=DeviceCMYK \
-sColorConversionStrategy=CMYK \
-sColorConversionStrategyForImages=CMYK \
$1
Thanks,
Ajay
Re: PDF DPI issue
Hi Ajay, I don't know this issue, but in your case have you ever considered to try ExportPDFCMYK extension for Inkscape? Or a specific guide such as Creating CMYK Prepress PDFs with Inkscape and Scribus? Hope it helps!
Add new comment