Open PDF files Dynamically in Content Editor Webpart

Problem:

Load dynamic pdf file through page viewer or content editor wepart

Solution:

Basically, if you had more than one pdf to view; it is not that easy to insert a pdf file onto a SharePoint page (through page viewer Webpart).  To fix this, I used a query string and a small java script to dynamically load the pdf on my page.

You have to first create a url.  It consists of the url of the pdf documentl.

Example:

http://<Server>/<Site Collection>/site/pages/<YourPage>.aspx?pdfurl=/sites/demojoseph/Lists/List Read Attach/Attachments/1/jebaticket.pdf

Add the following code in the source of a Content Editor Webpart

The above Javascript write an embed tag into the pdfHolder tag. In the embed code, you will put the address of your pdf library. The urlof the pdf file, which we got from the query string(pdfurl), gets placed here. You can adjust the width and height.

5 thoughts on “Open PDF files Dynamically in Content Editor Webpart

  1. Hi Joseph,

    I found your article really helpful. but what I want to know is, if I pass on the pdf url, would that in anyway expose the file location and allow user to get onto that address, if i am storing the files in one of the folders in sharepoint?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.