BusinessContinuity_0.jpg

NetConnect Blog - Your Resource For IT Tips, Tricks and News

Opening PDFs in the Browser in SharePoint Foundation 2013

Posted by Josh Nikle on May 21, 2015 3:00:00 PM

SharePoint's PDF "Support"

sharepoint_iconWith SharePoint 2013, Microsoft is finally offering native support for the PDF file format. No more add-ons or custom icons and code. However, saying it “supports” PDFs is a bit generous.

SharePoint’s default behavior is to force the user to download the file. Having hundreds of files residing on desktops all over your organization might be construed as defeating the purpose of document storage in SharePoint in the first place, so we need to fix that.

To get PDFs to open in the browser, you need to change the Browser File Handling setting to permissive. You’re half way there, but now PDFs are opening in the same window. This is obviously problematic, so you need to go one step further and edit your search center’s display template to add “target=’_blank’ ” to PDF URLs.

However, this option isn’t available in SharePoint Foundation 2013. You have no access to any display templates. And so, I fall back on my old standby: JQuery.

The basic process is…

1. Change the Browser File Handling to permissive.
2. Add JQuery to our document library to add a target to any PDF URLs.

Change the Browser File Handling setting

I should note that there are security implications in changing this setting, but to date, I haven’t found a way around it in Foundation. With that being said…

1. In SharePoint 2013 Central Administration, in the Application Management section, go to Manage Web Applications.
2. Select the application for which you want to change browser file handling.
3. In the ribbon, click on the General Settings button, then on General Settings in the dropdown.
4. Scroll near the bottom, and change the Browser File Handling setting from Strict to Permissive.

1-2

At this point, PDFs will open in the browser. However, they’re opening in the same window, so we need go one step further to make this really useful.

Make PDFs Open in a New Window with JQuery

The final step is to add a small bit of scripting to the page. Access the script by clicking here. Here’s how to add it to your library.

1. The first thing we’ll need to do is edit the attached script file with the ID of your particular library app web part.
  • Go to your library page.
  • Hit F12 to bring up your browser’s dev tools.
  • Click on the library section of the page. You’re looking for an ID in the format of “#MSOZoneCell_WebPartWPQ2”. Your web part may or may not be “2”.
  • Edit the attached file with your library app web part’s ID.
2-1
2. Upload the edited script to the library of your choice. Site Assets or Sites Styles are the common places.
  • Once uploaded, click on the ellipsis (…) next to the file. You’ll get a popup with the file’s URL. Copy it.
3. Now, go back to your library. In the ribbon, click on Page > Edit Page. Alternatively, you can click on the Settings cog > Edit Page.
4. Place a content editor web part (CEWP) at the bottom of the page and add a link to your edited script.
  • Edit the CEWP.
  • In the Content Editor section at the top of the Properties window, paste your copied URL in the Content Link field.

At this point, you should now be able to open PDFs in your browser, and in another window.

Troubleshooting

This solution is pretty short and sweet, so not much to go wrong. However, if you’re having problems with the script, there are a couple things to check.

1. Make sure you have the correct web part ID and that you edited the script before uploading. I wouldn’t mention it if I hadn’t done it before. <grins>
2. There’s a console.log line in the script. Remove the comment slashes (//) in front of it. Then refresh the page with dev tools turned on. You’ll at least be able to see if the script is returning the URLs you’re expecting.

Contact Network Center, Inc. for any questions regarding Microsoft SharePoint.

Contact Us Today!

 

Topics: Microsoft SharePoint, SharePoint Foundation 2013, SharePoint PDF Support

Subscribe to Email Updates

Recent Posts

Posts by Topic

see all