Skip to main content
Working from scratch, following simplicity

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.

A bash script to convert the color palette of a PDF into CMYK

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):

  •  RGB colorspace example
    RGB colorspace
  •  CMYK colorspace example
    CMYK colorspace

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 fogra271 , 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


You need to install:

  • Imagemagick
  • Ghostscript


Simply open a terminal and launch it after adding the input PDF file, in this way:

bash pdf2cmyk yourFile.pdf


./pdf2cmyk yourFile.pdf


Get the zip or clone my repository from GitHub:


Here are a few references which I used to write my script:

  • 1Imagemagick supports ICC and TXT profiles. I downloaded the fogra27 from this site: FOGRA27

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Sponsored Links

Nicola Rainiero

A civil geotechnical engineer with the ambition to facilitate own work with free software for a knowledge and collective sharing. Also, I deal with green energy and in particular shallow geothermal energy. I have always been involved in web design and 3D modelling.