viewer.js 加载pdf
时间: 2023-11-09 10:02:42 浏览: 36
文件的方法是什么?
您可以使用以下代码来加载 PDF 文件:
```
<!-- pdf.js library -->
<script src="/path/to/build/pdf.js"></script>
<!-- pdfjs viewer -->
<link rel="stylesheet" href="/path/to/web/viewer.css">
<!-- container to hold pdf viewer -->
<div id="pdfContainer"></div>
<!-- initialize pdf viewer -->
<script>
// reference to pdf container
const container = document.getElementById('pdfContainer');
// path to pdf file
const pdfPath = '/path/to/my.pdf';
// initialize pdf viewer
const pdfViewer = pdfjsLib.getDocument(pdfPath).promise.then(function(pdf) {
// set up the viewer options
const options = {
pdfDocument: pdf,
container: container,
};
// create the viewer
const viewer = new pdfjsViewer.PDFViewer(options);
// initialize the viewer
viewer.initialize();
// show the first page
viewer.currentPageNumber = 1;
});
</script>
```
请注意,您需要使用适当的路径替换路径字符串以及确保正确引用 pdf.js 库和样式表。