Tuesday, April 26, 2011

Open PDF files in browser from SharePoint 2010

By default, SharePoint 2010 doesn't allow you to open the PDF files directly in the browser, Instead it prompts a "Save" Dialog box. This is because of the Web application's general settings. We can open pdf instead save.
open pdf document browser sharepoint 2010

To Make SharePoint 2010 to Open PDF documents in browser: Go to Central Administration >> Application Management >> Select the web application >> and click on "General Settings".

Now in "General Settings" Dialogue box, set the "Browser File Handling" to "Permissive". Now you can open PDF documents in browser from SharePoint 2010.
Lets use PowerShell to instruct SharePoint open PDF not save:
#Get web application 
$WebApp = Get-SPWebApplication "http://sharepoint.crescent.com"
#Set property as Permissive
$WebApp.BrowserFileHandling = "Permissive"
#Update the changes
$WebApp.Update()

BrowserFileHandling at List/Library Level:
In some cases, BrowserFileHandling setting of a list or library may override web application setting. Here is how we can reset:

#Get the Site collection
$site = Get-SPSite("http://sharepoint.crescent.com/sites/Sales")

#Get all webs
foreach ($web in $site.AllWebs) 
  {
    write-host "Processing  $($web.Title)"
   
   #Get all lists
    foreach ($list in $web.Lists) 
      {
          #Check the browserfilehandling setting
           if($list.browserfilehandling -eq "Strict") 
            {
              Write-Host "Changing " $list.Title
              $list.browserfilehandling = "Permissive";
              $list.update();
            }
      }
   }                            

Bother this will open other security holes? use AllowedInLineDownloadedMimeTypes

SharePoint 2010 determines whether to Open the file in browser or not based on the "AllowedInlineDownloadedMimeTypes" type  property of the web application. You can add/remove File types to this property collection to control the behavior.

Get the AllowedInLineDownloadedMimeTypes:
$WebApp = Get-SPWebApplication <web-App-URL>
$WebApp.AllowedInlineDownloadedMimeTypes

Add a File Type to Allowed Inline Downloaded Mime Types:
$WebApp = Get-SPWebApplication <web-App-URL>
$WebApp.AllowedInlineDownloadedMimeTypes.Add("application/pdf" )

#For Flash files, use: 
#$webApp.AllowedInlineDownloadedMimeTypes.Add("application/x-shockwave-flash")
 
$WebApp.Update()

A bit cleaner code would be:
$webApp=Get-SPWebApplication "http://SharePoint.company.com"

If ($webApp.AllowedInlineDownloadedMimeTypes -notcontains "application/pdf")
{
  $webApp.AllowedInlineDownloadedMimeTypes.Add("application/pdf")
  $webApp.Update()
  write-host "PDF File type added"
} 
else 
{
  write-host "PDF File type already exists!"
}

Remove:
$WebApp = Get-SPWebApplication <web-App-URL>
$WebApp.AllowedInlineDownloadedMimeTypes.Remove("application/pdf")
$WebApp.Update()

Found the Remove works only for newly uploaded files after this change.

Open PDF Files in Adobe Reader application Instead of Browser:

We can open PDF in new window (in Adobe Reader's application or any client application which can handle PDF) from SharePoint. By default it opens in browser. In fact, this is based on the client settings. If you want to open PDF documents in Adobe Reader, instead of the same browser window: Open Adobe Reader, Go to: Edit >> Preferences >> Category: Internet >> Uncheck the option "Display PDF in browser ". 

However in latest version this option has been removed! So the remedy is: Disable Adobe reader add-on in browser. Here is how:
Go to Internet Explorer >> Tools >> Manage Add-ons >> Select "Adobe PDF Reader" and disable it! 
Open PDF Files in Adobe Reader Instead of Browser
Now, when you click on any PDF file, they'll be opened in Adobe Reader instead of browser.



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...