济南网站建设鲁icp备,wordpress首页图片导航分类,word调用wordpress,凡科互动答题辅助现在前端pdf需求越来越多#xff0c;比如发票的显示#xff0c;文件的显示#xff0c;怎么实现具体步骤百度一下吧#xff0c;这里不做详细介绍#xff0c;主要记录下遇到的问题
1.页面pdf已经看到了#xff0c;但是 iframe.contentWindow.PDFViewerApplication显示unde…现在前端pdf需求越来越多比如发票的显示文件的显示怎么实现具体步骤百度一下吧这里不做详细介绍主要记录下遇到的问题
1.页面pdf已经看到了但是 iframe.contentWindow.PDFViewerApplication显示undefined 当时代码是这么写的页面已经看到pdf了但是PDFViewerApplication确实undefined这样findBar方法也没法用于是我疯狂百度搜索原因很不幸这5个原因里面没有我的原因不得已值得从头来再啃一边pdf.js终于给我找到了 页面加载完成之后再赋值
很开心不仅可以高亮还可以自动定位到高亮的位置
最后贴一下代码 var data res.datavar ThemeInformationFileUrlInnerhtml iframe idnoticeIf width100% styleborder-radius: 0/iframe$(#notInformationId).html(ThemeInformationFileUrlInnerhtml)$(#noticeIf).attr(src, ./js/pdf/web/viewer.html?file data.notTextAnnouncementFileUrl);// 检查pdf是否正确加载var intervalId window.setInterval(function() {let iframe document.getElementById(noticeIf);if (iframe iframe.contentWindow iframe.contentWindow.PDFViewerApplication) {console.log(pdf已经加载)window.clearInterval(intervalId);// PDF已加载完成执行其他操作let text 主要财务数据iframe.contentWindow.postMessage(text, *)iframe.contentWindow.addEventListener(message, (e) {console.log(addEventListener, e)console.log(iframe.contentWindow:, iframe.contentWindow)console.log(iframe.contentWindow.PDFViewerApplication:, iframe.contentWindow.PDFViewerApplication)iframe.contentWindow.PDFViewerApplication.findBar.findField.value e.dataiframe.contentWindow.PDFViewerApplication.findBar.highlightAll.checked trueiframe.contentWindow.PDFViewerApplication.findBar.dispatchEvent(highlightallchange)console.log(延迟后 iframe.contentWindow.PDFViewerApplication:, iframe.contentWindow.PDFViewerApplication)}, false)} else {console.log(pdf还没加载)}}, 1000); // 每秒检查一次