Add a PDF Thumbnail Hover Preview Column to a Document Library

I got this request from Jewell from my previous post:

Display PDF Thumbnail Preview on Hover in Search Results Web Part

“Is there away to apply this to a document library?”

Here are the steps to add a pic of a magnifying glass to a column in a Document Library.

So that when your mouse hovers, it displays the first page of the PDF inside an iFrame window.

The only down-side to having this implemented, is that as the user hovers over each PDF, it needs to download the entire PDF file to display the first page.
 

* Document Library with the PDF Preview column added

pdfs - All Documents

* On Mouse-Over

pdfs preview

Step 1: First you’ll need to create a workflow that copies the Document Name to the Title column.

Follow this post to do exactly that: http://www.knowledgegroup.no/blogg/post/2012/05/13/Add-filename-in-title-field-using-workflow.aspx

Step 2: Go to http://cssglobe.com/easiest-tooltip-and-image-preview-using-jquery/ and download the Scripts Zip file.

You’ll need the 3rd Example files uploaded to a Document Library to hold your script files.

Step 3: Open up main.js and replace the text with this modified version: PDF thumbnail script .docx or the pastebin version: http://pastebin.com/Gb5mGw1c

Step 4:  Create a html file in the same folder as your scripts and paste the following:

Don’t forget to change the paths to your script files.

<script src="/server/site/scripts/jquery.js" type="text/javascript" ></script>
 <script src="/server/site/scripts/main.js" type="text/javascript"></script>
 <style>
 #screenshot{
 position:absolute;
 border:1px solid #ccc;
 background:#333;
 padding:5px;
 display:none;
 color:#fff;
 }
 </style>
Step 5:
Add the HTML file to the source of a Content Editor Web Part in the document library that holds the PDF files.
Step 6: Add a Calculated Column in the Document Library, call it Preview and select type returned as:
Number (1,2,3…).
Add the following from here:
or from here:
="<DIV><a href='..\"&Title&".pdf' class='screenshot' rel='..\"&Title&".pdf' ><img border='0' src='/_layouts/images/MAGNIFY.GIF' alt='' style='padding-right: 5px; padding-left: 5px; vertical-align:bottom'></a></DIV>"
That’s it! Now hover over the magnifying glass image and you should see the PDF thumbnail display.
Any questions or comments, post it below. Thanks for reading.
Advertisements

12 thoughts on “Add a PDF Thumbnail Hover Preview Column to a Document Library

  1. mompie77andpanda May 26, 2017 / 9:56 pm

    Thanks for this post, the solution works great within the Document Library!

    However, how can I get this solution to work in the web part of the same Document Library? I have an end-user page where I inserted the Document Library web part and filtered it to only show the PDF docs (we also house Word, Excel, and Visio documents in the same library). The magnifying glass (i.e. Preview column) shows up and so does the hover box, but the preview doesn’t actually load like it does in the library itself. It give the standard “The web page cannot be found” error message in the hover box. Any ideas how to adapt the above solution so it also works on a Document Library web part?

    Thanks!

    • Brett May 26, 2017 / 10:50 pm

      Hi, glad to see you got it working from the Doc Library.
      If everything is loading except for the PDF, it could be the path in the calculated column needs to be adjusted?
      If I have time, I can create a test myself and see if I can get it working also.
      Let me know if you have any success.

      • mompie77andpanda May 26, 2017 / 10:57 pm

        Thanks so much for the prompt response! I did adjust the path (my first thought too!) to include the entire URL for the doc library, but that didn’t seem to resolve it.

        Please note that I am a bit of a novice with jscripts, so that may not have been the right path to point to. I am an advanced SP user, but mostly OoB functionality and some intermediate Designer experience, so it could be something an expert could identify easily. I appreciate any help you can give me!

  2. mompie77andpanda May 26, 2017 / 6:26 am

    Thanks so much for this post, it was extremely helpful! For the Doc Library I implemented this on, I need to also display a filtered view of it on a different page in a web part. The preview is not working on the web part page. So you have a fix for this?

  3. Hector Maldonado April 1, 2015 / 12:02 am

    I did and tested jquery in my list and is working, everything points where it should. however the preview does not activate, the url link works but it seems that the class=’screenshot’ is not loading for some reason.

    I added a Content Editor in the same page where the Document library is with the example where i downloaded the package and it works.

  4. Tiac June 28, 2014 / 12:08 am

    Thanks for your great post… ;o)
    I tested your solution. It worked but i just see a little bit of my document. Only a piece from the left corner.
    Do you have any advice?
    Thanks in advance.

    • Brett August 6, 2014 / 8:53 am

      It’s possible the PDF is really large and hasn’t downloaded. Or it could be the path within the calculated column.
      If you’re getting the piece of left corner, the jQuery is loading correctly.

  5. Brett April 11, 2014 / 9:31 am

    Central Admin, Web Application, General Settings, Change Security Setting from Strict to Permissive. Test again.

  6. anshu dahiya April 10, 2014 / 10:17 pm

    tried with same way.. but it downloading pdf rather than display pdf as thumbnail. after hover, it shows black image and start download pdf.

  7. Jewell November 4, 2013 / 10:57 pm

    YOU ARE AMAZING!!!! Thank you SO much!!!

  8. Andy November 4, 2013 / 10:46 pm

    thanks for this post.

    another question:
    it is possible to integrate office web app ( for .doc or .xls) using iframe in calculated columns (SharePoint 2013) ?

    • Brett November 5, 2013 / 7:02 am

      Andy, this solution is specifically designed for PDF files. The modified main.js file is only for PDF parameters. eg: #page=1&toolbar=0&scrollbar=0&navpanes=0&statusbar=0.
      I’m not familiar with SP 2013 Office Web Apps to provide a concise answer but at this stage I would have to say no it would be too complex because of the different file types involved and the limitations of the calculated column.

Post a Comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s