我有一个"打印"按钮,可以调用以下JavaScript
window.frames.myPdfFrame.print();
Run Code Online (Sandbox Code Playgroud)
其中"myPdfFrame"指的是带有src的PDF的iframe.
在Chrome和Firefox 18(及以下版本)中,这会按预期打开打印对话框,但从Firefox 19开始,我收到以下错误
Error: Permission denied to access property 'print'
Run Code Online (Sandbox Code Playgroud)
我认为这与使用Firefox 19而不是Adobe插件发布的嵌入式PDF查看器有关.使用PDF插件工具栏中的打印图标按预期工作.
有没有办法从Javascript调用Firefox 19中的内联PDF中的打印对话框?
我有exf url的pdf文件的URL是"test.example.com/incoice/1/download?auth_token="some_token",当我访问此URL时,url将在浏览器中显示PDF.
现在我想用打印功能打开这个pdf,我的意思是用户不必按CTRL+P我想从我这边做这个.
我试过iframe,但它给了我错误的交叉起源.这是我使用的演示代码
//first try
let _printIframe;
var iframe = _printIframe;
if (!_printIframe) {
iframe = _printIframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.style.display = 'none';
iframe.id = "printf";
iframe.name = "printf";
iframe.onload = function() {
setTimeout(function() {
iframe.focus();
iframe.contentWindow.print();
}, 1);
};
}
// second try
// SRC of pdf
iframe.src = "Some API URl " + "/download?access_token=" +
this.authenticationService.currentTokenDetails.access_token;
let url = iframe.src + "&output=embed";
window.frames["printf"].focus();
window.frames["printf"].print();
var newWin = window.frames["printf"];
newWin.document.write('<body onload="window.print()">dddd</body>');
newWin.document.close();
Run Code Online (Sandbox Code Playgroud)
我在plunker中为print pdf创建了一个demo.http://embed.plnkr.co/WvaB9HZicxK6tC3OAUEw/在这个plunker我打开pdf在新窗口,但我想直接打印该pdf.我怎样才能做到这一点 …