i.amniels
i.amniels

Reputation: 1841

Print PDF in Firefox with Javascript

I'm building an application running in Firefox on a terminal in a warehouse. This application needs to print PDFs.

I found a lot of questions and answers about printing PDF from Javascript, but I can't get it to work.

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. With PDF, the pdf is displayed in the iFrame, but not printed. I tried printing with the Firefox built in PDF renderer and with embedded Adobe acrobat reader. I also tried

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

But that throws TypeError: window.frames.pdfLabel.print is not a function

Upvotes: 2

Views: 4664

Answers (1)

diego nunes
diego nunes

Reputation: 2828

. . 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).

. . They are aware of the problem and the fix is planned to ship with version 21 of Firefox.

Upvotes: 5

Related Questions