Office 365 Open PDF files in the browser

   A very useful Post from Office Community forum
1) Step 1:Download pdf icon and name it as ICPDF.gif

2) Step 2: Copy & Paste the below script in notepad (or
any editor of your choice) and save it as javascript file. For example

    <script type="text/javascript" src=""></script>

    <script type="text/javascript">
    //The script will run after the page is loaded

    // Load the page.
    function Page_Load() {
                //setting icons
                var $pdficons = $("td[class='ms-vb-icon'] img[title$='.pdf']");

var siteCollectionUrl = document.location.protocol + "//" + + _spPageContextInfo.siteServerRelativeUrl;
                                    var pdfImgLoc = siteCollectionUrl + "/SiteAssets/scripts/ICPDF.gif";
                                    $(this).attr({src: pdfImgLoc});


                //assign javascript for the pdf files
                var $items = $('.ms-vb a[href$=".pdf"]');

var $itemURL =  document.location.protocol + "//" + + $(this).attr('href');

                                            onclick: "javascript:OpenPDF('" + $itemURL + "')",
                                            onmousedown: "return VerifyHref(this,event,'0','AdobeAcrobat.OpenDocuments','')"

            catch (e) {


        function OpenPDF(itemPath) {
           document.write("<embed id='PDF' width='100%' height='100%' src='" + itemPath +"' type='application/pdf' />");


3) Step 3:  Save and upload the jQuery file & the PDF icon file. In this example I've uploaded the files under the 'scripts' folder of 'Site Assets' library in the site collection. - "SiteCollection/Site Assets/scripts".  (Check the green shaded color in the script)

Check the screen shots on how to enable the pdf via Content Editor Webpart.

Click on 'OK' and you should see that pdf icons are populated for the PDF files and when clicked it should open in the browser.

P.S: Make sure that you have installed the latest Adobe Acrobat Reader.


Post a Comment

Popular Posts