Chrome Direct Print (Web App Usage)

“Chrome Direct Print” is abandoned in favor of “WebApp Hardware Bridge
Which support all modern browsers (Chrome, Firefox, Edge),
with better compatibility, performance and serial port support.

Example Usage to call “Chrome Direct Print”
If the extension is not installed, it will fallback to view the PDF.

<!DOCTYPE html>
<html>
    <head>
        <title>Printing...</title>
        <link rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/fnfkcaeloalplnglklappfjfjeafakeo">
    </head>
    <body>
    <h1>Printing...</h1>

    <script>
        var url = 'https://tcpdf.org/files/examples/example_001.pdf';
        var type = 'RECEIPT';

        function directPrint() {
            var evt = document.createEvent('CustomEvent');
            evt.initCustomEvent('chromeHardwareEvent', true, false, {action: 'print', type: type, 'url': url});
            document.dispatchEvent(evt);
            window.close();
        }

        function downloadPDF() {
            document.location.href = url;
        }

        function start() {
            var testImage = document.createElement("img");
            testImage.setAttribute("onload", 'directPrint()');
            testImage.setAttribute("onerror", 'downloadPDF()');
            testImage.setAttribute("src", "chrome-extension://fnfkcaeloalplnglklappfjfjeafakeo/icon-128.png");
            document.body.appendChild(testImage);
        }

        setTimeout(start, 100);
    </script>
    </body>
</html>

6 Replies to “Chrome Direct Print (Web App Usage)”

  1. Getting Error
    “Chrome Direct Print
    Failed to connect to host:Error when communicating with the native messaging host

    Have you installed host?”

    I have installed host….

Leave a Reply to Haider Ali Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.