No one has responded to this discussion for at least a year, so this information may be out of date. If you're looking for information about this topic, please search for a more recent discussion or post a new question.

PDF Solution: Here's How to Display in the Browser

  • Hi John,

    I noticed the behavior you describe.  I spent a while and made some improvement, but never solved the problem completely.

    Sharepoint runs some javascript to display the contents of a group dynamically upon expanding.  My script ties into this function and fails to apply the enhancements the very first time you expand a group in the library.  After that, It works for other groups first try and works upon the second time you expand the first group.  

    It has something to do with the rows not being on the page when the script runs I think.  I just ran out of time to debug this.  If your handy with javascript maybe you can figure it out and contribute a improvement.

    The menu option generates in script every time you drop down so it's unaffected.

    Perhaps someone in the community will have the skills & time to work through this.


  • Josh - thanks so much for this solution. We have 40 site collections all with subsites and tons of libraries and Microsoft really left us to die here. At least your solution gives us a ray of light.

    One question I had that I didn't see brought up here - is there a way to edit the .js file to have the PDF open in a new window. This way we don't have to instruct users to hold down CTRL.

    Thanks again for all your efforts.

  • I think I did what you suggested, but am getting the following error (at least it's moved)


    Webpage error details

    User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; MS-RTC LM 8)

    Timestamp: Mon, 19 Dec 2011 17:09:50 UTC

    Message: 'href' is null or not an object

    Line: 113

    Char: 1

    Code: 0


    Message: 'href' is null or not an object

    Line: 113

    Char: 1

    Code: 0



    Line 113 is var c = b.href;


  • @PartlyCloudy and others who've requested opening PDFs in new window:


    Please download this file and replace your /utilities/pdf.js with this one.   I tested minimally, please test it out to see if it opens in new window as you would like.  If it works well let me know and I'll update my utilities files to benefit future folks.



    @PartlyCloudy, with a large implementation, you may find it easier to apply the script to you master pages using sharepoint designer.  This requires a change to the script.  Please read above and let me know how it goes.


    @Sharon, The error is in the code that builds the menu drop down option.  Beside the menu option, can you tell me whether the icon and file link are working?  If not what are the symptoms for those enhancements?



  • Josh - the new file worked and opens the PDFs in a new tab in IE9 both when you click the filename and when you select Open from the drop down.

    I will try applying your solution to the master pages and let you know.

    Thanks again.

  • This is AWESOME!  No script errors, Icon is showing, Drop Down is working (5 libraries deep!).  THANK YOU SO MUCH!!!!

    This little problem was stopping me from publishing and allowing people onto our Office 365 Site.  

    Josh,  I'll be visiting your site and making a nice contribution for sure!

  • I have a requirement to open .pdf file in browser in sharepoint online that is linked to another .pdf file in a seperate folder(linked with bookmarks) . This is working fine in Sharepoint 2010 when browser file handling is set to permissive. above solution works perfectly for opening .PDF files in browser, however linked .PDF files will not work.

    Are there any solutions to open linked .pdf files in browser with sharepoint online.

  • Sowjanya,

    I've never used bookmarks in PDF files before, but I assume it may work if you could alter the urls in the pdf file to use the following syntax:



  • Josh,

    I need to alter bookmarks for many pdf files and tried creating a console application that can read and alter the bookmarks. I could retrieve the pdf bookmarks using itextsharp, however didn't succed to retrieve the bookmark url that will enable me to alter with above syntax.

    Any pointers to retrieve pdf bookmark url using itextsharp will be helpful.


  • Josh - just wanted to update you and people following this thread regarding the alternative for installing in each library.

    I installed the .js reference into the v4.master file (after the body tag) for each of my sites and removed the script tags from the .js file. This worked perfectly.

    In addtion to making this easier to apply to sites with many libraries, I also found a few other advantages over applying at the library level with the content editor web part. When applying at the v4.master level, all new libraries created, regardless of template used, will contain the fix automatically. This avoids having to recreate your library templates if you have a lot of them. Also, the problem with the ribbon losing focus as described in other posts here does not happen when the fix is applied to the master page.

    Thanks again for this solution - it was a life saver.

  • PartlyCloudy,

    Thanks for the update.  Glad you got it working well using the masterpage reference.

    Have a great day!


  • @Art Smith


    This is in reply to the following comment on the wiki page which is associated to this thread.  I didn't create the wiki, so I don't get notified of comments there...just happended accross it today.


    Please use this this thread for questions instead of the wiki page.


    Wiki comment:

  • You have outlined the problem perfectly.  Of course, since the editform.aspx and dispform.aspx are both pop up windows, the pdf_forms.js doesn't run on them and they cannot be edited via sharepoint designer.  So I'm stuck.  We have tailored an "issue" list to work as an ordering platform for our company, where orders are attached to a new issue list item for processing.  Most of these are in PDF, as they are scanned, and it would greatly help our order dept to simply click on them rather than having to save/open.  I have played around in the V4.master, but have no idea where to place the .js.  I tried to emulate what PartlyCloudy had done to put the solution at a root level, but couldn't figure out where the "body tag" ended.  Bottom of the page?  Right below \body?  Can you say "end user"?  lol.  

    Anyway - your continued help on the PDF issue is greatly appreciated.

  • Hey Art,

    Glad to reach you.  Because I tried the master page thing and it had issues, I wouldn't recommend that for forms pages unless you have time/skills to work it out.

    Using Content Editor on the Forms pages will work the same as you got it to work for the calendar forms.  As in this article:

    Here are some hints....

    To get your forms to open in the browser when the list is set to display modal pop-ups you can type the url directly into the browser address:


    to get that form into edit mode so you can add the CEWP add this:


    I think that's where you're hung up.  Now you should be able to follow the steps in the above article to reference pdf_forms.js in CEWPs on both the dispform.aspx and editform.aspx for the respective list.

    It's not nessessary in this case if you use the browser edit mode described above, but you can edit forms in SPD on the list settings page under forms:

    Also FYI, you can specify whether forms open in modal dialogs in the List Settings | Advanced Settings page:

    Let us know how it goes.


  • Opening the editform.aspx in the browser to add the CEWP was the key.  Thanks so much for your help!