简体   繁体   English

使用Javascript在Firefox中打印PDF

[英]Print PDF in Firefox with Javascript

I'm building an application running in Firefox on a terminal in a warehouse. 我正在仓库中的终端上构建在Firefox中运行的应用程序。 This application needs to print PDFs. 该应用程序需要打印PDF。

I found a lot of questions and answers about printing PDF from Javascript, but I can't get it to work. 我发现了很多有关从Javascript打印PDF的问题和答案,但是我无法使其正常工作。

This is my current code. 这是我当前的代码。

$(document).ready(function() {
    $(document.body).append('<IFRAME id="pdfLabel" ... >');
    $('iframe#pdfLabel').attr('src', 'testlabel.pdf');

    $('iframe#pdfLabel').load(function() {
        document.getElementById('pdfLabel').focus();
        document.getElementById('pdfLabel').contentWindow.print();
    });
});

With a regular html page in the iFrame, this code works flawlessly. 通过iFrame中的常规html页面,此代码可以完美运行。 With PDF, the pdf is displayed in the iFrame, but not printed. 使用PDF时,pdf会显示在iFrame中,但不会打印。 I tried printing with the Firefox built in PDF renderer and with embedded Adobe acrobat reader. 我尝试使用内置PDF渲染器的Firefox和嵌入式Adobe acrobat reader进行打印。 I also tried 我也试过

document.getElementById('pdfLabel').print();

But that throws TypeError: window.frames.pdfLabel.print is not a function 但这会引发TypeError: window.frames.pdfLabel.print is not a function

. . Sadly, the PDF.js version shipped with Firefox 19 doesn't support built-in JavaScript to self-print the document and it also doesn't allow you to access anything inside the PDF window (including the print method). 令人遗憾的是,Firefox 19附带的PDF.js版本不支持内置JavaScript自行打印文档,也不允许您访问PDF窗口内的任何内容(包括打印方法)。

. . They are aware of the problem and the fix is planned to ship with version 21 of Firefox. 他们已经知道了问题,并计划在Firefox 21版本中提供此修复程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM