
Check out the whole SharePoint 2013 Solution Series
New Titles Added Weekly!
Introduction
One of the enhancements in SharePoint 2013 Enterprise Search results is the ability to preview documents using Office Web Apps Server. I am in the process of seeing what that looks like and will post an Office Web Apps server entry soon.
UPDATE: Here is the post.
Anyway, the issue is that if you have Office Web Apps configured, the only documents that show previews are Microsoft Office documents (e.g. Word, Excel, etc.). The preview of PDF documents is not implemented or supported using Office Web Apps.
Therefore, I created my own PDF preview for Enterprise Search results by customizing the new search Display Templates. This works for local site search results too which I explain at the bottom of this post.
To understand overall PDF functionality and behaviors,
read the whole story here.
Prerequisites
Here are some things you need in place before implementing this solution:
- Enterprise Search Application configured and running
- Crawled content that includes PDF documents
- Enterprise Search Center site collection
- SharePoint Designer 2013
Modifying the PDF Search Result Template
This is the main effort and is fairly easy. I found it better to modify the templates using SharePoint Designer 2013 although they are accessible through the SharePoint master page UI.
Step 1: Fire up SharePoint Designer 2013 and Open the Search Center Site
Step 2: Click on All Files from the left-hand navigation
If you attempt to get the files from the Master Pages, you will not see any items once you get to the Display Templates folders.
You will see the list of all files in the main window.
Step 3: Double-click on the _catalogs folder in the main window
This action displays the _catalogs structure under the left-hand navigation.
Expand the _catalogs folder, then the masterpage folder, and then the Display Templates folder.
Step 4: Click on the Search folder under Display Templates
The list of Search display templates is shown in the main window area.
Step 5: Right-click on Item_PDF_HoverPanel.html and select Edit File in Advanced Mode
Step 6: Paste the following code within the most inner <div>
<object data="_#= ctx.CurrentItem.Path =#_" type="application/pdf" width="500px" height="630px" >
<p>It appears you don't have a PDF plugin for this browser/device.
You can <a href="_#= ctx.CurrentItem.Path =#_">click here to
download the PDF file.</a></p>
</object>
Note: You may find it better to use the following for width and height: width="100%" height="500px"
I actually replaced the Render Header and Render Body divs with the object code.
Step 7: Save the file
When saving the file, you may get a warning about breaking from the site definition. Click OK.
What happens behind the scenes is that the HTML changes are incorporated into the javascript version of the template (Item_PDF_HoverPanel.js).
Step 8: Test results
Perform a search from your search center that produces PDF document results. Hover over the PDF document to see the preview:
Currently the object tag uses hard-coded widths and heights. It is not using any responsive design styles. Me and my designer will be working on producing a more consistent respresentation for the PDF preview.
Local Search Implementation
There is still local site search results using the OSSSearchResults.aspx. You may implement the PDF Preview for these results as well but the modification is slightly different.
You open the site in SharePoint Designer 2013 and navigate to the Display Templates in the same fashion. However, for local (non Enterprise Search sites) there are no HTML templates - only the javascript files. You may simply copy the javascript that was created in your Enterprise Search Center site collection (when you modified the HTML) or paste the following code:
,' <object data="', ctx.CurrentItem.Path ,'" type="application/pdf" width="280px" height="430px">'
,' <p>It appears you don\'t have a PDF plugin for this browser/device.'
,' No biggie... you can <a href="', ctx.CurrentItem.Path ,'">click here to'
,' download the PDF file.</a></p>'
,' </object>'
Save the file and preview the results by performing a local search in the SharePoint site.
It appears that the hover container in this case is being constrained in regards to its size. Therefore I needed to use 280px for width and 430px for height. I will be working on making this more flexible.
To see what Office Web Apps server does for previewing of documents, see this post.
For Installation steps, see this post.