2

I have a task where I need to take PDFs that are mock ups of printing products, and check their resolution, size and colour-space. I need to use Imagick with PHP to complete this task.

The printing shop that will print these PDFs only have CMYK printers and so, the uploaded PDF need to have CMYK colours. But I am not clear on how colour-spaces(CMYK/RGB) work in PDF, or in jpeg/png images. So, I have a few questions that will hopefully help me understand the thing better and complete the task:

  1. From what I understand, we can draw objects or add images to the pdf that can have their colours defined as RGB or CMYK, but how does this affect the colour-space of the entire PDF?

  2. Is it possible to check the colour-space of a PDF in php, without converting it jpeg/png?

  3. If I have images in a PDF defined in either CMYK or RGB colour-space and convert the PDF to jpeg/png with Imagick, does the colour-space remain the same in the converted image unless specifically mentioned by Imagick::transformImageColorspace()?

  4. A short background information on how colour-spaces work, how they are defined and detected and how they are affected when the file is converted from one mime-type to another.

P.S.: I am converting the PDFs to jpeg/png and checking the colour of the converted file as below, but it always gives false, no matter what pdf I use.

$img = new imagick(self::$_imgArray[0]);
if($img->getimagecolorspace() == imagick::COLORSPACE_CMYK)
    echo "Image is in CMYK";
Debopam Parua
  • 460
  • 1
  • 4
  • 24
  • When downvoting please do mention the reason with a short comment! Thanks! – Debopam Parua Oct 04 '18 at 13:03
  • "I need to use Imagick with PHP to complete this task." Why do you need to use image magick? Iterating the colorspaces in a PDF, getting page sizes/dimensions, are all straight forward, and there are many PDF reading libraries/tools out there that will give it to you. Who is creating the PDF files? Who is creating the mockups? – Ryan Oct 05 '18 at 05:27
  • "I need to use Imagick with PHP to complete this task."~~ This is the ideal requirement of the client, as he already has imagemagick installed on his server, and it would be preferable for him to use it and not any other libraries. But as I understand now, Imagemagick itself is not capable enough to do the tasks needed. – Debopam Parua Oct 05 '18 at 05:37
  • The PDF will be uploaded to the print shop by the user who wants his document printed. The print shop has various printing products and their size/color/resolution specifications are provided. The shop user who is looking to get something printed goes through the list with specifications, chooses a product, creates a pdf according to the specifications and uploads it. – Debopam Parua Oct 05 '18 at 05:42
  • Then, after the user has uploaded comes the task about which I have posted the question. The PDF uploaded by the user needs to be checked whether it corresponds to the size/color/resolution specifications provided by the shop. And hence I need to check the color space and resolution. – Debopam Parua Oct 05 '18 at 05:44
  • 1
    The only proper/true way to map what the user sees on their screen when creating the PDF, to what would be printed, is if the PDF also contains color profiles (e.g. ICC), and your printers have color profiles, then you can map from one to the other. Even if the PDF only contained CMYK values, there would still be color differences possible without profiles. Here are two good links you can read. https://thelogocompany.net/blog/branding-guides/color-profiles-printing-explained/ and https://www.hollandlitho.com/rgb_to_cmyk_what_you_need_to_know.html – Ryan Oct 05 '18 at 06:02
  • @Ryan.. Yes man.. I have been stuck with this task for 2 days now and came up with the term "ICC profiles" yesterday.. I am not experienced with printing and all even a little bit.. What i realised is: 1. When the user uploads a file, I need to check if it has an ICC profile and if it is set to CMYK. 2. If no ICC profile is found check the page for contained images, if an image is found corresponding to the size required (that is provided in the shop specification) and if it has CMYK color space. 3. Else, say that color space could not be detected. – Debopam Parua Oct 05 '18 at 06:19
  • "checked whether it corresponds to the size/color/resolution specifications". Note that PDF pages have up to 4 different dimensions, see figure 86 in PDF32000_2008.pdf. When you are viewing a PDF on your computer, you are looking at the crop box, but for printing you might be using one of the other, possibly larger dimensions. Other than that, size is straight forward. Color as discussed above, can be as complicated, or as simple, as you want. – Ryan Oct 05 '18 at 06:29
  • I am not sure what is meant by resolution. This would make sense for images in the page, in which case you would get raw image dimensions, and the transformation applied to the image, and apply the 1/72inch scale to get a "resolution". – Ryan Oct 05 '18 at 06:30
  • I would recomend going back to the print shop and finding out more about the requirements, or at the very least what software they use for RIP, and from that RIP what the accepted inputs are. https://en.wikipedia.org/wiki/Raster_image_processor – Ryan Oct 05 '18 at 06:33

1 Answers1

5

I have a task where I need to take PDFs that are mock ups of printing products, and check their resolution, size and colour-space.

A PDF page does not have a resolution (though images on the page do). It does have a "physical" dimension, default being Letter size. PDF units are by default 1/72 inch. If a PDF page contains pure vector data, then it look great at any resolution.

See below for more detail, but a single PDF page/document can contain one or more of Gray, RGB, CMYK, LAB, and more, color spaces.

  1. but how does this affect the colour-space of the entire PDF?

It doesn't, the PDF itself does not have an overall color space. Typically a PDF processor would convert all graphics to a target color space, e.g. Chrome would at some point have everything in RGB since it is drawing to a screen.

  1. Is it possible to check the colour-space of a PDF in php, without converting it jpeg/png?

Sure, though a single PDF could contain greyscale, rgb, cmyk, lab, separation colors, etc. Again, there is no one color space in a PDF file.

  1. If I have images in a PDF defined in either CMYK or RGB colour-space and convert the PDF to jpeg/png with Imagick, does the colour-space remain the same in the converted image unless specifically mentioned by Imagick::transformImageColorspace()?

It would depend on the software doing the conversion. Since PNG does not support CMYK, then at the very least any CMYK would be converted. Exactly what happens depends on the software, the settings, and the target output format and what is supports.

  1. A short background information on how colour-spaces work, how they are defined and detected and how they are affected when the file is converted from one mime-type to another.

See section 8.6 here: https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf Here is another good link https://www.color-management-guide.com/color-spaces.html

Ryan
  • 2,473
  • 1
  • 11
  • 14