Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ghostscript outputs blank pdf

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:

  • Script (or some other means) to convert RGB to CMYK in PDF?
  • Converting PDF to CMYK (with identify recognizing CMYK)
  • PowerBuilder 12.5 Classic GhostScript blank pdf
  • PowerBuilder 12.5 Classic PDF SaveAs creating files of 0 size on Win7 x64
like image 296
user3070053 Avatar asked Dec 28 '25 16:12

user3070053


1 Answers

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!

like image 55
user3070053 Avatar answered Dec 31 '25 19:12

user3070053