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


Friday, March 11, 2011

Looping Workflow Through All List Items

Background
I came across this solution because I was trying to calculate the number of days an item in a list was in a specific state and to send an alert to the creator of the item after the number of days was exceeded. I started by using the “Today” trick. Although the today trick worked to find the difference between dates I still needed a way to cycle through all the list items and send an alert when the date difference exceeded. Since you cannot easily calculate the difference between two dates using [Today] I decided to use the workflow Action “Find Interval Between Dates”. I came across few postings on the web that talked about using two lists to do this but I didn’t want to use two lists so I came up with this solution.

How to Create a Looping Workflow
Create a Custom List called Looping
Create a column called DueDate

  • Type: Date and Time
Create a column called DaysUntilDue
  • Type: Number
  • Decimal Places: 0
Create a column called CountDaysUntilDue
  • Type: Choice
  • Choices: Yes and No
Create a List Workflow called Loop Through Items
  • Initiation Settings: Allow this workflow to be manually started
Set Workflow Variable
  • Workflow variable: idCurrentItem
  • Value:
  • Data source: Looping
  • Field from source: ID
  • Field: CountDaysUntilDueValue: Yes

Find Interval Between Dates
  • Difference Type: Days
  • Date: Current Date

  • Date: DueDate
  • Variable: numDaysUntilDue
Update List Item
  • Field: DaysUntilDue
  • Value: numDaysUntilDue
  • Field: CountDaysUntilDue
  • Value: No
 
Start another workflow
  • This item:
  • List: Looping
  • Field: CountDaysUntilDue
  • Value: Yes
  • This: Loop Through Items
Save and Publish the workflow
  • For each item in the list that you want the workflow to process set the CountDaysUntilDue to yes.
 
Manually start the workflow for the first item on the list.
  • It may take time to for the next workflow to change from Starting to In Progress to Complete.
 

After the workflow updates the last item on the list it returns an Error Occurred result because there is not another item on the list to execute. So in order to run the workflow again on the last item on the list you need to terminate the workflow on that item.


Notes

I’m still trying to figure out how to get the workflow to complete the last item cleanly until I figure out how to do that you need to

Related Articles