Problem:
How to embed a PDF or other type of document inside of a WordPress post.
Additional Information:
There are multiple WordPress plugins that use Google Doc Viewer or some other third party to display PDF content. Each (modern) browser has PDF viewing capability built in, or there is a browser plugin that can view the content inline. For example, both Adobe Reader and Foxit Reader have the capability to view a PDF document if you paste the URL in to the address bar.
In the event that the browser does not have PDF viewing capability, the user will simply be prompted to download the PDF
Solution:
Use an iframe.
In the WordPress post editor, click the “Text” tab on the right. Add an iframe tag at the position where you want the content to appear:
<iframe src=”/content/Test_Embed.pdf” height=”1000″ width=”100%” />
The above tag produces this result when published:
Additional Considerations:
The PDF itself must be viewable on the internet. This can be accomplished a couple of ways…
1. Use “Media” and publish the PDF. It won’t be in a recognized format, but will provide a slug that can be used with the iframe tag. The relative URL for the object tag will be:
/wp-content/uploads/filename.pdf
If your base WordPress folder is not the root web, you’ll need to include the base folder:
/JustinParr-Tech/wp-content/uploads/Test_Embed.pdf
This method is useful because it allows posts to be created using only the WordPress GUI, without any file transfer tools or any other special tools.
2. Create a content folder outside of the WordPress folder structure, and upload the file to your server under
/content/some_file.pdf
This method provides the greatest flexibility, when using a separate static content server.
Conclusion:
Using a third-party embedded application (Even Google Doc viewer) complicates the publishing and viewing process — for example, some companies block Google Docs in order to maintain control over their data.