How to insert variables into Zebra .prn file to print a label with data via Intent

I have designed a custom label using ZebraDesigner2. The label contains custom fonts and variable text fields and looks like this:

RFO0Km.png

I've printed the label to a .prn file and downloaded it to the Android device. I'm using the PrintConnect app and have also set the correct Storage type and Storage folder.

What I want to do is print a custom label filled with specific data from my Android app. I'm using the following code:

    HashMap<String, String> variableData = new HashMap<>();

   

    variableData.put("var_ds", "10:00-12:00");

    variableData.put("var_on", "123ABC456");

    variableData.put("var_qcc", "123456778123456789");

    variableData.put("var_dd", "DO 19/06");

    variableData.put("var_ln", "1/1");

    variableData.put("var_cn", "John Doe");

    variableData.put("var_da", "Somecoolstreet 11");

    variableData.put("var_dc", "Awesomecity");

    variableData.put("var_ot", "Delivery");

    variableData.put("var_cp", "0612345678");

   

    Intent intent = new Intent();

    intent.setComponent(new ComponentName("com.zebra.printconnect",

            "com.zebra.printconnect.print.TemplatePrintService"));

    intent.putExtra("com.zebra.printconnect.PrintService.TEMPLATE_FILE_NAME", "custom_label.prn");

    intent.putExtra("com.zebra.printconnect.PrintService.VARIABLE_DATA", variableData);

   

    startService(intent);

The code does print a label but all the variables are not filled correctly. Example: instead of '10:00-12:00' it shows 'var_ds' on the label.

What am I doing wrong?

Anonymous (not verified)
Hi Narek, The issue is your

Hi Narek,

The issue is your custom fonts. If you want to have variable data with custom fonts, you need to download the custom font onto the printer.  The design software can't create a bitmap using the font for the text you haven't placed yet.

You can either use the built-in fonts on the printer or download the ones you want onto the printer.  Keep in mind there is usually a licensing fee per download paid to the font copyright owner.

Once you have the font on the printer, you would create you format in the designer with font 0, then you would modify the output format to use your downloaded font. After that, your code should work.

I have a video with many of these details here: Zebra Dev {Talk} Label Design – Creating Unique, Clear Labels For Your App - YouTube

Vote: 
Vote up!
Vote down!

Points: 1

You voted ‘up’


Narek Aramjan
Thanks for the help Robin!

Thanks for the help Robin!

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Alex Kopan
I'm having the same issue in

I'm having the same issue in my PC java application. Documentation is pretty poor, and I've wasted a lot of time on this. Even the example code from Zebra does not fill the label variable fields correctly. Just spits out the variable names like yours.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Alexander Palchikov
Hi Alex,In a comment above

Hi Alex,

In a comment above there was an advice for Narek on fixing this issue, have you tried it?
If so then could you please give more info about your issue?

Alexander Palchikov
Software Engineer, Kutir Mobility
Posted on behalf of Zebra Technologies

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments