Do you want to create thumbnails for pdf files with PHP (or C#)? You can simply do this with ghostscript. Here’s the php way (it is very easy to convert this code to C#):
- First install ghostscript on your server. Download: http://ghostscript.com/releases/
- Then write your code:
$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);[/php]
This code will generate a jpg file with the content of the first page of the pdf file.
Ready.
Comments 2
Good share, great article, very usefull for us¡thanks.
läuft ABER bei mir werden die bilder vom pdf nicht im jpeg angezeigt, wieso?
i am using convert command in php too, but the images from the pdf are not showing in my created jpg or png, why?