SharePoint 2010 and PDF Integration Series – Part 1

Posted by on March 9, 2011 in Blog Posts

Today I would like to start an article series on integration between SharePoint 2010 and PDF technologies. SharePoint becomes a fastest growing application Microsoft has. In the same time PDF documents become an industry standard long time ago. However, integration between these two technologies causes a lot of confusion and misperceptions.

The first area of interest is out of the box support of PDFs and related common issues.

Out of the box support

PDF documents are no different than any other documents users can store in SharePoint Document Libraries:

  • Standard Check-In/Check-out functionality is present (although it was not integrated till Adobe Acrobat X).
  • SharePoint document properties (SharePoint columns) are not mapped to PDF document in default configurations.
  • PDF document can be opened right form SharePoint. Although sometimes it can lead to undesired behavior described below

In the same time, there are many things that are either limited or not supported at all:

  • Default configuration of SharePoint 2010 does not consider PDF documents safe for displaying in the browser.
  • Support of Adobe PDF forms when PDF fields are mapped to SharePoint columns (3rd party solution is provided by SP Zap and you can learn more about this product right on this website)
  • Integrated security when SharePoint 2010 permissions could define what user can do with PDF document (like editing, annotating, etc).
  • SharePoint 2010 Search does not support content crawling by default (we will discuss iFilters and how to apply them and compare to FAST search capabilities)
  • Integration is cumbersome between SharePoint 2010 workflow and Adobe LiveCycle ES2.5 workflow.

I will review many workarounds and solutions how to address the above mentioned limitations in next posts. Right now we will start with a simple question:

Question: Why does SharePoint 2010 asks me to save PDF file when I am trying to open it?

If you have a default SharePoint 2010 setup you would notice that when you go to open a PDF file SharePoint prompts you to save it rather than opening.

This behavior can be very annoying for end users. The bigger concern is that such behavior promotes saving files on local computer even if document is designed for view only.

The cause of this behavior is SharePoint 2010 Browser File Handling. This property is on SharePoint Web Application level and its value determines how files are treated in the browser. “Strict” specifies that MIME content types which are not listed in “AllowedInlineDownloadedMimeTypes” are forced to be downloaded. “Permissive” specifies that the HTML and other content types which might contain script are allowed to be displayed directly in the browser. Source: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.browserfilehandling.aspx

“AllowedInlineDownloadedMimeTypes” is a collection of MIME types. This list of MIME types does not contain MIME type of PDF documents by default. It is important to understand that by adding PDF MIME type to IIS settings you will not solve this issue.

Solution #1 (via User Interface):

The solution is to change Browser File Handling property on Web Application level. For that you need to be a Farm Administrator. Steps to change Browser File Handling property:

  • Go to SharePoint 2010 Central Administration > Application Management > Manage Web Applications
  • Select the row of your web application
  • Click General Settings in the ribbon
  • Scroll down to Browser File Handling and select Permissive
  • Click Ok

Now, your PDF document will be opened in the browser.

By default, option is set to Strict when creating a web application. When set to Strict, a PDF document (and other file types) can only be Saved (downloaded), but in Permissive mode, the PDF document can be opened in the browser by default (this is a setting you can change. See Document Library Settings -> Open in the Client).

Limitation #1:

Once you enabled “Permissive” Browser File Handling, SharePoint will allow all documents be opened in the browser. Today, there is no “out-of-the-box” option to allow Permissive option for PDF documents only.

Everything else below is quiet technical and you can skip it if you are not SharePoint developer. If you are a SharePoint developer, then you should check Solution #2.

Update 3/10/11: Added PowerShell option to solution #2. (see below).

Workaround to limitation #1: If you are up to a coding challenge you can develop a Virtual Path provider that catches all PDF files requests and stream content. In this case you can adjust Browser Strict/Permission settings on the fly.

Technical note #1:

SPList class contains property BrowserFileHandling as well. According to MSDN (Source: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.browserfilehandling.aspx), this is a list level override of WebApplication’s BrowserFileHandling property.

…If this setting is BrowserFileHandling.Strict then files inside this list are handled in a strict fashion even if the SPWebApplication setting is BrowserFileHandling.Permissive. However if the site setting (in SPWebApplication.BrowserFileHandling) is BrowserFileHandling.Strict then this (the list) setting is ignored.

The above-mentioned quote means that even if SPWebApplication.BrowserFileHandling is Permissive, you can programmatically (no UI) overwrite list level BrowserFileHandling property to be Strict. Unfortunately, it does not work in reverse: list-level property cannot overwrite WebApplication setting “Strict”.

