php - convert pdf into jpg using exec -
i want convert pdf-image .jpg-image.
i made convert.php can call filename of pdf file , convert jpg. call function this: http://www.example.ch/tools/img/cache/convert.php?f=mypdf.pdf
this looks this:
if ($f = @$_request['f']) { $f = htmlspecialchars(urldecode($f)); $url = 'http://www.example.ch/img/cache/'.$f; $file = strtolower($f); $ch = curl_init($url); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (windows; u; windows nt 6.1; en-us; rv:1.9.1.2) gecko/20090729 firefox/3.5.2 gtb5'); $data = curl_exec($ch); $retcode = curl_getinfo($ch, curlinfo_http_code); curl_close($ch); if ($retcode == 200) { file_put_contents($file, $data); $converted_filename = str_replace('.pdf', '.jpg', $file ); $cmd = 'convert '.$file.' '.$converted_filename; exec('convert '.$file.' '.$converted_filename); $fp = fopen($converted_filename, 'rb'); header('content-type: image/jpeg'); header("content-length: " . filesize($converted_filename)); fpassthru($fp); exit; } else { header("http/1.0 404 not found"); } }
after done .jpg file size of 700kb in folder , can't open because corrupted. , html output like: image can't oppened because contains errors..
the best tool above imagemagic.
install image magic in system , refer link
convert pdf jpeg php , imagemagick
it easy these kind of things using imagemagic. refer link
http://php.net/manual/en/imagick.setimageformat.php
hope solve problem
Comments
Post a Comment