Tuesday, August 14, 2012

PDF Files and SharePoint 2010

Background
SharePoint does not inherently handle PDF files as a known file type by default. Not a big deal but for a better end user experience there are a few server configurations you can apply to have SharePoint work with PDF files.

Here are things that SharePoint does not do by default with PDF files that I will talk about.
  • Search content in PDF files
  • Display an icon for PDF file types
  • Open PDF files (it forces you to save them locally)
  • Open PDF files in a new browser tab
My goal with this post is to explain how I address these issues in one spot since I often find myself searching on the web for solutions to these issues.

Search Content in PDF Files
SharePoint by default does not search the content of PDF files like it does for Microsoft Office documents. To resolve this you need to install and configure the Adobe PDF iFilter 9.
  • Download and install the Adobe PDF iFilter for 64-bit platforms here
  • Open the SharePoint Central Administration
  • Under Application Management click the Manage service applications link
  • Click the Search Service Application link
  • In left navigation menu click the File Types link
  • Click the New File Type link
  • In the File extension text box enter pdf
  • Click the OK button
  • Open the Registry Editor
  • Navigate to the following location: \\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\Search\Setup\ContentIndexCommon\Filters\Extension
  • Right Click Extension
  • Choose New->Key
  • Name the new key .pdf
  • Open the (Default) value for the .pdf extension
  • In the Value data field enter {E8978DA6-047F-4E3D-9C78-CDBE46041603}
  • Click the OK button
  • Restart the SharePoint Server Search 14 service
  • In SharePoint Central Administration perform an full crawl
Display an Icon for PDF File Types
Not a big deal but I often found it frustrating when I add a PDF file to a SharePoint document library and it does not display the icon telling me what type of file it is. To fix this you need to install add the PDF icon to the 14 hive and update the DOCICON.xml file.
  • Download the PDF icon here
  • Copy the PDF icon to the following location C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES\
  • In Windows Explorer, navigate to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML
  • Right click on the DOCICON file and choose Edit
  • In the ByExtension section add the following text <Mapping Key="pdf" Value="pdficon.gif"/>
  • Save and close the file
  • Restart IIS
Opening PDF Files
So after you install the iFilter and try to open a PDF file you get a prompt to Save the file rather than opening them from the browser. Contrary to Microsoft’s resolution to the issue this is not an education problem. It is a problem with an inconsistent UI. Microsoft Office documents do not prompt you to save them when you open them from SharePoint so why do PDF files? To fix this issue you need to adjust how the browser handles files.
  • Open the SharePoint Central Administration
  • Under Application Management click the Manage web applications link
  • In the Web Application list click the name of the web application
  • From the ribbon click the General Settings icon
  • Scroll to the Browser File Handling section
  • Select Permissive
  • Scroll down and click the OK button
Note: This changes the Browser Handling setting for the entire web application which could be a security risk. A better but more tedious way to address this is to enable permissive browser handling for the document library that needs it.
  • Open a SharePoint Management Shell window
  • Type $site = Get-SPSite(“http://mysubsitecollectionurl”)
  • Press the Enter key
  • Type $web = $site.OpenWeb()
  • Press the Enter key
  • Type $list = $web.GetList(“http://mysubsitecollectionurl/List”);
  • Press the Enter key
  • Type $list.browserfilehandling
  • Press the Enter key
  • Type $list.browserfilehandling = “Permissive” ; $list.update();
  • Press the Enter key
  • Type $list.browserfilehandling
  • Press the Enter key
Open PDF Files in a New Browser Tab
The last thing I found to improve the user experience is to open PDF files in a new tab instead of the current window. Yes I could press the ctrl key and click the link and it will open in a new tab but not every user knows that. I found many solutions that say use a content editor web part with javascript to fix the issue but the thought of adding it to every page that would needs it is maddening. An even easier way is to add the javascript to your master page.
  • Download the latest version of jQuery (I used version 1.7.2 for this example)
  • Upload the jQuery file to a document library within the site collection
  • Make sure all users have read access to the document library
  • Add the following code with your Master Page’s body tag
<script src="http:// mysubsitecollectionurl /javascript/jquery-1.7.2.min.js"type="text/javascript">
</script>

<script>
$("a[href$='.pdf']").removeAttr('onclick').attr("target","_blank");
</script>
  • Save and publish your master page
References and Related Articles


2 comments:

  1. Will this allow folks to "save as" PDFs?

    ReplyDelete
    Replies
    1. Only if you right click on the link and choose Save Target As... Otherwise clicking on the link will open the document in a new tab.

      Delete