— update 30th November 2012 —
I always love it when someone points out a simpler solution to a question or problem. Jake added a comment having discovered that using the Page Viewer web part to point to the URL of the PDF file achieves the same result. An option I’d forgotten all about and arguably a cleaner and simpler approach:
- Add the Page Viewer web part to the page.
- Copy the shortcut to the PDF as outlined below, and paste into the web part properties
- Configure the usual web part properties to control width, height etc. as appropriate
- Done! No fiddling about with source code to get the HTML to behave as you want
— original —
This question cropped up a couple of times in the comments to the Adobe PDF Indexing blog post
How do you open a PDF in a web page on SharePoint?
Here is the method I use. There may be prettier and better ways to do it. If you know of one, please add a comment.
The short version:
- Take one Content Editor web part
- Enter <embed> tags containing the PDF fie as the source
The longer version:
- Upload the PDF you want to display to a SharePoint library. From within the library, right click the PDF file name and select ‘Copy Shortcut’ (this takes a copy of the full URL to the file)
- Add a ‘Content Editor’ web part to a SharePoint web page.
- If you’re using SharePoint 2007, it’s in the Miscellaneous group in the web part gallery
- If you’re using SharePoint 2010, it’s in the Media and Content group in the web part ribbon
- Edit the web part to insert your code
- Insert the code
- Click CTRL + V to paste the shortcut to the PDF file
- Then add the following code, using your shortcut in place of FILENAME.PDF
<object><embed src="FILENAME.PDF" height="600" width="600" type="application/pdf"></embed></object>
Here’s an example:
- Click OK/Save to save the code and then OK to save the web part
- You should now see your PDF file displayed in the web part. If required, adjust the height and width values until the PDF is displayed how you want it (preferably one full page in view). In SharePoint 2010, the code may have been modified a little – don’t panic.
- Save and publish your page (or Stop Editing, depending on what site template and version of SharePoint you are using)
Hey presto: One PDF document viewed inside a SharePoint web page. Cue free advertising for the last PDF that arrived onto my computer
You must use the Content Editor web part for this task. If you try adding <embed> tags to a standard page control (for embedded content within the page), SharePoint will remove the tags when the page is saved and your hard work will disappear. If you’re running SharePoint with extra strong mints security, you may also find the <embed> tags are stripped out when attempting to save your work.
People will still need a PDF reader installed on their client in order to view the PDF embedded in the web page, just the same as when visiting any other web site with embedded PDFs.
Update 30th Apr 2012: Beware the dreaded 64-bit edition of IE. I’ve seen it cause challenges with various different software and web site features. Add this one to the list – more details kindly shared by Terri in the comments.