Showing posts with label PDF Preview. Show all posts
Showing posts with label PDF Preview. Show all posts

Friday, April 5, 2013

SharePoint 2013: PDF Support and Behaviors - The Whole Story


Check out the whole SharePoint 2013 Solution Series
New Titles Added Weekly!

EXECUTIVE SUMMARY

SharePoint 2013 supports PDF documents out-of-the-box. Initially, web applications do not allow opening PDFs in the browser, however, by adding PDF as an allowed MIME type, browser rendering via Adobe is achieved.

Office Web Apps server provides Office document previews and rendering in Search results without the need for client applications installed (e.g. Word, Excel, etc.). However, once SharePoint is bound to Office Web Apps, PDF documents no longer open in the browser.
There are two workarounds –





1)      Configure PDF items to render as Word Items which allows PDFs to open and preview in Search within Office Web Apps
2)      Modify the PDF Item display template which allows PDFs to render in the browser via Adobe. Modify the PDF hover template to display previews.
These workarounds take care of Search, but PDFs will still open in the client application (e.g. Adobe) from Document Libraries. The solution here is an update to Office Web Apps. The February/March 2013 Update to Office Web Apps server supports opening PDFs from document libraries within Office Web Apps.

The following table summarizes the various PDF rendering and preview behaviors:



 

Search PDF Preview

Search Open (clicking on result)

Document Library Open (clicking on Document)

Out of the Box (Strict Web App)

 

Available by modifying the Display Template

Opens in Adobe or associated client application

Opens in Adobe or associated client application

Out of the Box

(Permissive Web App or Allowed Mime Type of PDF)

Available by modifying the Display Template

Opens in web browser and search term is passed into Adobe

Web Browser

Office Web Apps Server

(October 2012 Release)

Two options:

1.       Display template (shows in Adobe web)

2.       Modify Result Type to use Word Item (shows in Word App Web)

Opens in Adobe or associated client application.


Opens in Browser with modification of display template

Opens in Adobe or associated client application.

 

Office Web Apps Server (Feb/Mar 2013 Update)

Two options:

1.       Display template (shows in Adobe web)

2.       Modify Result Type to use Word Item (shows in Word App Web)

Opens in browser using Word Web App

 

Can use templates to display in Adobe Web.

Opens in browser using Word Web App

 

If not bound to WordPDF – Opens in Adobe or associated client application.

 
 


It is also worth mentioning that if Office Web Apps is not used for Search results of PDFs, the opening of PDFs in the browser passes the search terms into Adobe and thus finds the occurrences within the document. An example of this “search term pass-through” is displayed below:











Based on my investigations and modifications, when using Office Web Apps server with SharePoint, there are two overall options when handling PDFs. One provides a more consistent user experience and the other provides the most functionality. These options are outline below:
Most Consistent User Experience
The most consistent user experience would be to use Office Web Apps server (with the update) to enable opening of PDFs from libraries in the browser and to modify the search result type to render PDFs as Word Items which enables both preview and opening of the documents from Search results within Office Web Apps.
Most Functionality
The option that provides the most functionality is to use Office Web Apps for document libraries such that PDFs are opened within the browser but then use customized search templates to preview and open PDFs from Search results thus providing the search term pass-through functionality as described above.  For the most consistent preview, use a customized copy of the Word item hover panel template (explained in the last section of this post).
The rest of this post steps through the details and explains how to accomplish the various options and behaviors.
 
OUT-OF-THE-BOX BEHAVIOR (without Office Web Apps)
 
Web Applications are created with the Browser File Handling option set to Strict. This means that only the default allowed MIME types (correlates to document types such Word, PDF, etc.) can open and display within the browser without prompting the user to Open or Save the document. PDF is not one of those default MIME types and thus, the user is prompted when attempting to open a PDF document:

 
The recommended way to enable PDFs to be opened in the browser is to add the MIME type to the allowed list of types by using PowerShell commands:

