[英]how can I display my file name using PDF.js?
I am trying to display a PDF document using pdf.js. 我正在尝试使用pdf.js显示PDF文档。
I am able to display also the number of pages, current page, etc. But couldn't figure how to display file name!here's my code: 我还可以显示页数,当前页面等。但是无法显示文件名!这是我的代码:
<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>
Can someone help me out? 有人可以帮我吗?
I figured out a way to fix this inconvenience, here's my code: 我想出了一种解决此不便的方法,这是我的代码:
var __PDF_DOC,
__CURRENT_PAGE,
__TOTAL_PAGES,
__PAGE_RENDERING_IN_PROGRESS = 0,
__CANVAS = $('#pdf-canvas').get(0),
__TITLE;
__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=$("#file-to-upload").get(0).files[0].name;
// 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(__TITLE);
i was calling actually for the wrong variable!! 我实际上是在要求错误的变量! hope this would help some of you guys!!
希望这对你们中的一些人有帮助!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.