Freelancer Martin Zeller

php asp.net java c# .net c++ xml xhtml seo magento zend framework dotnetnuke tomcat iis sql server mysql oracle typo3 coremedia

Pdf thumbnails / Pdf to jpg

Tags: ,

Do you want to create thumbnails for pdf files? You can simply do this with ghostscript. Here’s the php way:

  1. First install ghostscript on your server. Download: http://ghostscript.com/releases/
  2. Then write your code:

$pathToPdf = “C:\….\PdfFile.pdf”;
$pathToJpg = “C:\….\generatedThumbnail.jpg”;

$gsCall = “\”C:\….\gs\gs8.70\bin\gswin32.exe\” -q -dBATCH -dMaxBitmap=300000000 -dNOPAUSE -dSAFER -sDEVICE=jpeg -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dFirstPage=1 -dLastPage=1 -sOutputFile={0} {1} -c quit”;

$gsCall = str_replace(array(’{0}’, ‘{1}’), array($pathToJpg, $pathToPdf), $gsCall); // or use sprintf
$str = exec($gsCall, $output=array(), $returnValue);

This code will generate a jpg file with the content of the first page of the pdf file.

Ready.

Tags: ,

One Response to “Pdf thumbnails / Pdf to jpg”


  1. Jo Lagasca
    on Mai 28th, 2010
    @ 03:05

    Good share, great article, very usefull for us¡­thanks.

Leave a Reply

© 2009 Freelancer Martin Zeller. All Rights Reserved.

This blog is powered by Wordpress and Magatheme by Bryan Helmig.