<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\758211560\46blogName\75Tech+Tips,+Tricks+%26+Trivia\46publishMode\75PUBLISH_MODE_BLOGSPOT\46navbarType\75BLUE\46layoutType\75CLASSIC\46searchRoot\75http://mvark.blogspot.com/search\46blogLocale\75en\46v\0752\46homepageUrl\75http://mvark.blogspot.com/\46vt\75-5147029996388199615', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Tech Tips, Tricks & Trivia

by 'Anil' Radhakrishna
A seasoned developer's little discoveries and annotated bookmarks.

Search from over a hundred HOW TO articles, Tips and Tricks


HOW TO open a PDF or Word .DOC file within the browser

I have seen this uncommon question come up on the Forums on how to make a PDF or a Word document show up within a browser rather than having that file open up in a separate window through Adobe Reader or MS Word (as the case may be). I realized while trying out Google Viewer that it can be used programmatically in your own pages to force  a .PDF or .DOC link to show up within the browser. Moreover with this technique, it does not also matter if the end user has a PDF or Word document viewer installed on his comp.

Here is how Google Viewer typically works. The URL of the .PDF or .doc file to be opened within the browser has to be passed to Google Viewer as a querystring value -
http://docs.google.com/viewer?url=http://www.hud.gov/buying/checklist.pdf

Suffixing an absolute URL of a PDF or Word document as a querystring value does the trick.

Update (4/Feb/2013): Google Docs/Drive viewer currently helps you preview over 16 different file types, so this trick can be extended to those file types as well.

Labels: ,

Tweet this | Google+ it | Share on FB

« Home | Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »
| Next »

Posted by Anonymous indra setyadi | 7/03/2010 05:16:00 AM

These means that the doc which we want to view need to be hosted on the internet? The problem is what if the doc that i want to be viewed were hosted in the intranet?

Any suggestion?    



»

Post a Comment