1

Question

Is it possible to view a PDF through an iframe that is stored in a SharePoint 2010 document library? If so, what changes do I need to make to the default document library settings?

Background

I want to display a PDF that is stored in a document library through an iframe. Currently this works without any issues when the PDF is stored in a _layouts sub-folder. When I store it in a document library I'm only given the option to save it locally. Below is the test HTML I used to validate this.

<html>
<body>
    Document Library: Forces user to download the document
    <iframe height="300" width="300" 
        src="http://sprocks/Shared%20Documents/test01.pdf" />

    _layouts sub-folder: Renders as expected in the iframe
    <iframe height="300" width="300" 
        src="http://sprocks/_layouts/CachedReports/test01.pdf" />
</body>
</html>
1
  • I am trying to do something similar. I was wondering if you could help me with my question. Thanks My Question
    – kds6253
    Commented May 15, 2012 at 17:55

3 Answers 3

2

For full story see SharePoint 2010 and Pdf Integration Series – Part 1

The short story either set Browser File Handling to Permissive

  • 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

Or only allow online showing of PDF

$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."
}
1

You need to change a setting for your web application in Central Administration.

  1. Go to Central Administration > Manage web applications > Your Web application
  2. Select General Settings
  3. Locate Browser File Handling
  4. Select Permissive

Here are the details as stated in Central Administration:

Specifies whether additional security headers are added to documents served to web browsers. These headers specify that a browser should show a download prompt for certain types of files (for example, .html) and to use the server's specified MIME type for other types of files.

Permissive Specifies no headers are added, which provides a more compatible user experience. Strict Adds headers that force the browser to download certain types of files. The forced download improves security for the server by disallowing the automatic execution of Web content that contributors upload.

0

Your browser should support PDF rendering within the context of the browser window. However there might other security related settings which might needs to tweaked based on the browser type. But overall, looking at the above code it should ideally render within the iframe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.