Pdf.js: IE11 print margins in iFrame

Created on 10 Feb 2017  路  8Comments  路  Source: mozilla/pdf.js

Outside to iFrame, and with outher browsers it's all ok!
Into IE11 iframe not.

<iframe src="http://mozilla.github.io/pdf.js/web/viewer.html"></iframe>

Configuration:

  • Web browser and its version: IE11
  • Operating system and its version: WIN 10
  • PDF.js version: 1.7.225
  • Is an extension: -

Steps to reproduce the problem:

  1. Open the official demo page in a iframe with IE11
  2. Print

Print outside iframe:
image

Print into iframe:
image

Wrong:
image

Could you help me? thanks!

4-printing

Most helpful comment

While I'm not entirely sure why, IE11 (and older version of IE) has issues with using window.print in an iframe. Using window.document.execCommand('print', false, null); seems to get the desired results, but is not supported in Firefox.

If you are building pdf.js from source, you can change print.call(window) in pdf_print_service.js to this:

if (document.queryCommandSupported('print')) {
  window.document.execCommand('print', false, null);
} else {
  print.call(window);
}

For a more complete solution, you might also want to check if you are in an iframe.

All 8 comments

While I'm not entirely sure why, IE11 (and older version of IE) has issues with using window.print in an iframe. Using window.document.execCommand('print', false, null); seems to get the desired results, but is not supported in Firefox.

If you are building pdf.js from source, you can change print.call(window) in pdf_print_service.js to this:

if (document.queryCommandSupported('print')) {
  window.document.execCommand('print', false, null);
} else {
  print.call(window);
}

For a more complete solution, you might also want to check if you are in an iframe.

Great! Print space is ok now, but I have one more issue ... Print doesn't take the correct page orientation. Below an example of landscape page, but printed with portrait orientation ... (always with IE11 and iFrame) ...

Thanks!!

image

solution by kimgronqvist worked for margin issue. But it created a new issue for me.

I had a custom event listener for "afterprint" event like below.

someiframe.contentWindow.addEventListener("afterprint", function() {
    window.close();
});

This event doesn't trigger in IE after the margin fix. Fine in chrome.... Any ideas?

Same issue here, can this be fixed inside the package?

Try setTimeout like:

someiframe.contentWindow.addEventListener("afterprint", function() {
   setTimeout(function(){
       window.close();
   }, 1000) 
});

In Internet Explorer锛宼he JavaScript thread will be blocked when the print dialog appears. So try to use setTimeout to make it execute when the thread resumes (close the print dialog)

I am also experiencing this in IE, but @kimgronqvist's solution did not fix it. Is there an official solution to this issue?

I face with same problem. @kimgronqvist's solutions work from time to time.
Will this issue be fixed in official package?

Closing IE11/Edge (non-Chromium-based) issues in response to #11211. Please note that, as outlined in https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#faq-support, only bugs which completely prevent the library and/or the default viewer from running will be accepted.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hp011235 picture hp011235  路  4Comments

SehyunPark picture SehyunPark  路  3Comments

sujit-baniya picture sujit-baniya  路  3Comments

anggikolo11 picture anggikolo11  路  3Comments

xingxiaoyiyio picture xingxiaoyiyio  路  3Comments