4

I'm using following command in PHP to convert a PDF with RBG colors to CMYK colors:

$input  = PDF_DIR . 'input.pdf';
$output = PDF_DIR . 'output.pdf'

exec("'gs'
      '-sDEVICE=pdfwrite'
      '-dUseCIEColor'
      '-sProcessColorModel=DeviceCMYK'
      '-sColorConversionStrategy=CMYK'
      '-sColorConversionStrategyForImages=CMYK'
      '-sOutputFile=$output'
      '$input'
");

I am using Ghostscript version 8.71.

gs -v
GPL Ghostscript 8.71 (2010-02-10)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.

Somehow the result is always an empty pdf file. Does anyone know what I'm doing wrong?

Thanks in advance for any answers, Cheers!

Some references:

Community
  • 1
  • 1
user3070053
  • 51
  • 1
  • 4
  • Here is an idea: why not put another parameter to exec() for collecting output from GS, then see if GS outputs some error messages? –  Dec 05 '13 at 13:25
  • This version of GS is very old try using the version 9.06 which is more stable for me than the latest one – mmoghrabi Dec 08 '13 at 10:37

2 Answers2

1

It seems to work if I omit the -dUseCIEColor parameter. I also added an parameter to collect the output like Sami Laine suggested. This is my final code:

$input  = PDF_DIR . 'input.pdf';
$output = PDF_DIR . 'output.pdf'

exec("'gs'
  '-o $return'
  '-sDEVICE=pdfwrite'
  '-sProcessColorModel=DeviceCMYK'
  '-sColorConversionStrategy=CMYK'
  '-sColorConversionStrategyForImages=CMYK'
  '-sOutputFile=$output'
  '$input'
");

Thank you for your answers!

user3070053
  • 51
  • 1
  • 4
  • Devs say ([1](https://bugs.ghostscript.com/show_bug.cgi?id=700819#c1),[2](https://bugs.ghostscript.com/show_bug.cgi?id=693716#c4),[3](https://ghostscript.com/irclogs/2012/11/21.html),[4](https://stackoverflow.com/a/36337225/1032586)) that there's no `sColorConversionStrategyForImages` switch. – Igor Mar 19 '19 at 22:35
0

In addition to what Sami says above (which is excellent advice, you need to see the back channel output) you should also upgrade, 8.71 is quite old.

KenS
  • 30,202
  • 3
  • 34
  • 51