pdf.js 自定义title

pdf.js 自定义title

step1:

viewer.js里找到setTitleUsingUrl: function setTitleUsingUrl,方法内的代码改成这样

 var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
                this.url = url;
                try {
                    var titleTmp = (TITLE == '' || TITLE == undefined) ? (decodeURIComponent(pdfjsLib.getFilenameFromUrl(url)) || url) : TITLE;
                    this.setTitle(titleTmp);
                } catch (e) { //
                    //decodeURIComponent may throw URIError, // fall back to using the unprocessed url in that case
                     this.setTitle(url);
                }

step2:

viewer.html引用了viewer.js,插入JS代码块改变viewer.js里的title变量,注意插在引入的viewer.js前

 <script type="text/javascript" language="javascript">
          var TITLE = localStorage.getItem("fileName");
      </script>
    <script src="viewer.js"></script>

step3:

在你使用的pdf.js的方法内,加入

function onLineReadPDF(rulesId,fileName) {
        localStorage.setItem("fileName",fileName)(加入这个,将fileName放进本地存储)
       // window.open("/pdfjs/web/viewer.html?file=/rules/preview?rulesId=" + rulesId);
        window.open("/pdfjs/web/viewer.html?file=/rules/preview?rulesId%3D"+rulesId);
        //		viewer.html?url_file=printcontroller.do?viewfile&id=9999

    }

你可能感兴趣的:(前端)