Jacob Collins Jacob is the JPedal Product Lead and specialises in PDF creation and manipulation. He also develops Salesforce backend systems and contributes to marketing and support. Outside of work, he’s a 1900‑rated chess player, guitarist, and French learner.

How to add a CMYK image to a PDF in Java (Tutorial)

1 min read

cmyk image in pdf

TL;DR

Printers operate in CMYK colour space rather than RGB, so adding a CMYK image to a PDF will ensure printing accuracy. The JPedal Java PDF library supports this using the addImage() method.

What are image colour spaces?

A colour space is a way of representing pixels using a combination of different channels. Each channel represents a colour and an intensity. The most common colour space is RGB (red, green, blue) which is used on computer monitors and phone screens, but there are many other options like CMYK (cyan, magenta, yellow, key AKA black) which is used for printing, or YCbCr (luma, blue, red) which is commonly used in highly compressed image formats.

Why would you insert a CMYK image into a PDF?

Commercial printers use the CMYK colour space so if you add images into your PDF as CMYK then you will ensure a greater accuracy when printing the documents.

Can PDF support CMYK images?

Yes, PDF supports CMYK and is the industry standard for professional printing because of it. While web-based PDFs usually use RGB, the PDF format can natively store four-colour CMYK data, embed specific colour profiles (like Fogra or GRACoL), and handle “spot colours” (Pantone).

How to set up JPedal

To get started using the JPedal PDF library, download the JPedal trial jar from our website, and add it to your Java project.

How to add a CMYK image to a PDF in Java

By using the code snippet below you can flatten the target PDF. Using JPedal’s PDF Manipulator class:

  1. Load the document
  2. Call the addImage() method and choose the CMYK colour space.
  3. Save the result


 

Download JPedal

You can download a JPedal trial jar to see how it works.

Resources

Learn more about manipulating PDF files in Java.

We can help you better understand the PDF format as developers who have been working with the format for more than 2 decades!



The JPedal PDF library allows you to solve these problems in Java


Jacob Collins Jacob is the JPedal Product Lead and specialises in PDF creation and manipulation. He also develops Salesforce backend systems and contributes to marketing and support. Outside of work, he’s a 1900‑rated chess player, guitarist, and French learner.