Solution #2 (programmatically):

As I stated above if WebApplication property is set to “Strict” then only MIME types in “AllowedInlineDownloadedMimeTypes” are allowed to be rendered in the browser. So, why not to change this “AllowedInlineDownloadedMimeTypes” property? Answer is: “Yes, we can”. The following code adds PDF MIME type to “AllowedInlineDownloadedMimeTypes” property. Note that code shall run in context of user who is Farm Administrator.
Otherwise SPWebApplication.AllowedInlineDownloadedMimeTypes is a read only collection.

The reason we can add PDF document MIME type is that underlying variable of WebApplication object is persisted.

const string pdfMimeType = "application/pdf";
SPWebApplication webApp =SPContext.Current.Site.WebApplication;
if (!webApp.AllowedInlineDownloadedMimeTypes.Contains(pdfMimeType))
{
  webApp.AllowedInlineDownloadedMimeTypes.Add(pdfMimeType);
  webApp.Update();
}

After you run the above code (of course, you can obtain SPWebApplication in some other manner than from SPContext), your PDF documents will be displayed in the browser even if SPWebApplication.BrowserFileHandling is set to Strict.

Solution #2 (PowerShell):

The solution of updating “AllowedInlineDownloadedMimeTypes” can also be done using PowerShell.

$webApp = Get-SPWebApplication http://intranet.domain
If ($webApp.AllowedInlineDownloadedMimeTypes -notcontains "application/pdf")
{
  Write-Host -ForegroundColor White "Adding PDF MIME Type..."
  $webApp.AllowedInlineDownloadedMimeTypes.Add("application/pdf")
  $webApp.Update()
  Write-Host -ForegroundColor White "Added and saved."
} Else {
  Write-Host -ForegroundColor White "PDF MIME type is already added."
}

Here is a screenshot of what you should see if you run this PowerShell script:

Interestingly enough…

