Read PRN file using C# to replace variables

// Expert user has replied.
Y Yanis Dalabiras 1 year 11 months ago
163 4 0

Hi,
I want to read PRN file in C# and replace variables with values from C# code. The PRN lael contains text variables and a variable barcode, which should be generated during printing.
Can you please suggest ASAP on this? We have a urgent requirement for this and trying to evaluate different products for barcode label printing.
I really appreciate any quick response.
Attached sample labels.
Thanks

Please Register or Login to post a reply

4 Replies

S Steven Si

Instead of reading from the PRN file and replacing the specific text, it would be better to take the advantage of the template based print offered by the ZPL. You can use the zebradesigner for developers 3 to design the label template and store the template on to the printer, which is called the Stored Format. The application then send the ZPL Recall Format with the variable values to call out the template on the printer. The printer will replace variables with the values and print. There are many examples about how to use the Stored Format & Recall Format on the ZPL user's guide. The Link-OS SDK for .NET also has API to print with the stored format. See the example here - Print a format with variable graphics.

S SRINIVAS PULIPAKA

Hi,
Thanks for replying back. For couple of reasons we cannot use Stored Format, (1) we have several different printers in use and users will choose printer depending on the label size or location they are in etc., (2) some of these printers can be replaced on Adhoc basis (3) some times these printers are relocated depending on the need and this means removing the power supply and etc.,
I believe Stored Format is saved directly in the printer's memory and as a DEV team we do not have direct access to these printers. Also, my understanding is the Stored Formats can be lost when the power supply is removed.

Are there any other options? Basically, we have a C# web application installed in IIS server and users can print labels using the Android application installed in Zebra MC93 type of devices. When the request comes to the web application then it needs to print the label by replacing the template variables, including value for the barcode image and then send that label to the selected printer.
Currently we are able to achieve this by creating PDF files for the labels using another software but the PDF method is taking extra time to print the labels. In our old barcode application written in Visual Basic we are using PRN file approach and it is working fine but now our latest application is written in C# web application and trying to find similar or better way to print labels from our web application.

Any suggestions are greatly appreciated.

S Steven Si

The Stored Format can be saved either in the printer's memory or on the internal flash as a file. If it's saved on the internal flash, it will survive the power off. If it's in the memory, then it will be gone when the printer is powered off.

You can still use the ZebraDesigner to design your own templates, even though you don't want to store them on the printer or use the Stored Format. A template is just a text file with various ZPL formatting statements inside. Place unique strings (or phrases) as the place holders in the text file when work with the ZebraDesigner. The application will need to replace the strings (or phrases) of the place holders in the template with the actual data that you want to print on the label. The C# library should have many string manipulation API for find/replace, etc. Then send the resulting text file to the printer to print. Start with a simple hello world label with the ZebraDesigner. Open the output file, i.e. the *.PRN file, to find the place holders planted in during the label design with the ZebraDesigner. The process is straight forward.

S SRINIVAS PULIPAKA

Thank you so much for your response and I will surely try it out.
Should I open the PRN file in Binary mode or normal text mode? as I see few unreadable characters in this file when opened in Notepad, when I include Barcode.
Do you have any sample C# application to demonstrate this? We need to print the file to a network printer - \\print_server\printer_name. Can we do this from a C# code?
Thanks

S Steven Si

If the PRN file is the output from the ZebraDesigner, it would be a text file and can be opened with any text editor. There should be no unreadable characters. If the label contains image (or graphics), you may see the Base64 characters for the image data.

If you go inside the installation of the Link-OS SDK for .NET, you will find the developer demo source code in the C:\Program Files\Zebra Technologies\link_os_sdk\PC-.NET\v2.15.2634\demos-desktop folder. In this demo, you can find the code on how to connect to the printer.

Please note, we cannot connect to the printer with the \\print_server\printer_name pattern. Unlike the office printers, the Zebra thermal label printers do not support Windows print services.

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