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:
$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.
Martin Zeller
Jo Lagasca
on Mai 28th, 2010
@ 03:05:
Good share, great article, very usefull for us¡thanks.