A label generation and printing method, apparatus, and storage medium
By converting ZPL format files into JSON objects and performing variable substitution and Chinese character processing, the incompatibility of ZPL format files on ordinary printers and the problem of Chinese character printing are solved, thus achieving compatibility and Chinese character support for printing ZPL format labels on ordinary printers.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-28
- Publication Date
- 2026-04-03
AI Technical Summary
Existing ZPL format files can only be used on specific printers, are not compatible with ordinary printers, and cannot print Chinese information.
The ZPL format file is converted into a JSON object, the tag content and control instructions are parsed, variables are extracted and assigned values, Chinese characters are converted into bitmap images and represented by ASCII symbols, and can be printed on a regular printer.
It enables compatibility of ZPL format labels with ordinary printers and Chinese printing, reducing costs and expanding the printer's application range.
Smart Images

Figure CN115660012B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of printing technology, and more particularly to a label generation and printing method, apparatus, and storage medium. Background Technology
[0002] With the development of information technology in warehouse management, it is frequently necessary to print material labels and affix them to materials to indicate their relevant attributes in warehouse management and manufacturing. Currently, printers using the ZPL format are widely used in various label printing activities. However, ZPL format files can only be used on certain specific printers, such as Zebra printers, lacking versatility and incompatibility with other common printers. Furthermore, it is impossible to add variables during printing to achieve dynamic printing for the user. Summary of the Invention
[0003] This invention addresses the shortcomings of existing technologies by providing a label generation and printing method, comprising the following steps:
[0004] S1, obtain the ZPL format file generated by the label designer, download the images in the ZPL format label file to the printer's specified storage location for subsequent label instructions to reference, parse the label content and label control instructions in the ZPL format file, and convert all fields in the label into a first JSON object. The label control instructions include, but are not limited to, label position and configuration printing parameters.
[0005] S2, extract the variable names and corresponding values from the received second JSON object containing the assigned variables, and replace the variable values after finding the corresponding matching variable names in the first JSON object;
[0006] S3 converts the Chinese characters in the ZPL format label file into dot matrix images, then converts them into ZPL encoding represented by ASCII symbols, and sends the converted image information to the target printer in advance, and adds image reference instructions at the corresponding coordinate positions in the first JSON object.
[0007] Preferably, step S1 includes: parsing the ZPL format file into fields of the execution statement, including but not limited to a first field, a second field, a third field, and a fourth field; the first field is a text / graphic field to be displayed during printing, including coordinate position, font size, font type, border thickness, and length; the second field is a printing parameter setting field, including printing parameters or strings composed of these parameters; the third field is an image field, configured to parse ASCII codes converted from image dot matrix; and converting the execution statement of the ZPL format file into a JSON object according to preset rules, wherein the preset rules are configured to adjust the parsing action based on the identified character markers, where TOKEN represents the default TOKEN group to start parsing, VALUE represents parsing until a set symbol is encountered, and VARSTR represents parsing strings enclosed in quotation marks on both sides, and the quotation marks cannot contain specific characters.
[0008] Preferably, step S2 includes:
[0009] Retrieve the material name field and its corresponding text box field with variables, as well as the serial number field and its corresponding barcode field with variables from the first JSON object;
[0010] Set the tag attribute in the first JSON object to the template tag, which is configured to be stored as a printing template in the printer's designated storage device and referenced when printing other tags;
[0011] Identify the variable names in the received second JSON object, which includes each variable name and its corresponding replacement value. Search for the corresponding field in the first JSON object based on the variable name and assign and modify its corresponding value to the replacement value.
[0012] Preferably, step S3 includes: converting Chinese characters into a dot matrix image, then converting the dot matrix image into ZPL encoding represented by ASCII characters as image information, sending the image file to the printer's image information database and storing it, and adding an image information reference instruction at the corresponding coordinate position in the first JSON object.
[0013] Preferably, step S3 further includes: determining the variable type based on the variable name and corresponding value in the second JSON object; if the variable value is Chinese, querying the corresponding variable name group in the image information database based on the variable name, obtaining the image information location information of the corresponding Chinese name in the variable name group, and replacing the variable value with the image information location.
[0014] This invention also discloses a label generation and printing device, including a parsing module, a variable substitution module, and a Chinese character conversion module. The parsing module is used to acquire a ZPL format file generated by a label designer, download the images within the ZPL format label file to a designated storage location on the printer for subsequent label instructions, parse the label content and label control instructions in the ZPL format file, and convert all fields within the label into a first JSON object. The label control instructions include, but are not limited to, label position and configured printing parameters. The variable substitution module is used to extract the variable names and corresponding values from a received second JSON object containing assigned variables, find the corresponding matching variable name in the first JSON object, and then assign and replace the variable value. The Chinese character conversion module is used to convert the Chinese characters in the ZPL format label file into dot-matrix images, then convert them into ZPL encoding represented by ASCII symbols, and pre-send the converted image information to the target printer, adding image reference instructions at the corresponding coordinate positions in the first JSON object.
[0015] Preferably, the parsing module includes: a field conversion module, used to parse the ZPL format file into fields of the execution statement, including but not limited to a first field, a second field, a third field, and a fourth field; the first field is a text / graphic field to be displayed during printing, including coordinate position, font size, font type, border thickness, and length; the second field is a printing parameter setting field, including printing parameters or strings composed of these parameters; the third field is an image field, configured to parse ASCII codes converted from image dot matrix; and a JSON conversion module, used to convert the execution statement of the ZPL format file into a JSON object according to preset rules, wherein the preset rules are configured to adjust the parsing action based on the recognized character markers, where TOKEN represents the default TOKEN group to start parsing, VALUE represents parsing until a set symbol is encountered, and VARSTR represents parsing strings enclosed in quotation marks on both sides, and the quotation marks cannot contain specific characters.
[0016] Preferably, the variable replacement module is configured to: obtain the material name field and its corresponding text box field with variable, and the serial number field and its corresponding barcode field with variable from the first JSON object; set the label attribute in the first JSON object as a template label, which is configured to be stored as a printing template in a designated storage device of the printer for reference when printing other labels; identify the variable names in the received second JSON object, which includes each variable name and its corresponding variable replacement value; search for the corresponding field in the first JSON object according to the variable name and assign and modify its corresponding value to the variable replacement value.
[0017] The present invention also discloses a server, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of any of the methods described above.
[0018] The present invention also discloses a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of any of the methods described above.
[0019] The label generation and printing method, apparatus, and storage medium disclosed in this invention can achieve previewing or printing as an image on a regular printer by converting ZPL files into JSON and then restoring the JSON. At the same time, it enables customers to print label files designed by a label designer that outputs ZPL format on regular printers using other file formats. Furthermore, variables can be added to the label, allowing users to transmit specific variable data during the printing process to achieve dynamic printing.
[0020] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description
[0021] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0022] Figure 1 This is a flowchart illustrating the label generation and printing method disclosed in this embodiment.
[0023] Figure 2 This is a schematic diagram of the specific process of step S2 disclosed in this embodiment.
[0024] Figure 3 An example of a label generated by the label designer disclosed in one embodiment. Detailed Implementation
[0025] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the described embodiments of the present invention without creative effort are within the scope of protection of the present invention.
[0026] In the description of this invention, it should be understood that the terms "center," "longitudinal," "lateral," "length," "width," "thickness," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," "outer," "clockwise," and "counterclockwise," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this invention.
[0027] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.
[0028] In this invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," "linking," and "fixing," etc., should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances.
[0029] In this invention, unless otherwise explicitly specified and limited, "above" or "below" the second feature can include direct contact between the first and second features, or contact between the first and second features through another feature between them. Furthermore, "above," "over," and "on top" of the second feature includes the first feature directly above or diagonally above the second feature, or simply indicates that the first feature is at a higher horizontal level than the second feature. "Below," "below," and "under" the second feature includes the first feature directly below or diagonally below the second feature, or simply indicates that the first feature is at a lower horizontal level than the second feature.
[0030] Unless otherwise defined, the technical or scientific terms used herein shall have the ordinary meaning as understood by one of ordinary skill in the art to which this invention pertains. The terms “first,” “second,” and similar terms used in the specification and claims of this patent application do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Similarly, the terms “an” or “a” and similar terms do not indicate a limitation of quantity, but rather indicate the presence of at least one.
[0031] Currently, some label designers generate ZPL format label printing files that can only be printed on certain printers such as Zebra printers, and cannot be printed on other common label printers. Furthermore, ZPL format files cannot print Chinese characters, causing inconvenience. Therefore, this embodiment discloses a label generation and printing method that achieves printing compatibility and Chinese character printing by converting the ZPL format into a JSON object, as shown in the attached figure. Figure 1 As shown, the label generation and printing method specifically includes the following steps.
[0032] Step S1: Obtain the ZPL format file generated by the label designer, download the images in the ZPL format label file to the printer's specified storage location for subsequent label instructions, parse the label content and label control instructions in the ZPL format file, and convert all fields in the label into a first JSON object. The label control instructions include, but are not limited to, label position and configuration printing parameters.
[0033] In this embodiment, step S1 may specifically include:
[0034] Step S11: Parse the ZPL format file into fields of the execution statement, including but not limited to the first field, the second field, the third field, and the fourth field; the first field is the text and graphic field to be displayed when printing, including coordinate position, font size, font type, border thickness, and length; the second field is the printing parameter setting field, containing the printing parameters or strings composed of the parameters; the third field is the image field, configured to parse the ASCII code converted from the image dot matrix.
[0035] Step S12: Convert the execution statement of the ZPL format file into a JSON object according to preset rules. The preset rules are configured to adjust the parsing action according to the recognized character markers. The TOKEN group indicates the default starting group for parsing, the VALUE group indicates that parsing will end when a set symbol is encountered, and the VARSTR group indicates that strings with quotation marks on both sides are parsed and the quotation marks cannot contain specific characters.
[0036] Specifically, the ZPL language file generated and exported by the tag designer is first parsed and converted into a JSON object, laying the foundation for reconstruction. In a specific embodiment, an interpretation file ParserZPL.jj can be created first, and then the javacc tool can be used to generate code. By calling the entry function of the code, the ZPL file can be parsed into fields. For fields to be displayed during printing, such as text and graphics, the fields include coordinate position, font size, font type, border thickness, length, etc. For printing parameter settings, the fields contain various printing parameters or strings composed of various parameters. For image fields, the ASCII codes converted from the image dot matrix need to be parsed, which are equivalent to any character. Parsing will only end when encountering ZPL instruction control characters such as ^ or ~ characters or the character stop character '\0', which is the ASCII null character.
[0037] The parser.jj file defines how to convert configuration or print statements described in the ZPL language into executable code described in a general high-level computer language. Executing this code can transform the ZPL file into a JSON object that can be recognized by any platform environment and language. TOKEN indicates tags in the ZPL file that need to be parsed, and SKIP indicates tags that should be skipped without parsing.
[0038] <default>The `TOKEN` group represents the default group to start parsing. It defines the relationship between all ZPL instructions and some commonly used characters and instruction symbols in high-level computer languages. Unless otherwise specified, parsing of ZPL files always begins from this group. The angle brackets under the curly braces in the `TOKEN` group define the relationship between the instruction symbols generated in the high-level language code and the ZPL tags. It's important to note that the definitions of `TOKEN` groups should not contain each other. For example, if a `TOKEN` of `ANY_CHAR` is defined, a `TOKEN` of an exclamation mark cannot be defined, because `ANY_CHAR` includes the exclamation mark.
[0039] Some angle brackets, i.e., relation groups, are followed by a colon, indicating that after parsing this tag, the parsing will jump to another TOKEN group to continue. For example, the relation group C_FH is followed by "VALUE", which means that after parsing the tag "^FH", the parsing will jump to the "VALUE" TOKEN group to continue. The "VALUE" group means that the parsing will not end until it encounters "^", a newline, or a null character. It is followed by a colon and then "DEFAULT", which means that after the parsing is completed, it returns to the default TOKEN group to continue parsing.
[0040] Additionally, for the VARSTR and VALUEANY TOKEN groups, the VARSTR group indicates that strings enclosed in quotes on both sides must be parsed, and these quotes cannot contain "^", newlines, carriage returns, quotation marks, or null characters. The next group after VARSTR is the DEFAULT group. Within the DEFAULT group, ANY_CHAR defines all other ASCII characters in ZPL, and D_CT defines the start header provided by the ZPL label designer. The parse() function is set as the entry point for parsing; this function parses one or more labels. The label() function parses the label content. download_grafic() downloads the image within the label to the printer's specified storage location before the label parsing begins, allowing subsequent label commands to reference it. Functions starting with control_command parse label control commands, such as controlling the overall label position and configuring printing parameters; these are generally executed before the label format command parsing. The label() tag parsing function consists of three parts: label_start() creates a new tag object and adds it to the object list after encountering the start marker C_XA; the middle part parses each field and can be repeated multiple times; and label_end() ends the parsing of a tag when it encounters the end marker C_XZ.
[0041] Next, the code parses font marker parameters, barcode or QR code marker parameters, and text block marker parameters. Then, it parses the specific content of the fields, including text fields, rectangular border instruction fields, serial number instruction fields, instructions to load images by name, instructions to directly reference images on the printer's storage device, instructions to print changing areas, instructions to draw circles, diagonals, and ellipses, and instructions to directly download and print image data. Through this process, a Java program for parsing ZPL can be generated. This program can then be encapsulated into an API for other applications to call.
[0042] Step S2: Extract the variable names and corresponding values from the second JSON object containing the assigned variables received in the first JSON object, and then replace the variable values after finding the matching variable names in the first JSON object.
[0043] In this embodiment, as shown in the appendix Figure 2 As shown, step S2 may include the following:
[0044] Step S21: Obtain the material name field and its corresponding text box field with variables, as well as the serial number field and its corresponding barcode field with variables from the first JSON object.
[0045] Step S22: Set the tag attribute in the first JSON object to a template tag. The template tag is configured to be stored as a printing template in a designated storage device of the printer and referenced when printing other tags.
[0046] Step S23: The server identifies the variable names in the received second JSON object, which includes each variable name and its corresponding variable replacement value. Based on the variable name, the server searches for the corresponding field in the first JSON object and assigns and modifies it to the variable replacement value.
[0047] By parsing the ZPL file, all fields within the label are ultimately displayed as JSON objects. These objects indicate the coordinates at which text, images, graphics, barcodes, QR codes, and other objects should be displayed, and specify object attributes such as size, orientation, spacing, and thickness. After parsing, variable substitution can be used to print labels with different data based on different variable values provided by the user. Furthermore, these objects or attributes can be used to reconstruct a ZPL file into an image, enabling support on regular printers, not just Zebra printers.
[0048] In this embodiment, the appendix Figure 3 It is a label generated using a label designer that uses the ZPL file format. The text box with a question mark after the material name is associated with the variable matName, the text box with a question mark after the material code is associated with the variable matCode, and there is also a row of question marks below the barcode, indicating that it is also associated with the variable serialNum. The label designer can export the label as a ZPL file.
[0049] The server runs a service program that performs ZPL file parsing, variable substitution, and printing. The user first uploads the ZPL file to the server to be parsed into a JSON object; the `objects` array consists of individual field objects. (See attached image.) Figure 2 The label has the following fields: a "Material Name" field and its corresponding text box field with the variable "matName"; a "Material Code" field and its corresponding text box field with the variable "matCode"; and a "Serial Number" field and its corresponding barcode ^BC field with the variable "serialNum". Before the ^FT mark (the starting mark of the field) are the printer's control instructions and label format instructions, excluding the fields themselves. "^DFR:sample.ZPL^FS" indicates that when this label is sent to the Zebra printer, it is simply saved as the file sample.ZPL to the printer's designated storage device for later use when printing other labels. The style for referencing it is as follows:
[0050] ^XA
[0051] ^XFR:sample.ZPL^FS
[0052] ^FN1^FD Injection^FS
[0053] ^FN2^ FDinjwater ^FS
[0054] FN3^FD112223330088^FS
[0055] ^XZ
[0056] ^XF refers to this tag, and FN1, FN2, and FN3 assign values to these three variables. When this tag is sent to the printer... Figure 1 The question mark in the label shown will be replaced with the corresponding variable data and then printed out.
[0057] In this embodiment, after assigning values to the three variables "matName", "matCode", and "serialNum", the JSON object is as follows:
[0058] {
[0059] matName:"Injection Solution",
[0060] matCode:"injwater",
[0061] serialNum:”112223330088”
[0062] }
[0063] The data is sent to the server. After receiving it, the server finds the variable numbers corresponding to the three variable names, such as FN1, FN2, and FN3, based on the JSON object of the previously parsed ZPL file. The variable values are then extracted to form the aforementioned tag fields.
[0064] Step S3: Convert the Chinese characters in the ZPL format label file into dot matrix images, then convert them into ZPL encoding represented by ASCII symbols, and send the converted image information to the target printer in advance. Add image reference instructions at the corresponding coordinate positions in the first JSON object.
[0065] As shown in the screenshot, even after the variable replacements mentioned above, these ZPL format printers still experience issues such as Chinese character support, resulting in garbled characters appearing in the printed Chinese information on the labels. The current solution is to increase the printer's internal storage space and download and install the corresponding font library. However, font files are quite large, with a single font file potentially reaching 20+ MB, while the printer's internal storage is typically only around 20+ MB. It also needs to store drivers and other operational data, making storing even one font difficult, let alone multiple fonts. Upgrading the printer's storage space and downloading font libraries both significantly increase costs.
[0066] In this embodiment, step S3 may include: converting Chinese characters into a bitmap image, then converting the bitmap image into ZPL encoding represented by ASCII characters as image information, sending the image file to the printer's image information database and storing it, and adding an image information reference instruction at the corresponding coordinate position in the first JSON object.
[0067] The variable type is determined based on the variable name and corresponding value in the second JSON object. If the variable value is in Chinese, the corresponding variable name group is queried in the image information database based on the variable name. The image information location information with the corresponding Chinese name is obtained from the variable name group, and the variable value is replaced with the image information location.
[0068] This embodiment converts Chinese characters into dot-matrix images, and then into ZPL format ZPL encoding represented by ASCII symbols that can be recognized by the printer. After conversion, the ~DG command is used to download these Chinese character graphics to the printer, and then the ^XG command is used to retrieve them at the specified label coordinates. For the printer, this is image printing, but for the user, it achieves the printing of Chinese characters in different font types.
[0069] The process of converting constant Chinese characters into ZPL encoding (ASCII characters) can include the following: In the parsed JSON object, the `objects` array contains three fields with text content "material name", "material code", and "serial number". Each field has two attributes, `fontFamily` and `height`, related to the font name and text size, and a `seqId` indicating the parsing order. During top-to-bottom parsing, fields parsed earlier have smaller `seqId` values, and fields parsed later have larger `seqId` values. After locating these three Chinese descriptions from top to bottom in the ZPL file, the Chinese descriptions and their corresponding fontFamily and height parameter values can be substituted into the interface function based on the seqId. The values of other interface parameters are as follows: text direction orient=0, thickness isBold=0, italic isItalic=0, compression isCompress=0, and font type is changed to fontFamily="SimSun" (depending on requirements). Finally, the Chinese descriptions are converted into ZPL encoding represented by ASCII characters. The statement "~DGOUTSTR10003,1980,22," indicates that the ZPL encoding following it is downloaded to the printer. "OUTSTR10003" represents the alias of this ZPL encoding (Chinese character image), which is convenient for subsequent fields to reference. The reference command is "^XG". Ultimately, you can see that the part in the ZPL file where "^FD material name^FS" is located has been replaced with "^XGOUTSTR10001,1,1^FS", indicating that Chinese images are printed at this location. Similarly, the fields containing "material code" and "serial number" have also been replaced in a similar way.
[0070] Then, the Chinese variables are processed. Based on the variable name and value passed by the user, it's determined whether to replace ^FN1 or ^FN2 with the image referenced by ^XG. ^FN3 indicates that the serial number cannot contain Chinese characters. Assume the data passed to the variables array is as follows:
[0071] {
[0072] matName:"Injection Solution",
[0073] matCode:"injwater",
[0074] serialNum:”112223330088”
[0075] }
[0076] In the final generated ZPL file, "^FN1"matName"" is replaced with "^XGOUTSTR20001,1,1", indicating that the value of the matName variable has been replaced with image data. matCode and serialNum are not replaced; they are replaced in the newly added tags at the bottom of the final generated ZPL file.
[0077] ^XA
[0078] ^XFR:sample.ZPL^FS
[0079] ^FN2^FDinjwater^FS
[0080] ^FN3^FD112223330088^FS
[0081] ^XZ
[0082] This newly added tag indicates that the sample.ZPL tag data is referenced and the variables matCode and serialNum are assigned the values "injwater" and "112223330088" respectively.
[0083] The label generation and printing method disclosed in the above embodiments can be used to preview or convert ZPL files into JSON, and then restore the JSON. This allows printing on a regular printer as well as converting the ZPL file into an image. It also enables customers to print label files designed by a label designer that outputs ZPL format on regular printers that use other file formats. Furthermore, variables can be added to the label, allowing users to transmit specific data during the printing process for dynamic printing.
[0084] In another embodiment, a label generation and printing device is also disclosed, including a parsing module, a variable substitution module, and a Chinese character conversion module. The parsing module is used to obtain a ZPL format file generated by a label designer, download the images within the ZPL format label file to a designated storage location on the printer for subsequent label instructions, parse the label content and label control instructions in the ZPL format file, and convert all fields within the label into a first JSON object. The label control instructions include, but are not limited to, label position and configured printing parameters. The variable substitution module is used to extract the variable names and corresponding values from a received second JSON object containing assigned variables, find the corresponding matching variable name in the first JSON object, and then assign and replace the variable value. The Chinese character conversion module is used to convert the Chinese characters in the ZPL format label file into dot-matrix images, then convert them into ZPL encoding represented by ASCII symbols, and pre-send the converted image information to the target printer, and add image reference instructions at the corresponding coordinate positions in the first JSON object.
[0085] Preferably, the parsing module includes: a field conversion module, used to parse the ZPL format file into fields of the execution statement, including but not limited to a first field, a second field, a third field, and a fourth field; the first field is a text / graphic field to be displayed during printing, including coordinate position, font size, font type, border thickness, and length; the second field is a printing parameter setting field, including printing parameters or strings composed of these parameters; the third field is an image field, configured to parse ASCII codes converted from image dot matrix; and a JSON conversion module, used to convert the execution statement of the ZPL format file into a JSON object according to preset rules, wherein the preset rules are configured to adjust the parsing action based on the recognized character markers, where TOKEN represents the default TOKEN group to start parsing, VALUE represents parsing until a set symbol is encountered, and VARSTR represents parsing strings enclosed in quotation marks on both sides, and the quotation marks cannot contain specific characters.
[0086] Preferably, the variable replacement module is configured to: obtain the material name field and its corresponding text box field with variable, and the serial number field and its corresponding barcode field with variable from the first JSON object; set the label attribute in the first JSON object as a template label, which is configured to be stored as a printing template in a designated storage device of the printer for reference when printing other labels; identify the variable names in the received second JSON object, which includes each variable name and its corresponding variable replacement value; search for the corresponding field in the first JSON object according to the variable name and assign and modify its corresponding value to the variable replacement value.
[0087] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. As for the label generation and printing apparatus disclosed in the embodiments, since it corresponds to the label generation and printing method disclosed in the embodiments, the description is relatively simple, and relevant parts can be referred to the method section.
[0088] In other embodiments, a server is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the various steps of the label generation and printing method as described in the above embodiments.
[0089] The label generation and printing apparatus may include, but is not limited to, a processor and a memory. Those skilled in the art will understand that the schematic diagram is merely an example of a server for label generation and printing and does not constitute a limitation on the label generation and printing apparatus. It may include more or fewer components than illustrated, or combine certain components, or use different components.
[0090] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. This processor is the control center of the server used for label generation and printing, connecting various parts of the server via various interfaces and lines.
[0091] The memory can be used to store the computer programs and / or modules. The processor implements various functions of the server for label generation and printing by running or executing the computer programs and / or modules stored in the memory and calling the data stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function, etc. In addition, the memory may include high-speed random access memory and non-volatile memory, such as hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0092] If the label generation and printing device is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the above embodiments of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various label generation and printing method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.
[0093] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
[0094] In summary, the above description is only a preferred embodiment of the present invention. All equivalent changes and modifications made within the scope of the claims of the present invention should be covered by the present invention.< / default>
Claims
1. A label generation and printing method, characterized in that, Includes the following steps: S1, obtain the ZPL format file generated by the label designer, download the images in the ZPL format label file to the printer's specified storage location for subsequent label instructions to reference, parse the label content and label control instructions in the ZPL format file, and convert all fields in the label into a first JSON object. The label control instructions include, but are not limited to, label position and configuration printing parameters. S2, extract the variable names and corresponding values from the received second JSON object containing the assigned variables, and replace the variable values after finding the corresponding matching variable names in the first JSON object; S3 converts the Chinese characters in the ZPL format label file into dot matrix images, then converts them into ZPL encoding represented by ASCII symbols, and sends the converted image information to the target printer in advance, and adds image reference instructions at the corresponding coordinate positions in the first JSON object.
2. The label generation and printing method according to claim 1, characterized in that, Step S1 includes: The ZPL format file is parsed into fields of the execution statement, including but not limited to the first field, the second field, the third field, and the fourth field; the first field is the text and graphic field to be displayed when printing, including coordinate position, font size, font type, border thickness, and length; the second field is the printing parameter setting field, containing the printing parameters or strings composed of the parameters; the third field is the image field, which is configured to parse the ASCII code converted from the image dot matrix. The execution statements of ZPL format files are converted into JSON objects according to preset rules. The preset rules are configured to adjust the parsing action according to the recognized character markers. The TOKEN group indicates the default starting group for parsing, the VALUE group indicates that parsing will end when a set symbol is encountered, and the VARSTR group indicates that strings with quotation marks on both sides are parsed and the quotation marks cannot contain specific characters. Specific characters include "^", newline, carriage return, quotation marks or null characters.
3. The label generation and printing method according to claim 2, characterized in that, Step S2 includes: Retrieve the material name field and its corresponding text box field with variables, as well as the serial number field and its corresponding barcode field with variables from the first JSON object; Set the tag attribute in the first JSON object to a template tag, which is configured to be stored as a print template in a designated storage device of the printer and referenced when printing other tags; Identify the variable names in the received second JSON object, which includes each variable name and its corresponding replacement value. Search for the corresponding field in the first JSON object based on the variable name and assign and modify its corresponding value to the replacement value.
4. The label generation and printing method according to claim 3, characterized in that, Step S3 includes: After converting Chinese characters into bitmap images, the bitmap images are then converted into ZPL encoding represented by ASCII characters and used as image information. The image file is sent to the printer's image information database and stored. An image information reference instruction is added to the corresponding coordinate position in the first JSON object.
5. The label generation and printing method according to claim 4, characterized in that, Step S3 further includes: determining the variable type based on the variable name and corresponding value in the second JSON object; if the variable value is Chinese, querying the corresponding variable name group in the image information database based on the variable name, obtaining the image information location information of the corresponding Chinese name in the variable name group, and replacing the variable value with the image information location.
6. A label generating and printing apparatus, characterized in that, include: The parsing module is used to obtain the ZPL format file generated by the label designer, download the images in the ZPL format label file to the printer's specified storage location for subsequent label instructions to reference, parse the label content and label control instructions in the ZPL format file, and convert all fields in the label into a first JSON object. The label control instructions include, but are not limited to, label position and configuration printing parameters. The variable replacement module is used to extract the variable names and corresponding values from the received second JSON object containing the assigned variables, and then replace the variable values after finding the corresponding matching variable names in the first JSON object. The Chinese character conversion module is used to convert Chinese characters in ZPL format label files into bitmap images, then convert them into ZPL encoding represented by ASCII symbols, and pre-send the converted image information to the target printer, and add image reference instructions at the corresponding coordinate positions in the first JSON object.
7. The label generating and printing apparatus according to claim 6, characterized in that, The parsing module includes: The field conversion module is used to parse ZPL format files into fields of executable statements, including but not limited to the first field, the second field, the third field, and the fourth field; the first field is the text and graphic field to be displayed during printing, including coordinate position, font size, font type, border thickness, and length; the second field is the printing parameter setting field, containing the printing parameters or a string composed of the parameters; the third field is the image field, configured to parse ASCII codes converted from image dot matrix. The JSON conversion module is used to convert the execution statements of ZPL format files into JSON objects according to preset rules. The preset rules are configured to adjust the parsing action according to the recognized character markers. The TOKEN group indicates the default starting group for parsing, the VALUE group indicates that parsing will end when a set symbol is encountered, and the VARSTR group indicates that strings with quotation marks on both sides cannot contain specific characters. Specific characters include "^", newline, carriage return, quotation marks, or null characters.
8. The label generating and printing apparatus according to claim 7, characterized in that, The variable replacement module is configured to obtain the material name field and its corresponding text box field with variable, as well as the serial number field and its corresponding barcode field with variable from the first JSON object; set the label attribute in the first JSON object as a template label, which is configured to be stored as a printing template in a designated storage device of the printer for reference when printing other labels; identify the variable names in the received second JSON object, which includes each variable name and its corresponding variable replacement value; search for the corresponding field in the first JSON object according to the variable name and assign and modify its corresponding value to the variable replacement value.
9. A server comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1-5.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1-5.
Citation Information
Patent Citations
Printer programming tool and method
CA2386843A1
Realization method for cross-platform high-speed thermal printer on intelligent terminal
CN107885465A