PDF.js如何打印多页pdf? [英] PDF.js How do you print a multi-page pdf?

查看:832
本文介绍了PDF.js如何打印多页pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向使用PDF.js库的网页中嵌入的多页 PDF添加打印功能.这是有问题的,因为当用户查看页面时,一次只能渲染一个页面,而页面实际上是作为画布元素中的图像渲染的.

此问题在这种情况下无济于事对于单页PDF,可以打印画布的当前内容.与此问题相同.我还希望避免仅在另一个选项卡/窗口中打开PDF并告诉用户自己打印它,这违背了将其嵌入页面的目的.

在Mozilla的文档中,我没有发现任何仅能打印PDF的本机函数,但是,我将开始使用renderingIntent,它似乎可以设置为打印". /p>

redingIntent似乎没有任何影响,并且无论PDF静止图像设置为显示"还是打印",PDF静止图像都以相同的方式呈现.

解决方案

记住PDF.js只是另一个网页. ATM,至少在标准HTML5 API中没有,网页无法将随机信息直接推送到打印机(但是您可以将其推送到云打印服务)-您只能打印自己看到的内容. "See"表示DOM中的内容,当前CSS可用于隐藏屏幕或打印机的信息.还可以更改DOM的preprint/afterprint事件.

在这种情况下,由于您的PDF视图是嵌入式的,因此您需要伪造DOM,以使所有PDF页面/画布都显示在主页上,使其在打印时可见,而在屏幕上隐藏(例如[4]).几乎没有什么其他需要解决的问题可能不在这里了:删除边距和不栅格化画布. Firefox正在通过moznomarginboxes [1]和mozPrintCallback [2]处理这些内容-两者都是为了支持PDF.js而创建的,其他浏览器均不支持. (有关后者,另请参见polyfill [3])

I'm trying to add print functionality to a multi-page PDF embedded in a web page that is using the PDF.js library. It's problematic because I only have one page rendered at a time when a user is viewing it and the page is really rendered as an image in a canvas element.

This question does not help in this case because it is for a single page PDF where printing the current contents of the canvas are acceptable. Same with this question. I also want to avoid just opening the PDF in another tab/window and telling the user to print it themselves, which defeats the purpose of embedding it into the page.

Looking through the documentation from Mozilla, I haven't found any native functions that will just print the PDF, however, I will start playing around with the renderingIntent which seems like it can be set to 'print'.

EDIT: redingIntent doesn't seem to affect anything and the PDF stills renders the same way whether it is set to 'display' or 'print'.

解决方案

Remember PDF.js is just another web page. ATM, at least not in the standard HTML5 APIs, there is no way for a web page push random information directly to printers (but you can push it to the cloud printing service) -- you can print only what you "see". "See" means what's in the DOM, and currently CSS can be used to hide information for the screen or printer. The DOM can also be changed the beforeprint/afterprint events.

In you case, since your PDF view in embedded, you need to fake DOM to have all PDF's pages/canvases on the main web page, make them visible for print and hide for screen (see e.g. [4]). Few different problems needs to be solved too that might be off-topic here: removing margins and non-rasterizing canvas. Firefox is dealing with those via moznomarginboxes [1] and mozPrintCallback [2] -- both are created in support of PDF.js and not supported by other browsers. (See also polyfill for the latter [3])

这篇关于PDF.js如何打印多页pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