h3nryk Posted February 2, 2010 Share Posted February 2, 2010 (edited) Hi, The Problem: I want to show a preview or the whole PDF content in image form. I've found this in web: (link) Requirements:The following applications need to be installed on the server you are running your webserver. - ImageMagick - GhostScript The CodeTo create the images of the PDF we call the external ImageMagick application from the command line. In PHP this is done like so: 1. <?php 2. exec(‘command line to run’); 3. ?> So to run ImageMagick from the command line we do: 1. <?php 2. exec(‘/path/to/imagemagick’); 3. ?> The paramters we then use to call ImageMagick depend on what we want to do, and consulting the ImageMagick help pages are the best way to learn exactly what is happening. Below are some common examples: Create GIF Thumbnail of First PDF Page 1. <?php 2. //the path to the PDF file 3. $strPDF = "my_pdf.pdf"; 4. 5. exec("convert \"{$strPDF}[0]\" -colorspace RGB -geometry 200 \"output.gif\""); 6. ?> Create JPEG Thumbnails of ALL Pages Within PDF 1. <?php 2. //the path to the PDF file 3. $strPDF = "my_pdf.pdf"; 4. 5. exec("convert \"{$strPDF}\" -colorspace RGB -geometry 200 \"output.jpg\""); 6. ?> Create Large PNG 1024px Image of First PDF Page 1. <?php 2. //the path to the PDF file 3. $strPDF = "my_pdf.pdf"; 4. 5. exec("convert \"{$strPDF}[0]\" -colorspace RGB -geometry 1024 \"output.png\""); 6. ?> Create Large PNG 1024px Images of ALL Pages Within PDF 1. <?php 2. //the path to the PDF file 3. $strPDF = "my_pdf.pdf"; 4. 5. exec("convert \"{$strPDF}\" -colorspace RGB -geometry 1024 \"output.png\""); 6. ?> As you can see the code is very simple as we are just calling an external command line application to do the hard work – the only thing we have to do is provide the parameters to tell ImageMagick what to do. I just don't understand few things.. Questions: How to instal: ImageMagick and GhostScript using CPanel or FTP ? Can I do do this myself or need to ask server support ? Where to install, how ??? Instead of product image I want to show PDF file preview - one or more pages of ebook, how to do it ?How to use the code ? 1. <?php 2. exec(‘/path/to/imagemagick’); 3. ?> 1. <?php 2. //the path to the PDF file 3. $strPDF = "my_pdf.pdf"; 4. 5. exec("convert \"{$strPDF}[0]\" -colorspace RGB -geometry 200 \"output.jpg\""); 6. ?> Edited February 2, 2010 by h3nryk Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.