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.
 






Friday, March 29, 2013

SharePoint 2013: Office Web Apps Issue - We Can't Open This Document - Resolved

I was building out my production environment and configured Office Web Apps as I have done in the past. However, I was receiving an error when attempting to preview search results:

 
 
Sorry, there was a problem and we can't open this document.

Apparently, since I was using HTTP, I needed to perform one more step on the SharePoint 2013 farm. I needed to allow OAuth via HTTP using the following commands:

$config = (Get-SPSecurityTokenServiceConfig)
$config.AllowOAuthOverHttp = $true
$config.Update()



I found this answer in a forum who received the information from here.

I did not have to do this previously when I built my stage environment but I may have been using the SharePoint 2013 Preview version. Now I am using the RTM/Released Version.

I updated my original post to include this step.

 

Monday, March 25, 2013

SharePoint 2013 Search: Fixing an Orphaned Search Component

Problem/Scenario
You previously moved a search component (e.g. Query Processing Component) to a web front end (WFE). For other issue resolutions, you needed to disconnect and then reconnect the WFE server to the SharePoint Farm. In reviewing the current Search Topology, there is an issue with the Query Processing Component:


Resolution

Run PowerShell as Administrator and load the SharePoint snap-in
(or run SharePoint 2013 Management Shell as Administrator):

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Get the Search Service Application and clone the search topology:

# Clone the active search topology
$ssa = Get-SPEnterpriseSearchServiceApplication
$active = Get-SPEnterpriseSearchTopology -SearchApplication $ssa -Active
$clone = New-SPEnterpriseSearchTopology -SearchApplication $ssa -Clone –SearchTopology $active


Issue the following to review the cloned topology:

Get-SPEnterpriseSearchComponent -SearchTopology $clone

Locate the search component (e.g. QueryProcessingComponent) entry with the missing ServerName and copy the ComponentId:


 
 
Remove the component by using the ComponentId above as the -Identity value in the following:
# Remove Orphaned Component
Remove-SPEnterpriseSearchComponent -Identity d8450c12-09a8-4aa4-b824-b709a7a852e0 -SearchTopology $clone -confirm:$false
 
 
Add a new search component component using the respective cmdlet:
# Add New Search Component
$wfe = Get-SPEnterpriseSearchServiceInstance -Identity "<<wfe name here>>"
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $clone -SearchServiceInstance $wfe
 
 
Activate the search topology:
# Activate  Search Topology
Set-SPEnterpriseSearchTopology -Identity $clone
 
 
That's it! Refresh the search service application page and life is back to good:


SharePoint 2013 Management Shell Cannot load Snap-In Issue Resolved

On a brand new production server after installing and configuring SharePoint 2013, running the SharePoint 2013 Management Shell produced an alarming error:

Add-PsSnapin : Cannot load Windows PowerShell Snap-In
Microsoft.SharePoint.PowerShell because of the following error: Unable to cast
object of type 'Microsoft.SharePoint.PowerShell.SPCmdletSnapIn' to type
'System.Management.Automation.CustomPSSnapIn'.
At C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\15\CONFIG\POWERSHELL\Registration\SharePoint.ps1:3 char:1
+ Add-PsSnapin Microsoft.SharePoint.PowerShell
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.SharePoint.PowerShell:St
   ring) [Add-PSSnapin], PSSnapInException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad
   dPSSnapinCommand


I searched the web for an answer and found some posts in forums. Essentially their answer was to rebuild the server because they installed and reinstalled software and/or upgraded the operating system. In my case, this was brand new - there was no way this was because of an upgrade or software being installed incorrectly.

After trying to repair SharePoint 2013, running the Products Configuration Wizard, uninstalling/reinstalling SharePoint 2013, removing server roles, adding server roles, etc. etc. etc., I finally took a step back and figured out the problem.

I thought this must be an issue with PowerShell and not SharePoint - it turns out it was. To resolve this issue, all you need to do is uninstall and reinstall the Windows Management Framework 3.0.

Simply open the Control Panel on your server and click on programs:

 
On the Programs screen, click View installed updates:

 
Locate Microsoft Windows Management Framework 3.0 (KB2506143), right click the entry, and select Uninstall:


 

Run through the uninstall, restarting the server if directed.

Next, open browser and navigate to the WMF 3.0 download in the Microsoft Download Center. Download and reinstall Windows6.1-KB2506143-x64.msu:



Restart the server if directed. Run SharePoint 2013 Management Shell and the issue is resolved!!!


Friday, March 22, 2013

SharePoint 2013 Search: Error Adding New Search Navigation Link

Search navigation links are the main links within your search center and link to respective search result pages:


You configure these links within the Search Settings page of the site:

 
 
 You can create a new link simply by clicking on the Add Link... link:

Enter at least a Title and URL and click OK.

 
This is pretty simple. I added a few new links but when I clicked on the OK on the settings page, something went wrong:
 
 

 
I could not understand why I was getting the error for a few minutes. The reason is because, apparently, there are some rules behind the link that you provide in the URL of the navigation link:
 
a) the page must actually exist and
b) it must have at least one major version.


Once I actually created my results pages, checked them in, and published a major version, everything worked. So much for trying to put in place holders.



 

Matched Content