使用 pdf.js 打印 PDF [英] Printing PDF using pdf.js
问题描述
我正在使用 pdf.js 在页面中嵌入单页 PDF,我希望能够仅打印 PDF,而不是整个 HTML 页面.
I am embedding a single page PDF in a page using pdf.js and I want to be able to print just the PDF, not the whole HTML page.
这可能吗?
推荐答案
我终于解决了.
我不能在这里发布我的代码,但这是我所做的:
I can't post my code here, but here's what I did:
我将 PDF 渲染到 2 个画布上,一个用于缩略图,一个用于打印(隐藏).然后我有一个打印按钮,它打开一个包含 img
标签的新窗口,该标签包含使用 toImageURL()
的巨大画布的内容.print()
函数在新窗口上被调用,接着是 close()
以在打印后自动关闭它.
I rendered the PDF onto 2 canvases, one small for the thumbnail and one huge for printing (hidden). I then had a print button that opened a new window containing an img
tag containing the contents of the huge canvas using toImageURL()
. The print()
function was called on the new window, followed by close()
to close it automatically once printed.
这导致了 PDf 的几乎全尺寸打印,尽管带有浏览器中通常的页码和日期戳.
This resulted in an almost-full-size print of the PDf, albeit with the usual page no and datestamp from the browser.
这篇关于使用 pdf.js 打印 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!