
Understanding Incompatibility of PrintJS with PDF Printing in Firefox, IE, and Edge
TL/DR –
The article contains JavaScript code for a web application. It contains various functions like printing a PDF, image, HTML, and JSON, error handling, and print functionality for various types of files. There’s also a function that listens for any changes in the content of the element with the id ‘printable’. Furthermore, the script contains functionality to track user interactions and cookies, apply event listeners for user interaction, implement a debounce function, and manipulate the Document Object Model (DOM).
Technical Changes To Enhance PrintJS Functionality for Firefox, IE, and Edge Users
In a recent development, PrintJS library has been modified to add support for browsers like Firefox, Internet Explorer (IE), and Edge. It has been observed that PrintJS currently does not support PDF printing in these browsers. Developers have taken steps to address this issue, ensuring a consistent user experience across all platforms. The changes have been implemented effectively to handle different data types including PDF, Image, HTML, Raw-HTML, and JSON.
The code has been optimized using the Uint8Array from the ArrayBuffer interface in JavaScript. This is used for handling binary data. For the ‘pdf’ type, a new Blob object has been created and a URL for the object has been generated using the URL.createObjectURL() method. This URL has been set as the source for the iframe to print the PDF.
For the ‘image’ type, a new div element has been created for each image and appended to the printable element. For ‘html’ and ‘raw-html’ types, the printable element has been cloned and all required child nodes have been appended. After this, the printable element is sent for printing.
For ‘json’ type, the code first validates the printable data to be a valid JSON object. If the data is valid, a new div element is created and the JSON data is appended to this div. Then, this div is sent for printing.
In addition to these, several error handling techniques have been implemented. If an error occurs during any operation, the error message is logged and the onError event is triggered. The showModal and onLoadingEnd events are also triggered to notify the user about the status of the printing process.
Furthermore, the interactive ‘Donate’ button has been redesigned with a more intuitive icon and linked to the donation page. Similarly, the ‘Print’ button has been modified to trigger the PrintJS function for non-Firefox users, while Firefox users are served with the default print dialog.
Other modifications include changes in the social sharing buttons, website’s popup modal, newsletter placement, and author’s name display. More details can be found in the source code.
—
Read More Health & Wellness News ; US News