Subscribe via RSS Feed Connect with me on LinkedIn

Embedding PDF’s into SharePoint 2010 pages

[ 28 ] March 14, 2011 |

Recently   I was asked by a client to see if you can embed a PDF into a SharePoint page. It turned out to be surprisingly easy!

I am assuming that you are using Wiki pages in your team sites in this example. Either way you have to put the embedded code into a  Content Editor Web Part for this to work. If you put the code to a standard page then SharePoint will strip out the tags and this will not work Sad smile

First you need to find the URL to the PDF that you wish to view, after that you are ready to go!

Step 1)

Add a Content Editor Web Part to the page

image

Step 2)

Click on the ‘Edit HTML Source’ button for the Content Editor Web Part (not the page)

image

Step 3)

Add the following code:

<object><embed src="FILENAME.PDF" height="850" width="850"
 type="application/pdf"></embed></object>

Where:

  • src = The URL of the file, remember to put in a server relative URL to this!
  • height = height of the rendered PDF
  • width = width of the rendered PDF

Click on Save and you should see your PDF rendered out just like the example below! By the way this book by Phil Wicklund is awesome, check it out here.

image

Tags: ,

Category: How To

About Michal Pisarek: Michal Pisarek is the founder of Dynamic Owl Consulting and a Microsoft SharePoint MVP. View author profile.

Comments (28)

Trackback URL | Comments RSS Feed

  1. [...] Embedding PDF’s into SharePoint 2010 pages [...]

  2. Reto says:

    What is about the SharePoint 2010 Blog Sites.
    Do you have also a solution for blog entries?
    I tried, but SharePoint remove the code automatically.

  3. [...] empfiehlt HTML Code (und HTML Code generierende Java Scripts) einzubetten  z.B. durch Änderung des HTML Codes der Seite mit dem Sharepoint Editor oder mit dem Sharepoint Designer. Dabei scheint es aber viele [...]

  4. Great post. Also, if you want to do this dynamically a colleague of mine did a good article to compliment this one:

    http://www.inspiredbytechnology.com/index.php/2011/03/31/embedding-a-pdf-object-in-a-sharepoint-2010-web-part-using-c/

  5. I tried this out, it looks like it works, but once I click save Sharepoint changes the HTML code.
    Any suggestions?

  6. Hey Michael,

    Are you sure that you are adding in the content into a Content Editor Web Part? If you are doing it directly on a page then it will strip out the HTML

  7. Matt Bramer says:

    I’ve actually done something similar with DVWP’s. I created a template with will dynamically render the file directly in SharePoint. Doesn’t matter what is chosen as long as you can embed it into a web page, it’ll render. Here’s a demo: http://spdwiki.com/SitePages/DocumentDashboard.aspx?docUID=2

    and the codeplex project:
    http://spxslt.codeplex.com/discussions/235951

    Cheers,
    Matt

  8. Hey Matt!
    That is cool.
    Thanks for the comment.

  9. Kirk says:

    I am having the same problem as Michael. How do I ensure that I am editing the HTML on the Content Editor Web Part? There is no button on that web part properties.

  10. Kirk says:

    When I edit the HTML coed in the Content Editor Web Part the preview shows great, though a message says that the code “may have been modified”. When I click OK or Apply, the pdf disappears and shows a blank screen.

  11. Marcus says:

    Hi!
    Im having the same problem as the other guys. It looks good in preview but when I save I get a message that my code might have been modified and then the webpart turns grey. When I go back to look at the code it has indeed changed and now looks like this:

  12. Marcus says:

    dont think the code was posted.. wierd.. i’ll try again, this time with a dot inside the object:

    .

  13. Hey Marcus.
    Make sure that you are editing the HTML in the CEWP and not on the page that it is embedded in.

  14. Kai Weber says:

    Hi,
    Is it possible to do that thing dynamically. I want to embed pdf-documents from a list. So whenever you select a pdf-document in that list or library it will be displayed in a frame?

    Any idea?

  15. Peter says:

    Matt Bramer,

    That is a good example of displaying PDF into sharepoint page. I am looking to do the same but I like to know how to inject all that code into sharepoint page?

    I mean do i have to add data view web part and then add provided code?

    Or do i just add Content editor webpart?

    The example shows that there is a ASPX dropdown which pass parameter to display appropiate PDF (files).

    Please provide any helpful details based on your experience.

  16. Prem says:

    Great useful tip :)

  17. Zarko says:

    Hi and thanks for this great solution. I am trying to do the same with .docx files but nusuccessfully yet. Any help would be appreciated.

    Thanks in advance

  18. Renuka says:

    Hi,

    I have the same problem like Kirk and Marcus has.When I edit the HTML code in the Content Editor Web Part the preview shows great, though a message says that the code “may have been modified”. When I click OK or Apply, the pdf disappears and shows a blank screen.I’m using IE8 and sharepoint 2010.Can anyone please add the screenshot of the entire HTML code in CEWP? I’ve been trying since long time but I’m still stuck with this issue.

  19. Abe Ibrahim says:

    Your demmah is resolved – the code and (steps -1) are corrrect and works great; the (-1) is for one missing note.
    Step 1a. Before you do step 2, click in the area below the Web-Part’s name, and it will work!

    Happy Coding!

  20. Matrix says:

    Thanks. The code works great. Many sites have similar but the codes are not correct. The code above 100% works!

    To those who have blank screen problem, you may need to zoom the PDF out (because it tries to fit everything into the box, hence it’ll become very small as the file page size ratio is different). It is best you installed Adobe X reader when you are doing this. Some other PDF reader might not show the results correctly or have the handy zoom in/out feature when you mouse over the PDF display area.

  21. [...] permanently. There is another way to embed a document using a Content Editor web part too (shared here and here) but I’ve not had a chance to try that [...]

  22. Steve Roh says:

    Hi,
    This solution work perfectly with FireFox, but in IE9 I got a red cross instead of the PDF document…
    Any idea about this problem ?
    Thanks & Regards,

    Steve

  23. Taffy Lewis says:

    Steve, I also got the read cross, so looking at your post, I got it to load in firefox–so, does anyone have the answer for IE9?????

  24. Ben says:

    Worked on my IE9(32 bit)

  25. Nancy Chen says:

    Do you still need PDF Viewer in SharePoint? Foxit has built up a PDF Web Reader Solution for SharePoint and would like to recruited beta volunteer. If you are interest in this, please contact nancy_chen@foxitsoftware.com for more detailed information. Thanks.
    Foxit PDF Web Reader Plugin for SharePoint is a document library extension product of SharePoint. The installation and configuration can be done by administrators in a SharePoint environment. The end users of SharePoint system can view PDF files online with using browser and no need to install any viewer application or plug-in locally.

  26. Michael Stever says:

    This does not work with Adobe Reader XI – with protected view enabled

  27. Brad says:

    I know I’m late to the forum, but for those of you still having the same issue as Michael and Marcus, try to manually type the code in rather than using copy/paste.

  28. Angel says:

    It worked! Thank you!

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.