1. iframe
所有瀏覽器都支持 < iframe > 標(biāo)簽览芳,直接將src設(shè)置為指定的PDF文件就可以預(yù)覽了谷朝。此外可以把需要的文本放置在
< iframe > 和 之間洲押,這樣就可以應(yīng)對無法理解 iframe 的瀏覽器,比如下面的代碼可以提供一個PDF的下載鏈接:
<iframe src="/index.pdf" width="100%" height="100%">
This browser does not support PDFs. Please download the PDF to view it: <a href="/index.pdf">Download PDF</a>
</iframe>
2. PDF.js
下載鏈接:https://mozilla.github.io/pdf.js/
PDFJS.getDocument('../index.pdf').then(pdf=>{
? ? ? ? var numPages = pdf.numPages;
? ? ? ? var start = 1;
? ? ? ? renderPageAsync(pdf, numPages, start);
? ? });