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

  • Really great job, Josh! We've tried the other script and that all works true good. Many, many thanks.


  • KKL, Ignacio, JI,

    Glad it's working. Thanks for the feedback.

    Have a great day!


  • In order to get the complete solution to work in my P1 environment, without any programming knowledge I needed to search for /utilities and replace with /teamsite/utilities in the pdf.js file. after an upload everything seasms to be working. It is also working seamless on iPad.

    Thanks for making this simple.

  • Ray,

    The script assumes you've created the utilties library on your top level site.  For P1 that is your public website.  This is so you can use the same relative url in every page on every subsite.  What you've done is fine, but the enhancements won't work on your public website pages.

    To correct this, create the utilties library on your public website.



  • Hi Josh,

    We are brand new to Office 365 and Sharepoint, and in an environment where we'd rather not have the material in the pdf files downloaded back to the local workstation once it's been uploaded to Sharepoint.  (Just seems a waste of time not to mention risky!)  I implemented your solution for the Library section and it seems to work as promised--although I do not see an Option to open PDF in browser--the familiar pdf icon and ability to view in browser work as promised.

    My challenge is how to have this functionality be duplicated for one of our calendars.  In our implementation we've gone from Public Folders to having our corporate planning calendars in Sharepoint.  However, we attach many files to our events and many are pdf's as well.  I tried adding the webcontent to the bottom of the calendar page, but that did nothing even after I modified the pathname to include /library/utilities/pdf.js.  Any help you can offer won't go to waste!

    You're a Christmas angel!



  • Hi Mary,

    The pdf.js assumes you've created the utilities at your top level site.  For P1 this is your public site I would suggest creating it there so you can resolve the file using the relative URL:


    in the Content Editor.  This should fix the Open in Browser Menu Item.

    As for PDFs attached to Calendar Events, I'd have to spend some time on that.  Which I don't see myself doing anytime soon.  If you have crafty web designers or if anyone reading this wants to give this a try, here are a few hints:


    The edit form looks like this and the attachments appear at the bottom.  It's the href of this link that needs to get changed to that of the pdf viewer page.


    Here is the source.  The href highlighted needs to get changed to:




    Something like this may work (?) Air code, I have not tested this, it porlly doesn't work, but it's close.


    <script type="text/javascript">
    //Create Array of All <a> Tags
    var a = new Array();
    var a=document.getElementsByTagName('a');

    //Loop through all tags using a for loop
    //alert (a.length);
    for (i=0; i<a.length; i++)
    //check for href attribute
    var h = a[i].href
    if (h!=null)
     //check for pdf extension
     var fileExt = h.split('.').pop().toLowerCase();
     if (fileExt == "pdf")
     //change link to use pdf viewer page
     a[i].href = "/utilities/pdf.aspx?file="+h;


    Lastly, you have to figure out where to add this code to the page.  Will it work on the Calendar.aspx or not?


    If not, it's probably easiest to add it to your custom master page using Sharepoint Designer.

    Have a great day.



  • I have implemented this solution fine the issue I have is that after adding the content editor webpart focus to the document library webpart is lost and the 'documents' & 'library' taps disappear. Is there a way to set the focus to the document library again?

  • 4114n,

    Please see the following post in this thread:

    Posted by jbooker on 2011-Oct-25 9:33 AM  


  • This is for Mary, Simon and others who've requested the ability to enable browser viewing of PDF files attached to list items from form pages.


    To do this you need to:


    1) Implement the PDF-Complete Solution here:


    2) Alter the Display and Edit forms of the respective list like so:


    Have a Great Day!



  • This is a really nice solution, but in my sharepoint, I have a lot of different document libraries in many subsites.  What a mess!  So I added the reference in my master page.  When I load the page, I'm getting this error.

    Can you help out?  I don't know anything about Java Scripting.  I have downloaded the newest version of the 3 files (dated 10/24) under the complete solution.

    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: Thu, 15 Dec 2011 11:05:47 UTC

    Message: Syntax error

    Line: 1

    Char: 1

    Code: 0


  • Sharon,

    I answered your other thread:

  • Thanks for your help mch.

    It sounds like Sharon's issue is that she has many Libraries and the masterpage option would be helpful to avoid having to add the Content Editor to every doc lib view.

    I havn't documented the masterpage option in this forum nor on my website.  To do this requires a change to the pdf.js file.

    1)  Use notepad to remove the <script></script> tags from the pdf.js file (2 of each I think)?

    2) You add this code using SPD to reference the the script in bottom of  v4.master (just after the </body> ) like this:

    <script type="text/javascript" src="/utilities/pdf.js"></script>


    Sharon, I'm guessing you need to do step 1.


    Hope that Helps,


  • Hey Josh,

    It works in the master page as you describe but it looks like you have to add it to each sub-site's v4.master file. So I guess the best option would be either make an adjusted v4.master available to every sub-site or create the libs from an adjusted template.



  • Hey Matt,

    I don't have time to test this right now, but you may be able to inherit the parent site master page by navigating to here on subsite:


    Like so:


    Can't remember if this only works for site collections with publishing feature activated(?)  If so, it's not an option for P1 subscrptions.


  • Hey,


    I applied the Office365 PDF Complete Solution on our sharepoint site. It works fine for the for the Documents Library without grouping. Some of our Doc lib grouped by categories. I have to close and expand the group twice for the java script applied to the icon and file name link. Any idea about this issue?


    Thanks John.