SPBrowserFileHandling is a core classes in SharePoint 2010 that addresses the above described behavior in programmatic terms (link: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbrowserfilehandling.aspx).
You can use BrowserFileHandling property of SPWebApplication to change options. While this is all trivial, I found another reference for SPBrowserFileHandling on MSDN (link: http://msdn.microsoft.com/en-us/library/ff386949(v=office.12).aspx ).
It looks like SPBrowserFileHandling can be also an attribute in Manifest.xml. It triggers an interesting thought: what if a custom solution can use this attribute to define BrowserFileHandling property on a file level.

Next topic:

In next topic about SharePoint 2010 and PDF, I will review new features of Adobe Acrobat X and SharePoint 2010. Stay tuned.

81 Comments

  1. “Your script causes a “You cannot call a method on a null-valued expression” error on line 5, char 47 of your code.

    • You need to edit the first line by adding your site. I did the same thing.

      • I had problems with the first line of the script presumably because my Powershell window was defaulting to the wrong farm solution or something.

        Basically, I got an error such as :
        Get-SPWebApplication : Cannot find an SPWebApplication object with Name, Id, or Url: http://………..

        I got around this by rewriting the script as follows:

        [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
        $webapp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup(“http://intranet.domain”)
        If ($webApp.AllowedInlineDownloadedMimeTypes -notcontains “application/pdf”)
        {
        Write-Host -ForegroundColor White “Adding Pdf MIME Type…”
        $webApp.AllowedInlineDownloadedMimeTypes.Add(“application/pdf”)
        $webApp.Update()
        Write-Host -ForegroundColor White “Added and saved.”
        } Else {
        Write-Host -ForegroundColor White “Pdf MIME type is already added.”
        }

  2. Thanks for this. Works like a charm. I’ve always had clients turn off strict browsing but never liked it. Now I don’t have to.

    • Hi Paul,

      I am stuck….
      I am hoping that you may be able to answere some questions.

      Any thoughts on Managed Metadata columns in document library for older versions of PDFs?

      Do you know if the installation of the iFilter on the server that hosts our SharePoint 2010 site be able to perform a content crawl on older PDF documents without any .Net code?

      If no, do you have any suggestions on how to programmatically create a searchable PDF from an older version of PDF documents?

      Will the “out of the box“`FAST Search capabilities in SharePoint 2010 work with my older PDF docs, or do I have to do it programmatically?

      I greatly appreciate any input,

      Reg

  3. Thanks for sharing this trick and it works perfectly. The issue is always there when they initially set up the web application then left the browser file handling as strict.

    Thanks again for posting this tips and please keep up with the good work.

  4. i used the powershell command, it is working if access the webapp using machine name (http://server/doc/abc.pdf) but if use proper website name (http://portal.com) it still ask me to save it. i used the proper name in powershell and it is also set as Default in URL access mapping.

    what is the solution

  5. Nice :)
    Thanks for this one!

  6. This post contains a lot of the common issues that SharePoint professionals will run into when utilizing pdf docs on the SharePoint 2010 platform. Thanks for taking the time to compile these issues.

  7. solution of PowerShell script Activate the property of open PDF just in firfox browser. but google chroom and IE NOT WORK :( any Help????

    • At least IE should work fine. Try to clean the browser cache, close the browser, and force-reload the page after your changes.

    • @ ZAID I know this is an old thread, but I’m having this same issue. Any resolution? I tried the delete IE cache option as someone else suggested but that doesn’t work.

  8. Dmitry, you sir, are the man! Thanks for sharing this!

  9. In the article, you mentioned the issue regarding the view only mode in SharePoint which still allows PDF documents to be saved locally. The View Only mode should not allow downloads of any document and I was wondering if you had a solution for that. Thanks in advance.

  10. This powershell script is dead on.. solved the problem we were having that setting the general options and editing the xml file didn’t fix. Thanks!

  11. Thanks this works for pdf files.
    I also want this to work for .msg (email) files.
    I tried adding mime types: application/msoutlook and application/vnd.ms-outlook but it doens’t work.
    Any ideas?

    • I tried this mime type for .msg and it works: application/octet-stream

      • Worked for me also. “application/octet-stream” is the way to go.
        Great thanks!

    • another option for the .eml mime type is message/rfc822. We went with that, it works like a champ.. this script has now saved us twice.

  12. Very well written. Thank you for taking the time!

  13. This is a very good and working solution. You’re great Dmitry!

  14. Solution #2 worked great for me. Thank you very much.

  15. could this same idea be used to disable SharePoint’s default behavior of attempting to open xslx files in the xlviewer.aspx page? If you don’t run Excel Services on the web app, this page will still attempt to open these files, even though it needs the services to work. Setting default behavior at web app/site collection/etc to use client application will not defeat it attempting to use the xlviewer.aspx page when SharePoint knows they either have view rights or doesn’t believe they have an application that can open the file.

  16. Worked perfectly. Thanks for an alternative to allowing all doc types permissive.

  17. Great solution! Thanks, I was pulling out my hair.

  18. Solution #1 only works for top-level site for us but #2 works perfectly for every sites. Thank you for your help.

  19. The script runs great. I tried it on my dev environment and now on prod. I have one small issue. At least I hope it’s small. When I open a pdf I now get: How would you like to open this file? With the options of read or edit. It didnt do this in my dev environment so what am I missing? Can anyone help me? I just want the file to open in read mode in the browser.

    Thanks

  20. Does this work with Sharepoint Online in O365?

  21. I am trying to do the solution #2 for html and html files. I used the “text/htm” but that does not seem to work. I did the same for PDF and it works like a charm. Thanks in advance.

    • I changed the mime type to “text/html” and it works.

      Thanks

  22. I’d thought this was always the way SharePoint worked until I saw one of your answers on StackOverflow.

    Great job and thank you for sharing the PowerShell scrip, works perfectly and my users are now suitably impressed.

    Niall

    • Niall, you are very welcome.

  23. I made small project in Visual Studio with Solution #2 (programmatically).
    Then I deploy this project to Sharepoint and start it as Administrator (this account have Farm Administrator privilge). Why I recive Exception “Access Denied” in catch ?

    • Send me your error (stack) and I will see if I can help.

  24. Thank you Dmitry!

  25. Thanks for sharing this tips!It’s work good for me!

  26. Thank you for posting the Browser File Handling permissive setting for opening PDF’s.

  27. Maybe someone has run into this issue. All our computers are running adobe x. We have sharepoint foundation 2010. When using the edit in adobe menu or just clicking the link for the file, some pdfs let you check them out and give you the sharepoint server checkin menu as anticipated. The problem is the majority of our forms sharepoint says “This document is part of a workflow” and make you save locally without the sharepoint server menu to check back in. These forms are not part of a workflow and we even went so far as to turn off workflows but still the same message. Any ideas?

    • This PDF document is a XFA document (dynamic PDF form). Inside form definition (XML) there should be a reference to Adobe Workflow. Remove the reference in XML Source view and it should fix your error.

  28. pefecto …just follow the steps blindly !…super wow

  29. You rock! Keep up the great work.

  30. I am experiencing different behavior with PDFs in different libraries within the same site collection (and therefore the same web app). In one library, clicking on the PDF displays the dialog box with Open and Save as options and in the other library, we only see the Save option. Any idea why this would happen or how to fix? Browser file handling is set to Permissive for this web app.
    thanks

    • Hi Dean:

      You also should check what options you have in your Document Library. Please compare settings (Document Library Settings -> Advanced Settings -> Open Documents in the Browser). Let us know.

      Good luck
      Dmitry

  31. You fixed our issue — the GUI settings simply did not work for HTML, but the Powershell code worked perfectly!

  32. THX!!

  33. Script #2 worked fine on my root web app. However, I have several other web ap p urls that contain a port #, like http://webapp:5000, and the powershell command doesn’t run. Any workarounds, fixes for that?

  34. Is there a way to undo this script? I came across a situation where I need the PDF to open via the local client. All PDF’s only open in browser since running this script.

  35. I owe your a large beer for this one! Thanks a lot :-)

    • I am glad my article helped you.

  36. I can’t seem to get this script to work. I’m an end user and don’t understand a whole lot of this. We have SBS 2011 so our sharepoint 2010 is using a the default intranet.domain but changing it to our companyweb address I keep getting the same error. I tried using Rob’s rewritten script and I get the following after “Adding PDF MIME type”

    You cannot call a method on a null-valued expression
    At line:4 char:45
    + $webapp.AllowedinlinedownloadedMIMEtypes.add <<<< ("application/pdf")

    then the same thing for:
    At line:5 char:15
    + $webapp.Update <<<< ()

    Any ideas? All I'm doing is copying the script Rob rewrote and hitting enter. The main script won't work either no matter what I put in for the intranet.domain.

    Thanks in advance

    • Just check that $webApp is not null. Usually it means that you didn’t acquire SharePoint web application correctly.

  37. Great write up!

    solution 1 worked for me only for main site, its subsites did not work.
    solution 2 work for all sub sites

    Many thanks Dmitry

  38. LOVE YOU

  39. May blessings beyond measure be heaped upon you for this information, particularly for Solution #2!

  40. You’re the man of the day …month …year ;-)
    Thank you!

  41. Nice work!PowerShell script worked perfectly.

  42. Will the installation of the iFilter on the server that hosts our SharePoint 2010 site be able to perform a content crawl on older PDF documents without any .Net code?

    If yes, do you have any suggestions on how to programmatically create a searchable PDF from an older version of PDF documents?

    Will the “out of the box“`FAST Search capabilities in SharePoint 2010 work with my older PDF docs, or do I have to do it programmatically?

  43. I have run into a problem integrating a PDF form (Enabled Extended Attributes in Adobe Pro X) and SharePoint when there are digital signatures on the form.

    Symptom: User opens form, signs and fills out som data in the form. Checks form into SharePoint using the File -> SharePoint Server -> Check-In menu selection.
    Result: Seemingly at random (not all the time) the form is no longer editable, all form fields have been removed, along with the data that was in them.

    After a long and painful process where I watched users fill out forms over and over again I discovered what the problem was. Some users filled out the form and then signed. Some users sometimes signed the form and then filled in the fields. In the later instance, the checkin strips extended features from the form.

    Just putting this out here in hopes that Google may save some other poor IT soul the pain of watching people fill out a thousand forms to see why 50 of them didn’t work.

  44. Thanks for this Share, i faced this problem recently and that solved my issue.

  45. If you desire to improve your know-how only keep visiting this website
    and be updated with the most recent information posted here.

  46. Thanks Solution 1 works great… :)

  47. Incredible points. Sound arguments. Keep up the great spirit.

  48. Is there any way to stop Internet Explorer from prompting to save across the entire network?

  49. Hi,
    Does this script work on the Office 365 SharePoint sites, and if so can you maybe provide clearer instructions as to how the script would be run?
    Thanks,
    Ken

  50. Thanks a lot Dmitry, the Powershell script worked like a charm!
    I do have some points and questions though for you or the readers:

    1) this desired functionality was already working via the Web Filetype= Permiissive setting in Central Admin. At first I thought it was an IE 9 or general browser change issue, however I checked with my colleagues and they were having the same issue. So what do you think changed???

    2) Since I am now able to set the Permissive setting back to Strict (and did so), is there still a security hole with PDF’s?

    • Clarifying my statement/question #1 above:
      The functionality to open PDF’s WAS working prior with Permissive setting, but did break RECENTLY, prompting me to fix it again.

  51. Hi,

    I try the second solution and it work fine but only on one servers of front-end server the other servers didn’t work on it so now when user open the sharepoint site using first server it work fine but when he open site using second server it didn’t work and only save option available for him when open PDF file

  52. Great post thanks – the Powershell script worked well for me (after I removed the -ForegroundColor White part – my PS editor is white on black so that attribute hid all the messages! :-)). it’s better than setting Permissive for the whole web application.

    • I meant black on white of course

  53. Very nicely explained. This is what exactly needed for me currently. Thanks

  54. DIMITRY – How do you apply these settings via Powershell for other document types – Ie .doc, .docx, .xls, .xlsx, etc

    • Yes it is possible. You just need to specify an appropriate mime type for file types .doc, .docx, etc.

  55. Hi ,

    Nice Article and impressive explanation to it but I have something opposite to this issue , I need that pop up box asking for save/cancel similar to the pdf one for docx and xslx files. At first when i login to my site and click on any attached doc present in Document Library i get pop up for open/save/cancel but only once when i open any doc once it never shows that pop up again for any of the docs in library.

    Should i try to remove MIME types of docx and xlsx from “AllowedInlineDownloadedMimeTypes” ?
    Or there is any other setting needs to be done?

    Regards,
    Prakriti

  56. My users are currently using Sharepoint 2010 and Internet Explorer 9. Now when opening PDF fiel using Adobe 11 and higher, they are getting the prompt ‘Check Out and Open’, “Open’ and ‘Cancel’. Also, we want all the files to be opened in new windows in Adobe and not open it in Browser. Is there any way we can disable this promt and just Open when clicked on the PDF file directly? Users accidently hit enter and as ‘Check Out and Open’ is the first option, the document is checked out and they dont check it in as there is no prompt for them to check in. Please help.

  57. thanks a lot…it worked like a charm/…

    • This scripted worked perfect for the users in my office with Adobe Reader but user with Adobe Acrobat or other pdf editors are still promptedto save? Do you know why and how to get around this?

  58. Brilliant! PowerShell script worked perfectly.
    Thank you for the article.

  59. Hey, thanks for the information! But could you make your code a bit more copy and paste friendly? No line numbers and such.

    1

    $webApp = Get-SPWebApplication http://intranet.domain

    2

    If ($webApp.AllowedInlineDownloadedMimeTypes -notcontains “application/pdf”)

    3

    {

    4

    Write-Host -ForegroundColor White “Adding PDF MIME Type…”

    5

    $webApp.AllowedInlineDownloadedMimeTypes.Add(“application/pdf”)

    6

    $webApp.Update()

    7

    Write-Host -ForegroundColor White “Added and saved.”

    8

    } Else {

    9

    Write-Host -ForegroundColor White “PDF MIME type is already added.”

    10

    }

    That’s what happens.

    • Hi Chuck. Place mouse over the block with a code and hold it still. Context menu will appear at the upper right corner of the block. There is a button “source code”. You can copy and paste it easily without line numbers!

  60. So, I followed solution 2. This worked for a different MIME type, but is not helping me with our PDF problem.
    In our case, the PDF file opens as needed if one goes to a SP 2010 doc library and clicks on the doc name.
    However, if one performs a search for documents and then clicks on the doc name, the only thing one gets is a prompt to save the pdf – no attempt to display the pdf occurs.

Trackbacks/Pingbacks

  1. PDF Security in SharePoint 2010 – JB's Just Sayin' - [...] setting an ‘Inline Download’ exclusion just for PDF files. There’s a good post at pdfsharepoint.com by Dmitry that covers …
  2. Document Library Prompts to Save PDF Although Web Application Set to Permissive « Just Enough SharePoint to be Dangerous - [...] the PDF file type to the list of exceptions to the strict file handling setting, as described here: http://www.pdfsharepoint.com/sharepoint-2010-and-pdf-integration-series-part-1/ …
  3. SharePoint 2010 and opening PDF files issue | Jamzar - [...] I want to thank Dmitry for posting this originally. His URL is http://www.pdfsharepoint.com/sharepoint-2010-and-pdf-integration-series-part-1/ [...]
  4. Dealing with Flash Modules in SharePoint | SoftArtisans, Blogged - [...] if you want to make a MIME type exception (allow a single type of file through) follow these steps: …
  5. PDFs and SharePoint 2010 integration using Acrobat/Reader X | Anjan's Blah...blahh - [...] Here is an article from pdfsharepoint.com. [...]

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>