【发布时间】:2018-09-14 22:33:13
【问题描述】:
我正在尝试使用 pdf.js 显示 PDF 文档。
我还可以显示页数、当前页等。但不知道如何显示文件名!这是我的代码:
<div id="pdf-title"></div>
<div id="page-count-container">Page
<div id="pdf-current-page"></div> of <div id="pdf-total-pages">
</div>
</div>
</div>
..
<script>
..
var title;
var __PDF_DOC,
__CURRENT_PAGE,
__TOTAL_PAGES,
__PAGE_RENDERING_IN_PROGRESS = 0,
__CANVAS = $('#pdf-canvas').get(0),
__CANVAS_CTX = __CANVAS.getContext('2d');
function showPDF(pdf_url) {
$("#pdf-loader").show();
PDFJS.getDocument({
url: pdf_url
}).then(function(pdf_doc) {
__PDF_DOC = pdf_doc;
__TOTAL_PAGES = __PDF_DOC.numPages;
title = __PDF_DOC._filename;
// Hide the pdf loader and show pdf container in HTML
$("#pdf-loader").hide();
$("#pdf-contents").show();
$("#pdf-total-pages").text(__TOTAL_PAGES);
$("#pdf-title").text(toString(title));
// Show the first page
showPage(1);
}).catch(function(error) {
// If error re-show the upload button
$("#pdf-loader").hide();
$("#upload-button").show();
alert(error.message);
});;
}..
</script>
谁能帮帮我?
【问题讨论】:
标签: javascript pdf.js