This is an example post showing different ways to embed PDF files in your Hugo blog posts.
Setup
First, place your PDF file in the static/documents/ directory. For example:
static/documents/resume.pdfstatic/documents/whitepaper.pdf
Method 1: Simple iframe (Recommended)
This is the most compatible method that works across all browsers:
| |
Example with actual file:
| |
Method 2: Embed tag
Another approach using the embed tag:
| |
Method 3: Object tag with fallback
This provides a download link for browsers that can’t display PDFs:
| |
Responsive Styling
You can make the PDF viewer responsive with better styling:
| |
Live Demo
Here’s a working example with an actual embedded PDF:
How to Use
- Place your PDF files in
static/documents/directory - Reference them in your markdown as
/documents/filename.pdf - Choose one of the methods above and paste the HTML code in your markdown
- Adjust width and height as needed
That’s it! The PDF will be embedded directly in your blog post and visitors can view it without downloading.