$webApplication = Get-SPWebApplication "http:/yourwebapplicationurl"
$webAppApplication.AllowedInlineDownloadedMimeTypes.Add("application/pdf")
$webApplication.Update()
Source: http://social.technet.microsoft.com/wiki/contents/articles/8073.sharepoint-2010-and-2013-browser-file-handling-deep-dive.aspx#DownloadFunctions

The other easy option, which is not recommended, is to modify your web application (via Central Admin) and change the Browser File Handling property to Permissive:




Either method will allow PDF files to be opened in the browser. A neat experience in search results is that the search term is passed into Adobe and the terms are highlighted in the document:

 












To get a PDF preview in the search results, you may follow my original idea and post.
 
 
OFFICE WEB APPS (October 2012 Release Version)

Once Office Web Apps is installed and configured, by surprise, PDF documents are no longer opening in the browser. Neither from document libraries nor from the search results. So there two options at this point (at least for the search results).

1. Follow Wictor Wilen's post to use the Word Item template for PDFs. This method both shows a preview and opens up PDF search results in the Office Web App's Word App Viewer.

2. Use my original method for creating a PDF Preview to generate the preview.
Follow these steps to allow opening of the PDF document in the browser via Adobe (maintaining the search term pass-through functionality:

Modify the Item_PDF.html in the display templates folder.
Replace this line:
            ctx.CurrentItem.csr_OpenControl = "PdfFile.OpenDocuments";

With this one:
     ctx.CurrentItem.csr_OpenApp = "word";





Problems solved, right? At this point the search is fixed but PDFs don't open from document libraries in the browser. That's where the Office Web Apps Update comes in to play!


OFFICE WEB APPS PUBLIC UPDATE (Feb/Mar 2013)

There was a cumulative and public update released in early March 2013 that adds additional support for PDFs in SharePoint 2013 using Office Web Apps server. What does this do for us??

The update adds a new application type named WordPDF. It allows PDFs to be opened from document libraries in the browser using the Word App Viewer. What about search?

For search, there is no change. You either need to copy the PDF Result Type and configure it to use the Word Item or modify the search display templates. (Same options as above).

However, I have come up with a hybrid approach that provides a consistent preview using the Word App Viewer but also provides the rendering of PDFs in the browser through Adobe with the search term pass-through!

Open SharePoint Designer and navigate to the search display templates (similar to the steps here).
Find Item_PDF.html. Right-click and select Copy:

 
Right-click again and select Paste:


This process creates a copy of the file which appears at the bottom of the list. Find the copy and rename to something different (such as Item_PDFCustom.html):

 Right-click the new file and select Edit File in Advanced Mode:


Rename the title:


Change the hoverURL:




Replace this line:
ctx.CurrentItem.csr_OpenControl = "PdfFile.OpenDocuments";

With this one:
ctx.CurrentItem.csr_OpenApp = "word";


Save the file. This handles the opening of the PDF document in the browser. Now for the preview.

Locate Item_Word_HoverPanel.html. Right-click and select copy:


Right-click and select Paste:




 
 
Rename the copied file (should be the same name you used for the hoverUrl value):
 

Right-click the new file and select Edit File in Advanced Mode:
 

 
 
Change the title:


Save the changes! Onto the Search Center!

In your Search Center, select Site Settings from the Settings menu (gear).
Under Site Collection Administration, click on Search Result Types:



 
 


Scroll down and find the PDF entry. Select Copy from the drop-down menu:

 
 

Give the type a unique name and select the PDF Customized Item as the display template:




 Click Save.

Now, the search results display previews using Office Web Apps:


And the documents open in Adobe with the search term pass-through:




CONCLUSION
There are various options and behaviors when handling PDFs in SharePoint 2013. Using Office Web Apps server somewhat forces you down a customized search experience path. The easiest and most consistent option is to have Office Web Apps handle all PDF interactions via the Word App Viewer. Providing the search term pass-through is another option but requires display template modification as explained in this post. I hope this post provided insight into this topic.
 






Tuesday, October 2, 2012

SharePoint 2013: PDF Preview in Search Results


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.

 

Matched Content