C #-use the ZPL language to generate and print the bar code,

Source: Internet
Author: User

C #-use the ZPL language to generate and print the bar code,
Zookeeper

Recently, due to the needs of the company's projects, I have studied a new technology-bar code generation and printing. I have never touched on this knowledge before, so I am confused and excited at the beginning, but the problem will always be solved step by step. Now let's sum up the harvest of bar code.

 

There is no difficulty in generating a bar code, that is, using some string processing functions to automatically generate a combination of letters or numbers. This section describes how to print the generated barcode value. First, we need to contact a new Language ZPL (ZebraProgramming Language). We can see that the name zebra is related to zebra. Indeed, ZPL is a language independently designed by banma (banma's business is mainly to make banma bar code printers ). Most bar code printers can recognize ZPL commands. We can use ZPL commands to compile a template and format the automatically generated bar code value (string) into a new string in a certain format. Then pass the content to the printer.

The following is a Demo to illustrate the specific operations:

This is a template I have compiled: (Name: BarcodePath, save the format as txt)

Bytes ---------------------------------------------------------------------------------------------------------

^ XA

^ PW1000

^ MD30

^ LH0, 0

# CN_DATA1 #; | | 20 | 15 | ^ FO150, 0

# CN_DATA2 #; | | 20 | 15 | ^ FO650, 0

^ FO70, 0 ^ BY2.0, 3.0 ^ BCN, 120, Y, N, N, A ^ FD # ID1 # ^ FS

^ FO570, 0 ^ BY2.0, 3.0 ^ BCN, 120, Y, N, N, A ^ FD # ID2 # ^ FS

^ PQ1, 0, 1, Y

^ XZ

The ZPL language is quite understandable. It's just a bit of fixed instructions.

Bytes ---------------------------------------------------------------------------------------------------------

^ XA and ^ XZ: The beginning and end of a command block are fixed.

^ PW: Print width. If the width is small, the print is incomplete.

^ MD: Set the depth of the label color. The value range is-30 to 30. The above command sets the color to the deepest.

^ LH: Set the margin of the bar code paper. This template is not set.

Bytes ---------------------------------------------------------------------------------------------------------

The following string is abc ^ edf ~ L000001 ^ L000002 (abc and edf are Chinese characters, L000001 and L000002 are bar code values)

# CN_DATA1 #: a placeholder for abc.

# CN_DATA2 #: a placeholder for edf.

| | 20 | 15 |: The font is, the character height is 20, and the width is 15

^ FO: set the coordinates () at the upper left corner of the bar code ).

^ BY: sets the bar code display style, which is the most important part of the template. 2.0 is the bar code scaling level (acceptable value: 1-10 points ), the bar code displayed under this value is very small, and 3.0 is the ratio of the bar code to the width column (acceptable values: 2.0 to 3.0, incremental 0.1, invalid for a fixed proportion of the bar code ), 120 is the bar code height.

^ BCN: Command for printing code128.

^ FD: Set the content to be printed

^ FS: Indicates line feed.

# ID1 #: L000001

# ID2 #: L000002

Bytes ---------------------------------------------------------------------------------------------------------

^ PQ50, 10, 1, Y: print the total number of 50 tags. Print the number of each group is 10, but it is not paused between each group.

^ PQ50, 10, 1, N: print the total number of 50 tags. The number of prints is 10, and each group is paused after printing.

It can be written as ^ PQ1, 0, 1, and Y, that is, one piece is printed at a time without being paused. Because the total number of printed sheets can be controlled in the program.

Bytes ---------------------------------------------------------------------------------------------------------

Suggestion: You need to write a template by yourself. You can first compile a printed demo and debug and modify the template based on the printed results to achieve the expected results.

The template should be similar here. The following describes how to print.

 

First, we need to introduce an encapsulated DLL file SMT. ZEBRA. dll. The print operation is mainly done by it, and a ZebraPrinter class is encapsulated in it, including the PrintLabEx method.

// Description: // print the barcode, RFID, and other types of tags /// parameter: // n_strTemplateFilePath: // tag TEMPLATE file name, excluding the path, such as: "TEMPLATE. TXT "// n_strLabels: // string of the tag data set. Multiple tag rows are separated by '|', and each tag row uses '^' (field) split or '~ '(Text or bar code), for example, "R & D department ^ 51296829 ~ 8019 ^ 8020 | 11g ~ 51296829 ^ 8001 ^ 8012 "indicates the following print points: // 1. print two lines of labels (commonly known as two) 2. the first line of the label prints two texts ("R & D department" and "51296829") and two bar codes (respectively "8019" and "8020") // 3. the second line of labels prints 1 text ("11G"), 3 bar codes ("51296829", "8001", "8012") // n_strPrinterName: // printer name, etc, for example, "ZDesigner 888-TT" public bool PrintLabEx (string n_strTemplateFilePath, string n_strLabels, string n_strPrinterName );

Client code:

Private void button#click (object sender, EventArgs e) {try {// instantiate a print class ZebraPrinter printer = new ZebraPrinter (); // defines two tag values: string str1 = "L000001 "; string str2 = "L000002"; // formatted as a new string str1 = string. concat ("", "^ ","","~ ", Str1," ^ ", str2); // double-row barcode // str = string. Concat ("","~ ", Str); // single-row barcode // printPath: Template Name // comboBox1.Text: printer name string printPath =" BarcodePath.txt "; printer. printLabEx (printPath, str1, comboBox1.Text);} catch (Exception ex) {MessageBox. show (ex. message) ;}} private void SmtZebraWinFormZPL_Load (object sender, EventArgs e) {// obtain all the printers installed on the Local Computer and save them to PrinterSettings in the strCollects set. stringCollection strCollects = PrinterSettings. installedPrinters; string strPrinterName = string. empty; // traverses the set and loads all printers to the foreach (String strName in strCollects) {strPrinterName = strName. toString (); comboBox1.Items. add (strPrinterName);} comboBox1.SelectedIndex = 0x00 ;}



Print effect:


If you have any questions, please refer to them!

 

 

Code download

 

 

O ノ o ═

│ Programming learning... welcome to the discussion. │

│ Http://blog.csdn.net/u010028869. sampled │

When there are too many threads, there are too many threads, too many threads

 


In the C language, what is the symbol (->) and how to use it?

This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.

In the C language, what is the symbol (->) and how to use it?

This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.