我正在创建一个通用组件,以便在我的网站上使用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);
});
}
}
})();