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

  • This post has 176 Replies |
  • I implemented this solution as directed in your link but it does not work for me. I still get the "Save ro Cancel" dialog box.

    I believe I may not have access to the javascript "sp.js" that you've embeded in the <HEAD> section of the page. Where is the /utilities directory located where this script is supposed to reside?

    Furthermore, the getDoc() procedure does not contain a parameter to indicate which document it's supposed to get.

    Can you provide further clarification?

  • OK, I figured it out. I have to use YOUR website,, to get this to work instead of MY website, http://<mywebsite>/Documents/pdf.aspx?file=http://<mywebsite>/Documents/<myfile>.pdf.

    I was hoping to be able to implement this on my site because, no offense, I'd rather have the address bar of the browser window in which the PDF opens to reflect MY website, rather than yours. It may tend to confuse my viewers.

    And again, I believe it's because I do not have access to your sp.js script. I guess I could reverse engineer it since I now believe I know how it works.

  • Howard,

    Not sure I get what you mean. I tested this with Josh a while back and it installs on your account and opens a document stored in your account with your address in the address window.

    Click "pdf test" on this page:

    Josh outlines the different approaches to public/private sites in his article. 

    Can you post an example?   |     |  Get more out of Office 365

  • Hi Howard,

    You should be able to open files on your own site.  The Site template includes the utilities document library which contains pdf.aspx and sp.js.  Everything is on your site.

    Do you see the utilities library when under 'all site content'?

    Did you upload a PDF file to the Documents Library of the new site?  What happens when you click on PDFLink?


  • Howard,


    Try this:




    pdf.aspx is in the utilities doc lib.





  • Nice Post .... Can you please share the sp.js code also .
  • Howard,

    If you please share your js code then it will be very helpful .

    I am using gdoc as below but looks like your code is something different .


    <iframe src="" style="width:600px; height:500px;" frameborder="0"></iframe>

    Thanks for this nice post .



  • Udayan,


    The code simply writes in an embed element, but has the option of using gview also.


    I updated this post with more code and details:





  • I do not have a "Utilities Library" under the "All Site Content". Under "Document Libraries" I have "Documents", "Style Library", Templates" and "Web Pages". Under "Picture Libraries" I have "Images".

    I may be able to "Create" a library, but I'm not sure which one I should create. "Web Page Library"? And even if I did create a new library and call it "Utilities", where do I get the sp.js file from to place in there?

    And yes, I did upload a PDF file to the Document library.

    Is this a limitation of the P1 Plan?

  • I tried as you suggested and got "The webpage can not be found". That is because I do not believe I have a "utilities" directory. And without a "utilities" directory I can't place the pdf.aspx file into it. Nor do I have a copy of the sp.js file to put there either.

  • Howard,


    If there was a problem with P1 plan I would think the solution would have failed to activate or the new site would have failed to create.


    Did you create a new site using the PDF Site Template?


    The site template includes a Doc Library called utilities which gets created at the subsite root.


    If you create a sub site using the template called 'Docs' then the utilties lib will be here:



    The site template also includes a library template called 'PDF Documents' that you can use the create new PDF enabled Doc Libraries.



  • Josh,

    The solution can't be activated in a P1 account. At least not in mine (but then mine is messed up and doc libraries won't even load anymore............)

    I tried the utilities template too and that throws an error.   |     |  Get more out of Office 365

  • I am new to Sharepoint so I have no idea what your talking about. I did not create a new site using the PDF Template. I guess they must have been in your "Solution" - I haven't used "Solutions' so I didn't even try to use it.

    Anyway, I had some time to look at your latest update that included the javascript and the method you used for parsing out the file name from the URL. I really think you made it alot more difficult than it needed to be. Here is the pdf.aspx file after my modifications:





         <script type="text/javascript">


            document.write("<embed type='application/pdf' width='100%' height='100%' src='/Documents/"+pdf[1]+"'/>");




    Two lines of code. If you ask me, it's a lot easier to understand.

    Placed the pdf.aspx file in the Documents Library of my website and it works just fine.

    I'm sure you had your reasons fo doing it the way you did. If you would care to enlighten us or point out any deficiencies in my solution I would be more than happy to learn someting new.

  • Sorry....Please use these lines of code instead:


           document.write("<embed type='application/pdf' width='100%' height='100%' src='"+pdf[1]+"'/>");

    This will allow you to use the absolute or relative address to the PDF document:

    http://<yoursite><pdf file> or just /Documents/<pdf file>

  • Hi Howard,

    Glad you found a solution that works for you.  I just always use the getQueryString code because it allows more than one query string.  In this case, presently there is only one query string so fewer lines is fine too.

    Yes, the file query string is relative so in your case you could supply only the 'PDFFileName.pdf'  if you want because you put the pdf.aspx in the same document library.  However, if you want to use the same pdf.aspx to view PDF files from another library, then you'll have to provide the whole url to the other file in your query string.

    That's why I put it in a separate utilities library so the file variable is alway relative to the site and there will only be one copy of PDF.aspx in case I want to make changes.

    In sharepopint a 'solution' is a set of functionality saved in a single file that can be uploaded and activated for later use on a site.  The PDF Site Template is a solution that adds a new site template to your templates gallery making it available to use when creating new sites.  When you do so, many artifacts are created in that site including the following:

    Utilities Library containing pdf.aspx and scripts

    Customized Documents Library 'PDF  Enabled'

    PDF Document Library Template (for creating new doc libs 'PDF enabled')

    New Item Workflow which sets a PDFLink column to the PDF.aspx having the correct relative file querystring

    In a nut shell this makes the PDF file display in browser by clicking on the list item nearly the same as it does when Browser File Handling is set to Permissive.

    Please let me know if you have any questions.



Page 3 of 12 (177 items) |1|2|3|4|5||»