Note:
This was reported before in #7711 and probably in #6152, but incorrectly closed as fixed or not relevant
Configuration:
Steps to reproduce the problem:
Testcase
https://kleins05.github.io/pdf.js/test-ieiframe/
(load in IE11, click print button, check print output)
What is the expected behavior?
The PDF in the iframe should be printed.
What went wrong?
The surrounding page is printed.
Printing support in IE11 is limited in general, furthermore please refer to the relevant section of the FAQ:
While the library and the default viewer should still work in IE 11/Edge (non-Chromium-based) for the time being, some functionality/features may not be available and the performance will be worse compared to modern browsers. Going forward, only bugs which completely prevent the library and/or the default viewer from running will be accepted.
I found the reason. Unlike other browsers window.print in IE causes the currently focused frame/window to print, not necessarily the one that window
refers to. Using document.execCommand avoids this.
In web/pdf_print_service.js:187 instead of print.call(window); use:
var result = window.document.execCommand('print', false, null);
if (!result) {
print.call(window);
}
If you are happy to accept a pull request in spite of your limited support of IE11, I am willing to create one. Let me know.
If you are happy to accept a pull request in spite of your limited support of IE11,
Unfortunately we've never accepted compatibility "hacks" placed in the main code-base, for various reasons such as e.g. readability/maintainability/performance, and those were always restricted to polyfills placed in https://github.com/mozilla/pdf.js/blob/master/src/shared/compatibility.js
Furthermore, at this point in time a bug needs to prevent using the library at all in IE11 to be considered valid. (Expect a future PDF.js release, which one still to be decided as far as I know, to mark IE11 as explicitly unsupported and remove what little compatibility code that remains. Historically trying to support IE11 has restricted the ability to use modern JavaScript features, and has forced contributors to spend a lot of time supporting an essentially dead browser.)
Most helpful comment
I found the reason. Unlike other browsers window.print in IE causes the currently focused frame/window to print, not necessarily the one that
window
refers to. Using document.execCommand avoids this.In web/pdf_print_service.js:187 instead of print.call(window); use:
If you are happy to accept a pull request in spite of your limited support of IE11, I am willing to create one. Let me know.