1

I use Imagick to convert pdf to JPG. The problem is that pdf is in CMYK format and the colors from resulting jpg is slightly different from those from pdf. I use the following code to achieve the result:

$filelist = array("D3807797-8425-5-1_40.pdf[2]","D3807797-8425-5-1_40.pdf[3]");

$all = new Imagick();

foreach($filelist as $file){
    $im = new Imagick($file);       
    $all->addImage($im);

}

$all->resetIterator();
$combined = $all->appendImages(true);


$combined->setImageFormat("jpg");
$combined->writeImage("test.jpg");

I also tried a linux command for this

$cmd = "gm convert -density 150x150 {$pdf}[2] {$pdf}[3] -append -quality 100 {$image}";
exec($cmd)

And i get the same result.

Could somebody help me with this problem? Thanks in advance.

Centurion
  • 5,169
  • 6
  • 28
  • 47
  • 1
    "Slightly different" sounds as expected when converting from CMYK to RGB. Can you show an example? Do the images in the PDF have colour profiles attached? – Pekka Jan 10 '12 at 10:20
  • @Pekka , I edited and put the link to pdf and images. – Centurion Jan 10 '12 at 10:25
  • CMYK to RPG cannot be done 100% accurate. The best you can do on your site is to make a note colors can differ, and link to the PDF too. – Rene Pot Jan 10 '12 at 10:38
  • @TopenerIt could be possible , but the problem is that the pdf i have to send to one place but screenshot ot another, but they have to be the same. – Centurion Jan 10 '12 at 10:52
  • @Centurion the thing is that CMYK colour can't be mapped to RGB 1:1. There needs to be a colour profile in play in order to *try* and get similar results. This is rather complicated to get right, not sure what to suggest... Except try and use colour profiles if any are available in the incoming data. – Pekka Jan 10 '12 at 19:53

1 Answers1

0

I cannot say definitive what is different (I for one do not see much difference between the image and pdf). But a good possibility is the conversion routine used to convert the CMYK channels to RGB. PDF uses the following formula:

  • red = 1 - min( 1, cyan + black )
  • green = 1 - min( 1, magenta + black )
  • blue = 1 - min( 1, yellow + black )

And there are other formulas around yielding different results, perhaps the conversion used by your tooling isn't the prescribed one in the PDF standard.

Note that in the PDF file specified I do see that both DeviceRGB and DeviceCMYK are used; everything is vector based, no images are present.

Ritsaert Hornstra
  • 5,013
  • 1
  • 33
  • 51