views:

198

answers:

1

I need to create thumbnails from dynamic (database driven) pdf's. I've used a variation of the script below in the past, but this doesn't seem to be working for me now (page just hangs).

<?php
 require_once('./template/all_includes.php');

 $descriptorspec = array(
  0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
  1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
  2 => array("pipe", "w")   // stderr is a file to write to
 );

 $cwd = '/tmp';
 $env = array('asdfadf' => '193');

 $convert = "convert pdf:- png:-";
 $process = proc_open($convert, $descriptorspec, $pipes, $cwd, $env);

    fwrite($pipes[0], 'php /var/www/html/domain.co.uk/store/pdf.php');
    fclose($pipes[0]);

    while(!feof($pipes[1])) $im .= fread($pipes[1], 1024);
    fclose($pipes[1]);

    $return_value = proc_close($process);

 header("Content-Type: image/png");
 echo $im;

   ?>

Could anyone help me out with this please? Much appreciated :)

A: 

Magick can open PDFs natively:

$im = new MagickWand('file.pdf[3]');  // open page 3 of the PDF
$png = $im->whateverTheMethodIsForPNG();
Coronatus
I want to avoid the API's as the performance hit is significant over using exec()
Simon Stevens
Where did I use `exec()`?
Coronatus
I wasn't very clear. Using the PHP Native API's is a significant performance hit over using the command line (via exec or similar). Hence my need to use the method I outlined.
Simon Stevens
Running something thru exec() and a native API will be the same speed if they are the same language (and there is a 80% chance it is, probably) -- C.
Coronatus
I worked on a project where I initially used the API's to generate dynamic styled text. After a lot of frustration with the speed, I reverted to using command line/exec which improved the generation time to just a few hundredths of a second (from several seconds).Not really looking to argue the point, just backing up my claims in case somebody finds it useful one day.
Simon Stevens