在 iframe 中获取 pdf 的当前页和总页 - pdf.js

get current page and total page for pdf in an iframe - pdf.js

来自 pdf.js 的 pdf 查看器内置了显示当前页面的总页数:

https://mozilla.github.io/pdf.js/web/viewer.html

我在 iframe 的页面上嵌入了一个 pdf。

是否可以在我的页面上使用它,以便

<div id="counter"></div>

填充了与 currentpage / totalpages 相同的信息,如果当前页面不可用,则 totalpages 计数将是令人满意的回退。

我尝试访问 iframeID,但遭到 跨域拒绝

在您的网站上托管查看器不会收到跨域拒绝 -- 这些拒绝是一种浏览器保护,您将无法绕过它们。一旦位于同一域中,您就可以访问 iframe 的 contentWindow 和 PDFViewerApplication 对象。