如何使用Mozilla pdfjs在隐藏选项卡中呈现pdf

时间:2018-11-20 11:51:00

标签: jquery css pdf mozilla pdfjs

我正在创建一个通用组件,以便在我的网站上使用pdfjs呈现pdf

在某些页面中,我有多个包含PDF的标签,我的问题是文本图层无法在隐藏的标签中呈现,那么如何使所有pdf在所有标签中呈现?

(function () {
ko.bindingHandlers.fileViewer = {
    init: function (element) {
        var pdfjsLib = window['pdfjs-dist/build/pdf'];
        pdfjsLib.GlobalWorkerOptions.workerSrc = '/Scripts/pdfJs/pdf.worker.js';
    },

    update: function (element, valueAccessor) {
        var pdfLinkService = new pdfjsViewer.PDFLinkService();

        var pdfViewer = new pdfjsViewer.PDFViewer({
            //The container is relative to the element to support multiple pdfs in the page 
            container: element.children[0].children[0],
            linkService: pdfLinkService,
        });
        pdfLinkService.setViewer(pdfViewer);

        pdfjsLib.getDocument({
            url: ko.unwrap(valueAccessor()),
        }).then(function (pdfDocument) {
            pdfViewer.setDocument(pdfDocument);
            pdfLinkService.setDocument(pdfDocument, null);
        });
    }
}

})();

0 个答案:

没有答案