Crossbrowser print pdf

The web application allows the user to print PDF documents using the browser print dialog. Documents are transferred from the service using the mimetype / pdf application. In the web client, an iframe is created and added to document.body, and a service uri is set for the source, which returns the contents. The frame is as follows:

<iframe id="printPage" name="printPage" src="/remote/api/export/resource_name" style="position: absolute; top: -1000px; width: ${opts.frameWidth}px; height: ${opts.frameHeight}px;"></iframe>

Part of printing in javascript is as follows

let iframe = $('the_iframe_html_above');
iframe.load(() => {
  window.frames.printPage.focus();
  window.frames.printPage.print();
});
$('body').append(iframe);

Thus, the print dialog opens, as expected, only in the Chrome and Safari browser.

  • In Firefox, the dialog opens, but prints about: an empty page because the iframe remains empty (there is no content in the body). This happens when pdfjs is disabled roughly from: config, which is obviously ok. If it is not disabled, then FF generates the error "Error: permission is allowed for access to print properties", for which there is a 3-year error indicated in mozilla bugtracker https://bugzilla.mozilla.org/show_bug.cgi?id=911444
  • IE and Edge simply ignore the onload handler, for which I know that it is expected, but even with the onload built-in handler, they cannot open the print dialog. Only IE provides a file for saving / opening, but not for printing. A.

So my question is: if there is a way to cross-browser to perform a print operation (open a browser-based print dialog), given these conditions?

+4

Source: https://habr.com/ru/post/1656312/


All Articles