\n"; } $original = $pdfPath . $pdf; // Add file path to PDF file name $originalBase = basename($pdf,'.pdf'); // Extract PDF file name basename w/o extension $thumbnail = $thumbsPath . $originalBase . $extension; // Use basename for the thumbnail .jpg file name if (!file_exists($original)) { // Make sure PDF file exists $error .= "Source PDF Document Not Found
\n" . $original . "
\n"; } // Fix file name(s) to select 1st page of PDF and enquote $original if it/they contain s. if (strpos($original, ' ') !== false) { $original = "\"" . $original . "[$pageNo]\""; // Enclose file name in quotes and add Page # $thumbnail = str_replace(' ', '_', $thumbnail); // Replace s with underscores } else { $original = $original . "[$pageNo]"; // Just add Page # to PDF $original } // Check to see if the thumbnail already exists in the "cache" if (!file_exists($thumbnail)) { // No! Convert PDF to JPG with ImageMagick/GhostScript now! if ($error == '') { $wmCmd = "convert $original"; if ($thumbsize != 0) { $wmCmd .= " -resize " . $thumbsize . "x"; } $wmCmd .= " $theWMType$thumbnail"; $result = exec($wmCmd); } // endif $error == '' // A little error-checking overkill if (!file_exists($thumbnail)) { $error .= "Convert Failed! Can't find $thumbnail
\n"; $error .= $result . "
\n" . $original . "
\n" . $thumbnail . "
\n"; } // endif !file_exists } // endif !file_exists($thumbnail) if ($error != '') { // Did we see an error? header("Content-type: text/html\n"); // Yes! Send MIME-type header for HTML files echo($error); } else { header("Content-type: image/jpeg\n"); // No. OK, send MIME-type header for JPEG files echo(file_get_contents($thumbnail)); // Fetch image file contents and send it! } // endif $error exit; ?>