How to embed PDF in html
Published: Post views:I tried to embed my CV in my homepage, and found that there are mainly three options to include PDF in html:
- object / embed:
<object data="document.pdf" width="1000" height="1000" type='application/pdf'></object>
or<embed src="document.pdf" width="100%" height="100%" type="application/pdf" />
- Pros: Easy to use.
- Cons: Desktop and mobile Safari will stuck when using this method.
- iframe:
<embed src="document.pdf" width="100%" height="100%" ></iframe>
- Pros: Easy to use.
- Cons: Mobile Safari will only show the first page, can not scroll.
- pdf.js:
<iframe src="/web/viewer.html?file=document.pdf" width="100%" height="800"></iframe>
- Pros: works fine in both mobile and desktop browsers.
- Cons: Not natively supported in HTML, needed external libraries.
- Notes:
- The legacy version works fine, but the modern version does not work well in my desktop Safari.
- Some configurations are useful, e.g.,
#pagemode=none
.
References:
- 记录一些曾遇到的前端问题 - 书童小二的文章 - 知乎
- Safari on Big Sur freezes when embedding PDF file
- Make embedded PDF scrollable in iPad
Tags: Front-end, Github pages
Categories: Misc
Comments