less than 1 minute read

如何將PDF檔案嵌入HTML頁面,進行顯示?

以下提供並測試幾個方案,並對放在arXiv及GitHub上面的PDF進行測試。

使用 embed

<embed src="https://arxiv.org/pdf/2405.04225" type="application/pdf" width="100%" height="100%">

效果:

對放在arXiv上的PDF,有效。


但對放在GitHub的repository上的PDF就沒效了。GitHub拒絕連線。


使用 iframe

<iframe src="https://arxiv.org/pdf/2405.04225" style="width:100%; height:100%;" frameborder="0"></iframe>

<iframe src="https://arxiv.org/pdf/2405.04225" style="width:718px; height:700px;" frameborder="0"></iframe>

效果:

對放在arXiv上的PDF,有效。


但對放在GitHub的repository上的PDF就沒效了。GitHub拒絕連線。


使用 object

<object width="400" height="500" type="application/pdf" data="/my_pdf.pdf?#zoom=85&scrollbar=0&toolbar=0&navpanes=0">
    <p>Insert your error message here, if the PDF cannot be displayed.</p>
</object>

效果:

對放在arXiv上的PDF,有效。

Insert your error message here, if the PDF cannot be displayed.


但對放在GitHub的repository上的PDF就沒效了。GitHub拒絕連線。

The PDF cannot be displayed. (出現這行字,表示PDF無法顯示)


相關連結

Stack overflow: Recommended way to embed PDF in HTML?

Leave a comment