1

i wanna convert each page of a pdf to a jpg file. Converting a single page works:

exec('/usr/local/bin/convert -density 288 -resize 50% -quality 85 -    colorspace CMYK dv.pdf[8] -colorspace RGB test.jpg');

Converting all pages does not work:

    exec('/usr/local/bin/convert -density 288 -resize 50% -quality 85 -    colorspace CMYK dv.pdf -colorspace RGB test.jpg');

What could be wrong?

Danack
  • 24,939
  • 16
  • 90
  • 122
peter
  • 11
  • 3
  • which "convert" is that? –  Dec 17 '15 at 00:04
  • sorry, i pasted the second "convert" by mistake. Code fixed. Problem still exists... – peter Dec 17 '15 at 00:09
  • @peter this isn't really a php question since the php code just executing the `convert` command line program and you question is about `convert`, not php. Try running your command in a terminal and post the any errors you receive when doing that. – Kyle Kochis Dec 17 '15 at 00:33
  • thx, the error is: convert: Postscript delegate failed `/home/httpd/docs/test/magazine/best/dv.pdf': No such file or directory @ pdf.c/ReadPDFImage/630. convert: missing an image filename `/home/httpd/docs/die8test2/magazine/best/ateste.jpg' @ convert.c/ConvertImageCommand/2819. – peter Dec 17 '15 at 01:12
  • but the file is there - by adding a page number dv.pdf[8] converting a single page works – peter Dec 17 '15 at 01:15

2 Answers2

0

you could use imagick to do this. More information can be found here at http://php.net/manual/en/imagick.setup.php

 <?php 
    $imagick = new Imagick(); 
    $imagick->readImage('myfile.pdf'); 
    $imagick->writeImages('converted.jpg', false); 
    ?> 
Juakali92
  • 1,155
  • 8
  • 20
  • thx, that works great - but the color of images is not the same as in pdf. The pdf is CMYK. How can i get correct colors using your example? – peter Dec 17 '15 at 00:15
  • if color becomes inverted, read the user contributed notes at http://php.net/manual/en/imagick.setimagecolorspace.php which shows different workarounds. – Juakali92 Dec 17 '15 at 00:26
  • no changes... according to this post http://stackoverflow.com/questions/4830478/php-imagick-rgb-to-cmyk-inverts - php imagick is not doing it, i need to do it with imagick command line as in my original post above. So the problem still exists.. – peter Dec 17 '15 at 00:44
0

I could not solve the problem, but i found an alternative solution - im executing Ghostscript without using Imagick:

exec(
    "'gs' '-dNOPAUSE' '-sDEVICE=jpeg' '-dUseCIEColor' '-dTextAlphaBits=4' 
    '-dGraphicsAlphaBits=4' '-o$exportPath' '-r$res' '-dJPEGQ=$quality' '$input'",
     $output
);
Jens A. Koch
  • 39,862
  • 13
  • 113
  • 141
peter
  • 11
  • 3