Firefox 19从JavaScript打印PDF [英] Firefox 19 print PDF from JavaScript

查看:127
本文介绍了Firefox 19从JavaScript打印PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个打印按钮,调用下面的JavaScript

  window.frames.myPdfFrame.print(); 

其中myPdfFrame是指带有PDF的iframe的src。



在Chrome和Firefox 18(及以下版本)中,按预期打开打印对话框,但从Firefox 19开始,出现以下错误:

 Error:Permission denied to access property'print'

假定这与使用随Firefox 19发布的嵌入式PDF查看器相关而不是Adobe插件。使用PDF插件工具栏中的打印图标按预期工作。

有没有一种方法可以在Javascript 19中的Firefox 19中的内联PDF上调用打印对话框?

/ p>

解决方案

我尝试了 JSFiddle演示,使用Firefox 22 和NoScript 。有趣的是,当我第一次打开小提琴的时候,iframe的内容被NoScript屏蔽了,但是打印对话框很容易弹出!我点击确定,我有一个任务栏敬酒说文件 about.blank 被发送到打印机。果然,我检查了打印机,它吐出一个不错的白页。没有用...



现在,在告诉NoScript暂时允许PDF域(irs.gov)之后,我重现了这个错误:


$ b $

 错误:Permission denied to access property'print'

这个其他问题使我不知道这是否是相同来源政策的问题。所以我在自己的web服务器上测试了它,同一台机器上托管了一个PDF文档。而且...没有骰子!

然后我在IE 9和Chrome上试了我的测试页面。他们两个都显示打印对话框,但是当我打印文档的时候,在IE 9的情况下,它实际上是打印about:blank,Chrome打印出一个灰色的矩形Loading...看起来好像是打印整个页面,而不仅仅是iframe中的文档。

所以,我同意Jason Sperske的说法,这看起来不太可能。



更新这个答案提供了一个解决方案只是工作,但只适用于由 Fpdf库生成的PHP文件...


I have a "Print" button which invokes the following JavaScript

window.frames.myPdfFrame.print();

where "myPdfFrame" refers to an iframe with a PDF for the src.

In Chrome and Firefox 18 (and below) this opens the print dialog as expected, but as of Firefox 19 I get the following error

Error: Permission denied to access property 'print'

I assume this is related to using the embedded PDF viewer released with Firefox 19 rather than the Adobe plugin. Using the print icon in the toolbar of the PDF plugin works as expected.

Is there a way to invoke the print dialog on an inline PDF in Firefox 19 from Javascript?

解决方案

I tried the provided JSFiddle demo, with Firefox 22 and NoScript. Interestingly, when I first opened the fiddle, the iframe's content was blocked by NoScript, but the print dialog readily popped up! I clicked "Ok", and I got a taskbar toast saying the document about.blank was sent to the printer. Sure enough, I checked the printer and it spit out a nice white page. Not useful...

Now, after telling NoScript to "temporarily allow" the domain of the PDF (irs.gov), I reproduce the bug :

Error: Permission denied to access property 'print'

This other question made me wonder if it was a problem of same origin policy. So I tested it on my own webserver, with a PDF document hosted on the same machine. And... no dice !

I then tried my test page in IE 9 and Chrome. Both of them do show the print dialog, but when I print the document, in the case of IE 9, it's actually printing about:blank, and Chrome prints a grey rectangle saying "Loading"... looks like it's printing the whole page, not just the document in the iframe.

So, I agree with Jason Sperske that this doesn't seem possible.

UPDATE : this answer offers a solution that "just works", but only for PHP files generated by the Fpdf library...

这篇关于Firefox 19从JavaScript打印PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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