Creating ZPL files from a .nlbl template using .net

// Expert user has replied.
J Jordon Pilling 1 year 7 months ago
2296 4 0

We have multiple templates ready in ZebraDesigner and saved as *.nlbl files - i.e. with placholder textboxes and barcodes all in the correct locations / sizes etc

We need to use .net to open this *.nlbl files, populate the placeholder textboxes and barcodes with real data then save as a zpl file.

Stackoverflow and general googling gives a barrage of outdated / conflicting information on this topic.

Please can you confirm the "pest practice" way for us to acheive the above? Is there an SDK that will open an nlbl file and allow the export to zpl file?

Please register or login to post a reply

4 Replies

D Dougie Birrell

Not the most elegant solution, but I've printed the nlbl file I'd designed to a zpl file, by changing the print port to "Print to File". I then opened and pasted the ZPL file into a string. (example below) This allowed me to add in variables (assetID, location, item, category) from a database allowing me to to print custom labels. C# Example

private static string CreateLabel(string assetID, string item, string category, string location)
{
byte[] assetByte = Encoding.Default.GetBytes(assetID);
var assetHex = BitConverter.ToString(assetByte);
assetHex = assetHex.Replace("-", "");
string label = "CT~~CD,~CC^~CT~" +
"^XA~TA000~JSN^LT0^MNW^MTT^PON^PMN^LH0,0^JMA^PR2,2~SD10^JUS^LRN^CI0^XZ" +
"^XA" +
"^MMT" +
"^PW607" +
"^LL0198" +
"^LS0" +
"^FO0,0^GFA,02048,02048,00016,:Z64:" +
"....long string of hex which was an image" +
"^BY3,3,43^FT149,167^BCN,,Y,N" +
"^FD>:" + assetID + "^FS" +
"^FT25,130^AAN,27,10^FH\\^FD" + assetID + "^FS" +
"^FT115,23^A0N,23,26^FB468,1,0,R^FH\\^FD_MYCOMPANY_NAME^FS" +
"^FT489,44^A0N,17,16^FH\\^FDEH54 5DJ, UK^FS" +
"^FT146,92^AAN,18,10^FH\\^FDCat: " + category + "^FS" +
"^FT146,112^AAN,18,10^FH\\^FDLoc: " + location + "^FS" +
"^FT134,71^AAN,18,10^FH\\^FDItem: ^FS" +
"^FT208,71^AAN,18,5^FH\\^FD" + item + "^FS" +
"^PQ1,0,1,Y^XZ";
return label;
}

J Jordon Pilling

Thank you for the example.
This is pretty risky if your variables (category, location, item etc) contain ZPL control characters such as ^ or \\
Is there an authoritative list of illegal characters that need to be escaped in ZPL / do you have a function already that does this?
This is why i was asking about SDK, this concatenation method appears very crude / reminds me of SQL injection lol.
That said, if it's the only option, i can figure out the escape logic from scratch by adding ^ and \\ in ZebreaDesigner labels and saving as prn files i suppose – I just don’t want to re-invent the wheel when smarter and more knowledgeable people have surly already tackled this issue :)
Thanks again, and would love to hear how other people have approached the escaping issue with concatenation / string replace method.
J.

D Dougie Birrell

These were labels with a barcode and certain areas for the text. The values for the text came from a SQL table, in which had the safety measures to only allow letters and numbers when entered into the database, so it by passed the risky aspect.

\\ was a C# specific change, they were originally \ but C# treats that as a special character so needed to be changed to \\ in the code.

Yeah I totally get about not reinventing the wheel! Hope you can find what you're looking for, if not this will help! :)

S Steven Si

There is no need to deal with the *.nlbl file directly, which is in a proprietary format. The ZebraDesigner can export the *.nlbl into the *.prn file, called as the template file in ZPL (or in XML with the ZebraDesigner for Developers). Your .NET application only needs to work with the *.prn file to populate the values. There are two ways to populate the values for the template. You can either replace the variables (or the placeholders) in the template and send the resulted ZPL file to the printer to print. Or you can send the template first as the stored format onto the printer and then send the recall format (with the values) to the printer. The printer will replace the variables with the values passed in the recall format and print the label.

CONTACT
Can’t find what you’re looking for?