Results 1 to 4 of 4

Thread: automatic thumnail from a pdf file?

  1. #1
    Join Date
    Mar 2013
    r-d-l- canada

    automatic thumnail from a pdf file?


    on my site i am refering pdf file with href text. So when i click on the text, browser is opening the pdf file. Everything works perfect. But i would like to change the linking text to an image link. I mean is there any way of coding that will tell the browser to use the first page of my pdf file as the img. I dont really know how to better explain this. i mean just like in a video that are reachable via a thubnail image, this image is taken ( i presume randomly) within the video.

    thank you all


  2. #2
    Join Date
    Apr 2013
    The quality option edits a parameter in the function that creates thumbnails, and it actually works. As you can see in your own site, the thumbs on the right are just fine. The problem with the biggest thumbs on the left may be due to the fact that the original images are smaller than the thumbs themselves. Having to resize and enlarge the images, they will obviously be of worse quality - and the fact that they're not created using a photo editing program but a library on a web server explains why they look so ugly. Try using bigger images as a basis, and let me know what happens

  3. #3
    Join Date
    Mar 2011
    Considering the fact that this thread is six months old, there's little chance that the original poster will come back to see the answer or care anymore about it. But in case anyone is interested, it is relatively simple to create an image from any page of a PDF file using ImageMagick and GhostScript - both of which are generally installed on most servers. If you search on "php pdf thumbnail script" you'll find lots of choices, including my own (pardon the self-promotion).
    Rick Trethewey
    Rainbo Design

  4. #4
    Join Date
    Sep 2013
    Try It Out - Full Code:


    if (isset($_POST['submit'])){

    $pdfDirectory = "pdf/";
    $thumbDirectory = "pdfimage/";

    //get the name of the file
    $filename = basename( $_FILES['pdf']['name'], ".pdf");

    //remove all characters from the file name other than letters, numbers, hyphens and underscores
    $filename = preg_replace("/[^A-Za-z0-9_-]/", "", $filename).".pdf";

    //name the thumbnail image the same as the pdf file
    $thumb = basename($filename, ".pdf");

    if(move_uploaded_file($_FILES['pdf']['tmp_name'], $pdfDirectory.$filename)) {

    //the path to the PDF file
    $pdfWithPath = $pdfDirectory.$filename;

    //add the desired extension to the thumbnail
    $thumb = $thumb.".jpg";

    //execute imageMagick's 'convert', setting the color space to RGB and size to 200px wide
    exec("convert \"{$pdfWithPath}[0]\" -colorspace RGB -geometry 200 $thumbDirectory$thumb");

    //show the image
    echo "<p><a href=\"$pdfWithPath\"><img src=\"pdfimage/$thumb\" alt=\"\" /></a></p>";


    <form method="post" action="" enctype="multipart/form-data">
    <input type="file" name="pdf" />
    <input type="submit" name="submit" value="Upload" />

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles