PassMark Logo
Home » Forum


No announcement yet.

PDF preview

  • Filter
  • Time
  • Show
Clear All
new posts

  • PDF preview

    Zoom search result page can show images. If Zoom find a PDF as a result, it can show the image preview of the first age of the PDF. The PHP code to do it is like this:
    PHP Code:
    $im = new imagick('file.pdf[0]'); //zero is the first page of the PDF
    header('Content-Type: image/jpeg');
    Can you help me to insert it in search.php page? (versions 6 and 7)

  • #2
    Won't this make the page load very very slow? If a set of search results had 10 search PDF results then.
    1) 10 PDF files will need to read from disk.
    2) 10 PDF files will need to be rendered in series (one at a time)
    3) All the presumably hi-res JPG files will need to be downloaded to the client browser. (and the browser will need to resize them down to thumbnails).

    This all this work would need to be repeated for every search done.

    Your code isn't even close t being complete. For example you can't set the header to be JPG if the images are embedded in the page.

    A better approach would be pre-generate thumbnail images (just once) of the correct size for each PDF and place the thumb into sub-folder. Your code snippet could also be the starting point for doing this. Then just serve the pre-made thumbs using existing functionality in Zoom.

    But another potential problem is that the thumb would be too small to view any details in the PDF file. So maybe you can just use a fixed icon for all PDFs instead of an unreadable thumb?


    • #3
      Dear David,
      our website contains more than 12'000 PDF files, continuing changing. So we can't make previews everytime Zoom search update the database.
      However a we could find a different approach: we could use the thumb folder and a script that generate previews only if the requested image is not in the thumb folder.
      So, if I change the Zoom file prefix for thumbnails from "th_" to "generate_image.php?image=", could it work?
      Unfortunately I need to know the absolute path of the PDF.
      Could you write me some hints about where I should make changes?


      • #4
        Yes, this would be better, but why create thumbnails as part of the search process at all?

        Surely you could write a PHP script that does this in advance.

        1) Lists the PDF files in the folder, scandir()
        2) For each PDF file, generate the thumb path and check if thumb already exists, file_exists()
        3) If thumb file doesn't existing, then create it (using code similar to your original post)
        4) Resize image to correct size for serving via search results.

        Then use Crontab to schedule the PHP file to run each night (or each week).

        There are lots of examples on the web. Here is an example of an example