zebra printer

-2
I need to use Zebra printer (Thermal printer) while using Mendix and it does not work . The report paper that need to be printed , look like a bill papar. any advice or suggestion would be nice
asked
7 answers
0

Do you run your mendix app in a browser or in a native app created by phone gap?

How do you try to connect to the zebra printer? Do you want to connect by an app module of Mendix app Store? 

Please, provide more information.

answered
0

Hi, 

I found a solution for WEB Responsive Printing with Zebra BrowserPrint SDK (Working for me with Zebra GC420 USB Printer but it works with bluetooth and ethernet printers too)

1 – Download and install Zebra Browser Print, It automatically identify usb printers connected to your pc, you must only select the default printer.

https://www.zebra.com/us/en/products/software/barcode-printers/link-os/browser-print.html

2 – In mendix project, Edit \..\theme\index.html, Add a Javascript function in the javascript section.

<script type="text/javascript">
            var selected_device;
            var devices = [];
            function setup()
            {
                //Get the default device from the application as a first step. Discovery takes longer to complete.
                BrowserPrint.getDefaultDevice("printer", function(device)
                        {
                    
                            //Add device to list of devices and to html select element
                            selected_device = device;
                            devices.push(device);
                                                        
                                            
                        }, function(error){
                            //alert(error);
                        })
            }
            function writeToSelectedPrinter(dataToWrite)
            {
                selected_device.send(dataToWrite, undefined, errorCallback);
            }
            var errorCallback = function(errorMessage){
                alert("Error: " + errorMessage);    
            }
            window.onload = setup;
        </script>

3 – Call the Javascript function using a Javascript Action, like this:

 

import { Big } from "big.js";

 

// BEGIN EXTRA CODE

// END EXTRA CODE

 

/**

* Ação javascript para imprimir através do web responsivo utilizando o driver Zebra BrowserPrint.

* @param {string} zpl

* @returns {Promise.<Big>}

*/

export async function Act_Imprimir_ZebraBrowserPrint(zpl) {

    // BEGIN USER CODE

    writeToSelectedPrinter(zpl)

    // END USER CODE

}

Hope it works fot you too!

answered
0

Hi, how are you all? This is a solution without JAVA; Directly using javascript, and IT WORKS!

I will tell you how to print directly from your browser to your Zebra Printer;

 

First go to Zebra Website and download the app ‘Zebra Browser Printer’

Install it and make sure iit’s running on your windows;

Now you can use a nanoflow to write a JS function just like bellow, requesting a POST into your 127.0.0.1:9100/write wich was created by Zebra Browser Printer

 

/**

 * @param {string} zPL

 * @returns {Promise.<void>}

 */

export async function JS_ImprimeLocal(zPL) {

    // BEGIN USER CODE

    await fetch("http://127.0.0.1:9100/write", {

    "credentials": "omit",

    "headers": {

        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0",

        "Accept": "*/*",

        "Accept-Language": "pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3",

        "Content-Type": "text/plain;charset=UTF-8",

        "Sec-Fetch-Dest": "empty",

        "Sec-Fetch-Mode": "cors",

        "Sec-Fetch-Site": "cross-site"

    },

    "body": zPL,

    "method": "POST",

    "mode": "cors"

});

    // END USER CODE

}




This solution enable printer fixing CORS issues where a request of POST from an external DNS server is possible directly to your local windows machine ip 127.0.0.1:9100/write;

Another stuff is the following (in this example the zPl variable passed to JS activity has all the informations of printer and his connection to properly works); So, THE JSON bellow is  an example to make it work from mendix;

 

create a variable with the json bellow and change the variables just like your printer settings; you can also test the function in console first, to make the first request and be authorized by zebra browser printer to make this request

 

'{

 

"device":   {"name":"NAME_OF_YOUR_PRINTER","uid":"UID_OF_YOUR_PRINTER","connection":"network","deviceType":"printer","version":4,"provider":"com.zebra.ds.webdriver.desktop.provider.DefaultDeviceProvider","manufacturer":"Zebra Technologies"},

"data":

 

“:D:D:D:D HERE IS WHERE YOUR ZPL GOES :D:D:D:D”


}'

answered
-1

any advice would be nice

answered
-1

Did you read this: https://developer.zebra.com/community/home/blog/2018/04/13/printing-from-websites-part-1 ?

answered
-1

Hi Pasit,

Looks like you can print through javascript. The browser print section of this documentation shows some example code and more details.

https://www.zebra.com/content/dam/zebra/software/en/application-notes/zebra-web-printing-solutions-app-notes.pdf

 

To run custom javascript in Mendix, you could use a custom widget or build your own widget.

 

I think the examples use a specific javascript library, and in order to that you will have to create a custom widget.

Here is some documentation on custom widgets

https://docs.mendix.com/howto50/creating-a-basic-hello-world-custom-widget

https://docs.mendix.com/howto/custom-widget-development/

 

 

Here are two widgets that are used often to run custom javascript in a mendix app. You can also give these a try.

https://appstore.home.mendix.com/link/app/56/

https://appstore.home.mendix.com/link/app/43096/

 

Hope this helps!

 

 

 

answered
-2

Are you sure this is a Mendix related question?

answered