Printing method and device for generating label picture based on configuration, terminal and storage medium

By acquiring the label definition configuration file and the data to be filled from the external data source, and using arbitration rules to handle data conflicts and automatically adjust the layout, the problems of data inconsistency and unreasonable layout in the label printing system are solved, achieving accurate label content and personalized printing, and improving enterprise operational efficiency.

CN121600104APending Publication Date: 2026-03-03SUZHOU HANMA INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511542174.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-27
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

In existing enterprise information systems, label printing systems face problems such as data conflict risks, static templates being unable to flexibly handle dynamic content, and slow response to personalized needs, resulting in inaccurate label information and unreasonable layout, as well as high modification costs.

Method used

By acquiring the label definition configuration file and the data to be filled from the external data source, arbitration rules are used to handle data conflicts, the initial pixel layout is calculated and layout conflicts are detected, the optimized layout is automatically adjusted and generated, and finally the label image is synthesized to achieve personalized printing.

Benefits of technology

It achieves accuracy in label content and automatic layout adjustment, meets the integration needs of enterprise information systems and label printing systems, improves operational efficiency, reduces labor costs, and supports personalized market demands.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121600104A_ABST
    Figure CN121600104A_ABST
Patent Text Reader

Abstract

The invention discloses a printing method and device for generating a label picture based on configuration, a terminal and a storage medium, and relates to the field of data processing and image generation, and the method comprises the steps: obtaining a label definition configuration file and to-be-filled data, processing data conflicts, determining target data, calculating an initial pixel layout, and detecting layout conflicts. If conflicts exist, adjusting and generating a final layout, and finally synthesizing and outputting a final label picture according to the final layout. The technical effects of effectively processing data conflicts and layout conflicts and automatically generating and outputting high-quality final label pictures are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of data processing and image generation, and in particular to a method, apparatus, terminal, and storage medium for generating label images based on configuration. Background Technology

[0002] In enterprise operations, information systems such as Enterprise Resource Planning (ERP) and Manufacturing Execution System (MES) need to be integrated with label printing systems to automate product identification and logistics management. Current technologies generally use predefined static label templates, generating labels by acquiring data from a single data source and populating it. However, with the deepening of enterprise informatization and the growth of personalized market demands, this traditional method faces serious challenges.

[0003] First, there is a risk of data conflict. Data for the same tag element (such as batch number) may come from multiple business systems and conflict with each other. Relying on manually specifying a single data source is inefficient and prone to inaccurate tag information due to the use of incorrect data, affecting quality traceability.

[0004] Secondly, fixed static label templates cannot flexibly handle dynamic content such as changes in text length and multilingual switching, easily leading to problems such as content overlap, truncation, or unrecognizable barcodes. Manual and repeated template adjustments are required, making intelligent layout adaptation impossible and ensuring label visual compliance costly.

[0005] In addition, the market has an increasingly strong demand for personalized product labels, but each modification to static templates involves code adjustments or professional software operations, which is cumbersome and time-consuming, and cannot quickly respond to customers' needs for customized label content and style through simple configuration.

[0006] Therefore, there is an urgent need in the field for a label printing method that can automatically arbitrate multi-source data, intelligently adapt to dynamic content layouts, and respond quickly based on configuration, in order to systematically address the shortcomings of existing technologies in terms of data accuracy, layout adaptability, and personalized agile response. Summary of the Invention

[0007] The purpose of this application is to overcome the above-mentioned technical problems and provide a printing method, apparatus, terminal and storage medium for generating label images based on configuration.

[0008] Firstly, this application provides a method for generating label images based on configuration for printing, employing the technical solution described below: A method for generating label images based on configuration and printing includes the following steps: Obtain a label definition configuration file and data to be populated from at least one preset external data source. The label definition configuration file includes label size, printing parameters, and at least one label element definition. When a data conflict is detected for the same tag element, arbitration is conducted according to the preset arbitration rules to determine the target data; Calculate the initial pixel layout of the canvas and each of the label elements according to the label definition configuration file; generate the estimated visual content of each of the label elements based on the target data and detect whether there are layout conflicts in the initial pixel layout; If the layout conflict exists, the initial pixel layout of the detected conflicting tag elements is automatically adjusted to generate an optimized final layout. Based on the final layout, the visual content is composited onto the canvas to generate and output the final label image.

[0009] By adopting the above technical solution, label configuration and data to be filled can be obtained from different data sources, data conflicts can be resolved to determine target data, the initial pixel layout can be calculated and layout conflicts can be detected, conflicting elements can be automatically adjusted to generate an optimized layout, and finally the label image can be synthesized and output. This enables the automatic generation and printing of label images based on the configuration, meets the integration requirements of enterprise information systems and label printing systems, can generate complete label content based on information from different data sources, and can also achieve personalized label printing by adjusting the configuration to meet the personalized needs of the market.

[0010] Preferably, obtaining the tag definition configuration file and the data to be populated from at least one preset external data source specifically includes the following steps: Read the label definition configuration file, which includes label size, printing parameters, and at least one label element definition, which includes label element type and initial layout parameters; Based on the preset data source connection information, a connection is established with at least one external data source, the original data to be filled is obtained from the external data source, the data field value corresponding to each of the tag elements is extracted from the original data to be filled, and the data field value is used as the data to be filled for the corresponding tag element definition.

[0011] By adopting the above technical solution, the label definition configuration file containing information such as label size, printing parameters, label element type, and initial layout parameters can be read, providing a basic configuration for subsequent label image generation. By establishing a connection with the external data source based on the preset data source connection information and extracting the corresponding data field values, the data to be filled for generating label elements can be accurately obtained, ensuring the accuracy and completeness of subsequent label image generation.

[0012] Preferably, when a data conflict is detected for the same tag element, arbitration is performed according to preset arbitration rules to determine the target data, specifically including the following steps: For the same tag element definition, the data to be filled obtained from different external data sources are compared; when there are at least different data to be filled, it is determined that the current corresponding tag element has a data conflict. When the data conflict is detected, a preset arbitration rule is invoked to select different data to be filled to obtain target data. The target data is the final data used to generate the estimated visual content of the current tag element.

[0013] By adopting the above technical solution, it is possible to compare the data to be filled for the same tag element definition obtained from different external data sources, determine whether there is a data conflict, and when a data conflict is detected, a preset arbitration rule can be called to select the target data, providing accurate and unified data for generating the estimated visual content of the tag element, avoiding errors or confusion in the tag content caused by inconsistent data, and ensuring the accuracy and reliability of the final tag image generation.

[0014] Preferably, the step of invoking a preset arbitration rule to select different data to be filled to obtain target data includes the following steps: Each external data source is assigned a priority level. When a data conflict occurs, the data to be filled provided by the external data source with the highest priority level is adopted as the target data. Alternatively, compare the timestamps corresponding to conflicting data to be filled from different external data sources, and adopt the data to be filled with the latest timestamp as the target data; Alternatively, check all conflicting data to be filled and adopt the first non-empty data or data that conforms to a preset valid format as the target data; Alternatively, a confidence weight can be calculated for each conflicting piece of data to be filled, and the piece of data to be filled with the highest weighted average can be adopted as the target data.

[0015] By adopting the above technical solution, when there are conflicts between the data to be filled for the same tag element from different external data sources, the target data can be selected according to various rules such as preset priority level, timestamp, data validity or confidence weight, so as to ensure that the data used to generate the estimated visual content of the tag element is accurate and reliable, and improve the accuracy and quality of the final tag image generation.

[0016] Preferably, the step of calculating the initial pixel layout of the canvas and each of the tag elements according to the tag definition configuration file, generating the visual content of each of the tag elements based on the target data, and detecting whether there are layout conflicts in the initial pixel layout specifically includes the following steps: Calculate the canvas pixel size required to generate the final label image based on the label size and the printing resolution in the printing parameters; Based on the print resolution and the initial layout parameters defined in each of the label elements, the initial pixel position and initial pixel size of each label element on the canvas are calculated, which together constitute the initial pixel layout of the canvas. Based on the target data determined for each of the tag elements and the corresponding tag element type, the corresponding element processor is called to generate the estimated visual content corresponding to each of the tag elements, and the actual pixel size of each of the estimated visual contents is obtained. The actual pixel size of each estimated visual content is combined with the initial pixel layout to determine the actual area occupied by each estimated visual content on the canvas. Based on the preset layout rules, it is determined whether there is a layout conflict in the actual occupied area.

[0017] By adopting the above technical solution, the canvas pixel size is calculated based on the label size and printing resolution. The initial pixel layout is determined by combining the initial layout parameters in the label element definition, which provides an accurate canvas basis for the subsequent generation of label images. Based on the target data and label element type, the element processor is called to generate estimated visual content and obtain the actual pixel size, which can yield element visual content that meets the actual needs. The actual pixel size of the estimated visual content is combined with the initial pixel layout to determine the actual occupied area. Based on the preset layout rules, it is determined whether there are layout conflicts. This can detect layout problems in advance, prepare for subsequent layout optimization, and ensure that the final generated label image has a reasonable layout.

[0018] Preferably, the step of automatically adjusting the initial pixel layout of the detected conflicting tag elements to generate an optimized final layout if a layout conflict exists specifically includes the following steps: Based on the detected layout conflicts, all conflicting tag elements that need to be adjusted are identified, forming a set of conflicting elements; based on the tag element type of each conflicting tag element in the set of conflicting elements, the adjustment strategy for the conflicting tag elements is determined. The adjustment strategy is used to calculate the new first layout parameters of the corresponding conflicting tag element in the final layout. The first layout parameters include the first pixel position or the first visual content size. The initial pixel layout is updated based on the first layout parameters of all the conflicting tag elements to generate the optimized final layout.

[0019] By adopting the above technical solution, the label definition configuration file and the data to be filled can be obtained. When a data conflict is detected, the target data is determined by arbitration. The initial pixel layout of the canvas and label elements and the estimated visual content are calculated and layout conflicts are detected. When there is a layout conflict, the conflicting label elements are identified to form a set. The adjustment strategy is determined according to the element type, new layout parameters are calculated, the initial pixel layout is updated to generate an optimized final layout, and then the final label image with no layout conflict and reasonable layout is synthesized and output based on the final layout.

[0020] Preferably, the step of compositing the visual content onto the canvas based on the final layout to generate and output the final label image specifically includes the following steps: Based on the tag element type of each tag element in the final layout, the corresponding target data, and the first layout parameters, a corresponding bitmap image is generated, and the bitmap image is used as the final visual content of the current tag element. Based on the hierarchical information of each tag element contained in the final layout, the final visual content corresponding to all tag elements is sorted to determine the order in which they are composited onto the canvas. According to the determined sequence, based on the first pixel position of the tag element corresponding to each final visual content in the final layout, each final visual content is sequentially drawn onto the canvas; The final drawn canvas is encoded into a bitmap file and output, and the bitmap file is the final label image.

[0021] By adopting the above technical solution, the label definition configuration file and the data to be filled can be obtained. When a data conflict is detected, the target data is determined by arbitration. The initial pixel layout of the canvas and label elements and the estimated visual content are calculated and layout conflicts are detected. When there is a layout conflict, the conflicting label elements are identified to form a set. The adjustment strategy is determined according to the element type, new layout parameters are calculated, the initial pixel layout is updated to generate an optimized final layout, and then the final label image with no layout conflict and reasonable layout is synthesized and output based on the final layout.

[0022] Secondly, this application provides a printing device for generating label images based on configuration, employing the following technical solution: A printing device for generating label images based on configuration includes the following modules: The configuration and data acquisition module is used to acquire the label definition configuration file and the data to be filled from at least one preset external data source. The label definition configuration file includes the label size, printing parameters and at least one label element definition. The data arbitration module is used to arbitrate and determine the target data according to preset arbitration rules when a data conflict is detected for the same tag element. The layout calculation module is used to calculate the initial pixel layout of the canvas and each of the label elements according to the label definition configuration file; generate the estimated visual content of each of the label elements based on the target data and detect whether there is a layout conflict in the initial pixel layout; The layout optimization module is used to automatically adjust the initial pixel layout of the detected conflicting tag elements and generate an optimized final layout if the layout conflict exists. The label image synthesis module is used to synthesize various visual contents onto the canvas according to the final layout, and generate and output the final label image.

[0023] By adopting the above technical solutions, the configuration and data acquisition module can obtain the label definition configuration file and the data to be filled from the external data source, providing a foundation for the subsequent generation of label images; the data arbitration module can resolve data conflicts of the same label element, ensuring that appropriate data is used to generate labels; the layout calculation module can calculate the initial pixel layout, generate estimated visual content, and detect layout conflicts; the layout optimization module can automatically adjust conflicting label elements when layout conflicts exist, generating an optimized final layout; the label image synthesis module synthesizes and outputs the final label image based on the final layout, realizing the function of generating and printing label images based on configuration, meeting the needs of enterprise information system and label printing system integration and personalized label printing.

[0024] Thirdly, this application provides a smart terminal, which adopts the following technical solution: A smart terminal includes a memory and a processor. The memory stores at least one instruction, at least one program, code set, or instruction set. The at least one instruction, at least one program, code set, or instruction set is loaded and executed by the processor to implement the configuration-based label image printing method described above.

[0025] Fourthly, this application provides a computer-readable storage medium, which adopts the following technical solution: A computer-readable storage medium storing at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, at least one program, code set, or instruction set is loaded and executed by a processor to implement the configuration-based label image printing method described above.

[0026] In summary, this application has at least the following beneficial effects: (1) This application integrates the information system and the label printing system, which can generate and print labels based on the data in the system, thereby improving the efficiency of enterprise operation and reducing labor costs; (2) This application can handle data conflicts according to the preset arbitration rules to ensure the accuracy of the data generated for the label images; (3) This application can automatically detect and adjust layout conflicts, generate an optimized final layout, realize automatic adjustment and optimization of label content and layout, and meet the personalized needs of the market. Attached Figure Description

[0028] Figure 1 This is a flowchart of a method for generating label images based on configuration for printing; Figure 2 This is a structural diagram of a printing device that generates label images based on configuration. Detailed Implementation

[0029] This application provides a printing method, apparatus, terminal, and storage medium for generating label images based on configuration. To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be further described in detail below.

[0030] The following describes in further detail an embodiment of a printing method for generating label images based on configuration, in conjunction with the accompanying drawings.

[0031] This application discloses a method for generating label images based on configuration for printing, the process of which is as follows: Figure 1 As shown, it includes the following steps: S1. Obtain the label definition configuration file and the data to be populated from at least one preset external data source. The label definition configuration file includes label size, printing parameters, and at least one label element definition, specifically including the following steps: S11. Read the tag definition configuration file from the local file system, network server, or configuration database. In this embodiment, the configuration file is in JSON, XML, or YAML format. The tag definition configuration file includes tag size, printing parameters, and at least one tag element definition. The tag element definition includes tag element type and initial layout parameters.

[0032] Using a parsing library that corresponds to the format of the tag definition configuration file, the configuration file content is parsed into a structured data object in memory, and the tag physical size, printing parameters, and multiple tag element definitions are extracted from the structured data object.

[0033] In this embodiment, a label element refers to an independent visual component on a label that has a specific type, content, and function. Each label element is described as an independent label element definition in the label definition configuration file. Label elements include a text field and a barcode frame.

[0034] In this embodiment, the label element type in the label element definition includes at least one of text, barcode, QR code, graphic, or image.

[0035] The initial layout parameters include at least one of the following: element position coordinates, element size, rotation angle, and hierarchy information, expressed in physical units or pixels.

[0036] S12. Based on the preset data source connection information, establish a connection with at least one external data source, including a database, enterprise resource planning system, manufacturing execution system, or application programming interface; and execute predefined query statements or requests.

[0037] S13. Obtain the original data to be filled from the external data source. Extract the data field values ​​corresponding to the definition of each tag element from the original data to be filled, and use the data field values ​​as the data to be filled for the corresponding tag element definition.

[0038] This embodiment includes interfaces for reading external data sources with different configurations, such as JSON, XML, databases, and text files. For JSON and XML files, appropriate parsing libraries are used, such as the json library and xml.etree.ElementTree library in Python, to read and parse the file content into in-memory data structures, such as dictionaries or element tree objects.

[0039] S2. When a data conflict is detected for the same tag element, arbitration is performed according to the preset arbitration rules to determine the target data, specifically including the following steps: S21. For the same tag element definition, compare the data to be filled from different external data sources. The data to be filled is the data obtained from external data sources that needs to be dynamically filled into the tag element definition to form specific visual content. Its content determines the specific display content of the visual element, such as the specific string of a text element, the encoded data of a barcode element, or the image source identifier of an image element.

[0040] In one specific implementation, for example, a text-type tag element definition specifies the font as SimSun and the color as black in its element-specific parameters. In this case, the string 'Product A-001' obtained from the ERP system is the data to be filled corresponding to this tag element definition.

[0041] S22. When there are two or more different data to be filled, it is determined that there is a data conflict in the current corresponding tag element.

[0042] In this embodiment, data conflicts in the data to be filled must meet the following three conditions: First, they must be defined for the same tag element, which means that the conflict occurs in the competition for the same tag position, such as product name; second, they must come from different external data sources, because inconsistencies in data from the same data source are usually considered data errors rather than conflicts between systems; third, the data to be filled must be distinct and valid. Distinction is a direct manifestation of conflict, and validity is to exclude null values, NULL, or obviously formatted data, ensuring that data arbitration is conducted among meaningful candidate data to be filled.

[0043] S23. When a data conflict is detected, the preset arbitration rules are invoked to select different data to be filled to obtain the target data. The target data is the final data used to generate the estimated visual content of the current tag element.

[0044] In this embodiment, preset arbitration rules are invoked to select different data to be filled to obtain target data, including the following arbitration solutions: A. Priority Arbitration: Preset priority levels for each external data source. When a data conflict occurs, the data to be populated provided by the external data source with the highest priority level will be adopted as the target data. B. Timeliness Arbitration: Compare the timestamps of conflicting data to be populated from different external data sources, and adopt the data with the latest timestamp as the target data; C. Validity Arbitration: Check all conflicting data to be filled and adopt the first non-empty data or data that conforms to the preset valid format as the target data; D. Weighted decision arbitration: Calculate the confidence weight for each conflicting data point to be filled, and adopt the data point to be filled with the highest weighted average as the target data.

[0045] The confidence weight can be calculated based on the historical reliability score of the data source, the integrity of the data itself, or the age of the data.

[0046] S3. Calculate the initial pixel layout of the canvas and each tag element according to the tag definition configuration file; generate the estimated visual content of each tag element based on the target data and detect whether there are layout conflicts in the initial pixel layout, specifically including the following steps: S31. Calculate the canvas pixel size required to generate the final label image based on the label size and the printing resolution in the printing parameters.

[0047] In this embodiment, after determining the target data through data interpolation, the original configuration parameters defined in physical units are not used directly. Instead, a unified intermediate data model in pixels is constructed for subsequent layout calculations and image generation.

[0048] First, convert the physical dimensions to pixel values ​​using the following formula: Pixel value = millimeter value × DPI / 25.4; 25.4 is the conversion constant between inches and millimeters.

[0049] Perform canvas size conversion for the final label image: Calculate the pixel size of the label canvas based on the physical length and width of the label in the label definition configuration file, combined with the DPI value in the printing parameters.

[0050] This embodiment uses an image processing library, such as Python's PIL library or other suitable libraries, to create a blank base image object based on the length and width pixel values ​​of the label. The background color can be determined according to default settings or configuration parameters.

[0051] Perform position and size conversion for tag elements: For each tag element defined in the tag definition configuration file, convert its position (X, Y) and size in the initial layout parameters to pixel values ​​according to the above formula.

[0052] For example, for a 50mm×30mm label, at 300 DPI, the canvas width is approximately (50×300 / 25.4)≈591 pixels and the height is approximately (30×300 / 25.4)≈354 pixels.

[0053] After completing all necessary unit conversions, the system constructs a standardized intermediate configuration object in memory, which serves as the standard data source for all subsequent processing flows and contains the following key properties: label_length_px: The converted label length in pixels, used to create the canvas.

[0054] label_width_px: The converted label width in pixels, used to create the canvas.

[0055] print_dpi: Prints the DPI value in the parameters, which is reserved for reference.

[0056] print_speed: Print speed parameter, reserved for reference.

[0057] `label_elements`: An ordered list containing the transformed definitions of all label elements. Each element in the list is an object describing all pixel-level information of that label element, and each label element object includes the following properties: element_type: The type of element, such as text, barcode, QR code, or image.

[0058] x_px: The X-pixel coordinate of the converted element position.

[0059] y_px: The Y-pixel coordinate of the converted element position.

[0060] width_px / height_px: The pixel dimensions of the element after conversion.

[0061] layer: Element hierarchy, used to determine the top-to-bottom overlapping relationship of elements during composition.

[0062] `element_specific_params`: A parameter object specific to the element type. For example, for a text element, this object might contain attributes such as font, font size, and color; for a barcode element, it might contain attributes such as code type and encoded data.

[0063] S32. Based on the printing resolution and the initial layout parameters defined in each label element, calculate the initial pixel position and initial pixel size of each label element on the canvas, which together constitute the initial pixel layout of the canvas.

[0064] The system iterates through each tag element definition in the configuration file. For each tag element, it uses the unit conversion formula mentioned above to convert its initial layout parameters to obtain the initial pixel position (x_px, y_px) and initial pixel size (width_px, height_px) on the canvas.

[0065] The pixel-level information of all the tag elements together constitutes an initial pixel layout, representing the preset position and size of each tag element on the canvas under ideal conditions.

[0066] S33. Based on the target data and corresponding tag element type determined for each tag element.

[0067] In this step, the previously determined target data is combined with the corresponding tag elements.

[0068] The system maintains an element type mapping table, which maps different element types, such as text, barcode, QR code, and image, to corresponding processing classes.

[0069] For example, if the element type is text, it is mapped to the Text Element Processor class; if it is a barcode, it is mapped to the Barcode Element Processor class, and so on. S34. Call the corresponding element processor to generate the estimated visual content for each tag element, and obtain the actual pixel size of each estimated visual content.

[0070] The corresponding processing class is instantiated based on the element type of each tag element, and its pre-rendering method is called. This pre-rendering method generates an estimated visual content, i.e., a temporary image object, in memory based on the specific parameters of the tag element, such as the font, font size, and color of the text, or the encoding type and data of the barcode.

[0071] Once generated, immediately retrieve the actual pixel dimensions occupied by the temporary image object. For text elements, even with the same font and size, the actual width of different character content will differ, such as ABC versus ABCDEFG.

[0072] S35. Combine the actual pixel size of each estimated visual content with the initial pixel layout to determine the actual area occupied by each estimated visual content on the canvas.

[0073] The actual pixel size of each visual content obtained in step S33 is combined with the initial pixel position in the initial pixel layout calculated in step S32 to calculate the actual area occupied by each visual content on the canvas. This area is usually a rectangular area.

[0074] S36. Based on the preset layout rules, determine whether there are any layout conflicts in the actual occupied area.

[0075] In this embodiment, according to the preset layout rules, all actually occupied areas are traversed and compared to detect whether one or more of the following layout conflicts exist.

[0076] A. Area overlap conflict: Based on the element avoidance rules, determine whether there is an intersection between the boundary rectangles of any two actual occupied areas.

[0077] B. Boundary Conflict: Based on the boundary constraint rules, determine whether any actually occupied area exceeds the canvas boundary calculated in step S31.

[0078] C. Spacing Conflict: Based on the element spacing rules, determine whether the minimum distance between any two actual occupied areas is less than the minimum safe spacing required in the configuration file.

[0079] Through the aforementioned pre-rendering and conflict detection mechanisms, layout problems caused by dynamic changes in data content can be detected and located in advance before the final image is actually synthesized. This provides accurate input for subsequent intelligent adjustments, avoids printing failures or incomplete label information due to layout errors, and thus significantly improves the reliability and intelligence level of the system.

[0080] S4. If layout conflicts exist, automatically adjust the pixel position of the detected conflicting tag elements or the estimated size of the visual content to generate an optimized final layout. This includes the following steps: S41. Based on the detected layout conflicts, identify all conflicting tag elements that need to be adjusted, forming a set of conflicting elements.

[0081] In this embodiment, output from the layout conflict detection step is received, which identifies specific pairs or groups of tag elements that have overlapping, boundary crossing, or spacing conflicts. This conflict information is traversed to identify all involved tag elements and group them into a conflict element set.

[0082] This set of conflicting elements constitutes the direct object of this layout adjustment. It is important to note that when constructing the set, the hierarchy of tag elements defined in the configuration file needs to be confirmed to ensure that, in subsequent adjustments, higher-level tag elements visually take precedence over lower-level tag elements.

[0083] S42. Process each conflicting tag element in the conflicting element set in parallel. Based on the tag element type of each conflicting tag element, assign a parallel adjustment strategy to the conflicting tag element from a predefined strategy mapping table. The strategy mapping table defines one or more strategies applicable to different types of elements, including at least one of position movement strategy, size scaling strategy, and content rearrangement strategy.

[0084] For example, in this embodiment, a position shifting strategy is usually adopted for barcode and QR code type label elements because their size is usually strictly regulated and cannot be arbitrarily scaled.

[0085] For text-type tag elements, content reflow strategies, such as automatic line wrapping, are preferred. If conflicts still exist after reflow, size scaling strategies or position shifting strategies are then adopted.

[0086] For graphic or image elements, a position shifting strategy can be used, and a size scaling strategy can also be used if the configuration allows.

[0087] The parallel processing mechanism described above ensures the efficient allocation of adjustment strategies, laying the foundation for subsequent calculations.

[0088] S43. Calculate the new first layout parameters for each conflicting tag element in the final layout based on the adjustment strategy assigned to it. The first layout parameters include the first pixel position or the first visual content size.

[0089] In this embodiment, if the adjustment strategy is a position movement strategy, then a nearest legal position that satisfies the layout rules is found in the canvas space, and the first pixel position of that position is calculated. The layout rules include element avoidance rules, boundary constraint rules, and element spacing rules.

[0090] If the adjustment strategy is a size scaling strategy, then the new first visual content size of the element is calculated proportionally based on the available space and the minimum readable size of the element.

[0091] If the adjustment strategy is to a content reflow strategy, it should be noted that the content reflow strategy only applies to text element types. It uses font measurement information to recalculate the line break position and total height of the text within the constrained width, thereby generating a new text image and its corresponding size.

[0092] S44. Update the initial pixel layout based on the first layout parameters of all conflicting tag elements to generate an optimized final layout.

[0093] In this embodiment, the first layout parameters calculated from all conflicting label elements are collected and integrated with the initial layout parameters of those non-conflicting label elements. These parameters are then used to update the layout description object, generating a completely new, optimized final layout that eliminates all detected conflicts. This final layout will be used as input in subsequent image compositing steps to drive the generation of the final label image.

[0094] S5. Based on the final layout, composite all visual content onto the canvas, generate and output the final label image, specifically including the following steps: S51. Based on the tag element type of each tag element in the final layout, the corresponding target data obtained after arbitration, and the first layout parameters, generate the corresponding bitmap image in memory, and use the bitmap image as the final visual content of the current tag element.

[0095] For each tag element, a corresponding bitmap image is generated in memory based on its unique and common parameters. For example, the image generation method of the Text Element Processor class uses an image processing library to draw a text image based on parameters such as text content, font, font size, and color; while the image generation method of the Barcode Element Processor class generates a barcode image based on the barcode type and encoding data.

[0096] In this embodiment, it is necessary to distinguish between estimated visual content and final visual content. Estimated visual content is a simulated visual representation generated during the layout conflict detection stage to calculate the actual area occupied by elements; final visual content is a specific bitmap image generated during the image compositing stage based on the final layout and target data.

[0097] S52. Based on the hierarchy information of each tag element contained in the final layout, sort the final visual content corresponding to all tag elements to determine the order in which they are composited onto the canvas; the higher the hierarchy value of an element, the later it is composited, so that it visually covers the lower hierarchy elements.

[0098] S53. Following the determined sequence, based on the first pixel position of the label element corresponding to the final visual content in the final layout, draw or overlay this bitmap image onto a pre-created blank canvas with the final pixel size of the label, and perform the drawing operation of each final visual content in sequence according to the above steps.

[0099] This process uses image processing libraries such as paste or alpha_composite to ensure that each element is placed precisely in the correct position.

[0100] S54. Once the final visual content of all label elements has been composited onto the canvas, a complete label image is generated in memory. An image encoder is then called to encode the final drawn canvas into a standard bitmap file, such as PNG or JPEG.

[0101] After encoding is complete, perform at least one of the following operations according to the preset output configuration: Save the bitmap file to a specified path on the local file system or network storage; The bitmap file is sent to the designated printing device for physical printing via the print driver or network printing protocol.

[0102] Based on the same inventive concept described above, this application also discloses a printing device for generating label images based on configuration, the architecture of which is as follows: Figure 2 As shown, the device includes the following modules: The configuration and data acquisition module is used to acquire the label definition configuration file and the data to be filled from at least one preset external data source. The label definition configuration file includes the label size, printing parameters and at least one label element definition. The data arbitration module is used to arbitrate and determine the target data according to preset arbitration rules when a data conflict is detected for the same tag element. The layout calculation module is used to calculate the initial pixel layout of the canvas and each tag element according to the tag definition configuration file; generate the estimated visual content of each tag element based on the target data and detect whether there are layout conflicts in the initial pixel layout; The layout optimization module is used to automatically adjust the pixel position of the detected conflicting label elements or the estimated size of the visual content if layout conflicts exist, and generate an optimized final layout. The label image compositing module is used to composite various visual contents onto the canvas based on the final layout, generating and outputting the final label image.

[0103] In a specific feasible implementation, the configuration and data acquisition module includes the following units: The first configuration and data acquisition unit is used to read the label definition configuration file. The label definition configuration file includes label size, printing parameters and at least one label element definition. The label element definition includes label element type and initial layout parameters. The second configuration and data acquisition unit is used to establish a connection with at least one external data source according to the preset data source connection information, obtain the original data to be filled from the external data source, extract the data field value corresponding to the definition of each tag element from the original data to be filled, and use the data field value as the data to be filled for the corresponding tag element definition.

[0104] In one specific implementation scheme, the data arbitration module includes the following units: The first data arbitration unit is used to compare the data to be filled from different external data sources for the same tag element definition; when there are two or more different data to be filled, it is determined that there is a data conflict in the current corresponding tag element. The second data arbitration unit is used to select target data from different data to be filled by calling preset arbitration rules when a data conflict is detected. The target data is the final data used to generate the estimated visual content of the current label element.

[0105] In one specific implementation scheme, the second data arbitration unit includes the following sub-units: The data arbitration subunit is used to preset a priority level for each external data source. When a data conflict occurs, the data to be filled provided by the external data source with the highest priority level is adopted as the target data. Alternatively, compare the timestamps of conflicting data to be populated from different external data sources and adopt the data with the latest timestamp as the target data; Alternatively, check all conflicting data to be filled and adopt the first non-empty data or data that conforms to the preset valid format as the target data; Alternatively, a confidence weight can be calculated for each conflicting data point to be filled, and the data point to be filled with the highest weighted average can be adopted as the target data.

[0106] In one specific implementation scheme, the layout computing module includes the following units: The first layout calculation unit is used to calculate the canvas pixel size required to generate the final label image based on the label size and the printing resolution in the printing parameters; The second layout calculation unit is used to calculate the initial pixel position and initial pixel size of each label element on the canvas according to the printing resolution and the initial layout parameters in the definition of each label element, so as to jointly form the initial pixel layout of the canvas. The third layout calculation unit is used to call the corresponding element processor to generate the estimated visual content corresponding to each tag element based on the target data determined for each tag element and the corresponding tag element type, and to obtain the actual pixel size of each estimated visual content. The fourth layout calculation unit is used to combine the actual pixel size of each estimated visual content with the initial pixel layout to determine the actual area occupied by each estimated visual content on the canvas, and to determine whether there is a layout conflict in the actual occupied area according to the preset layout rules.

[0107] In a specific feasible implementation, the layout optimization module includes the following units: The first layout optimization unit is used to identify all conflicting tag elements that need to be adjusted based on the detected layout conflicts, and form a set of conflicting elements. The second layout optimization unit is used to determine the adjustment strategy for conflicting tag elements based on the tag element type of each conflicting tag element in the conflicting element set. The third layout optimization unit is used to calculate the new first layout parameters of the corresponding conflicting tag elements in the final layout according to the adjustment strategy. The first layout parameters include the first pixel position or the first visual content size. The fourth layout optimization unit is used to update the initial pixel layout based on the first layout parameters of all conflicting tag elements, and generate an optimized final layout.

[0108] In one specific implementation scheme, the label image synthesis module includes the following units: The first label image synthesis unit is used to generate a corresponding bitmap image based on the label element type, corresponding target data and first layout parameters of each label element in the final layout, and use the bitmap image as the final visual content of the current label element. The second label image compositing unit is used to sort the final visual content corresponding to all label elements according to the hierarchical information of each label element contained in the final layout, and determine the order in which they are composited onto the canvas. The third tag image composition unit is used to draw each final visual content onto the canvas in a determined order, based on the first pixel position of the tag element corresponding to each final visual content in the final layout. The fourth label image compositing unit is used to encode the finally drawn canvas into a bitmap file and output it. The bitmap file is the final label image.

[0109] Based on the same inventive concept described above, this application also discloses a smart terminal, including a memory and a processor. The memory stores at least one instruction, at least one program, code set, or instruction set. The at least one instruction, at least one program, code set, or instruction set is loaded and executed by the processor to implement the printing method for generating label images based on configuration as described above.

[0110] Based on the same inventive concept described above, this application also discloses a computer-readable storage medium storing at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, at least one program, code set, or instruction set is loaded and executed by a processor to implement the configuration-based label image printing method described above.

[0111] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in the computer-readable storage medium, which includes, for example, various media capable of storing program code such as: USB flash drive, portable hard drive, read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk.

[0112] The above description is merely an optional embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A method for printing label images based on configuration generation, characterized in that, Includes the following steps: Obtain a label definition configuration file and data to be populated from at least one preset external data source. The label definition configuration file includes label size, printing parameters, and at least one label element definition. When a data conflict is detected for the same tag element, arbitration is conducted according to the preset arbitration rules to determine the target data; The initial pixel layout of the canvas and each of the label elements is calculated based on the label definition configuration file; Based on the target data, the estimated visual content of each of the label elements is generated and the layout conflict in the initial pixel layout is detected. If the layout conflict exists, the initial pixel layout of the detected conflicting tag elements is automatically adjusted to generate an optimized final layout. Based on the final layout, the visual content is composited onto the canvas to generate and output the final label image.

2. The printing method for generating label images based on configuration according to claim 1, characterized in that, The process of obtaining the tag definition configuration file and the data to be populated from at least one preset external data source specifically includes the following steps: Read the label definition configuration file, which includes label size, printing parameters, and at least one label element definition, which includes label element type and initial layout parameters; Based on the preset data source connection information, a connection is established with at least one external data source, the original data to be filled is obtained from the external data source, the data field value corresponding to each of the tag elements is extracted from the original data to be filled, and the data field value is used as the data to be filled for the corresponding tag element definition.

3. The printing method for generating label images based on configuration according to claim 2, characterized in that, When a data conflict is detected for the same tag element, arbitration is performed according to preset arbitration rules to determine the target data, specifically including the following steps: For the same tag element definition, the data to be filled obtained from different external data sources are compared; when there are at least two different data to be filled, it is determined that the corresponding tag element has a data conflict. When the data conflict is detected, a preset arbitration rule is invoked to select different data to be filled to obtain target data. The target data is the final data used to generate the estimated visual content of the current tag element.

4. The printing method for generating label images based on configuration according to claim 3, characterized in that, The step of invoking preset arbitration rules to select different data to be filled to obtain target data includes the following steps: Each external data source is assigned a priority level. When a data conflict occurs, the data to be filled provided by the external data source with the highest priority level is adopted as the target data. Alternatively, compare the timestamps corresponding to conflicting data to be filled from different external data sources, and adopt the data to be filled with the latest timestamp as the target data; Alternatively, check all conflicting data to be filled and adopt the first non-empty data or data that conforms to a preset valid format as the target data; Alternatively, a confidence weight can be calculated for each conflicting piece of data to be filled, and the piece of data to be filled with the highest weighted average can be adopted as the target data.

5. The printing method for generating label images based on configuration according to claim 3, characterized in that, The steps of calculating the initial pixel layout of the canvas and each of the tag elements according to the tag definition configuration file, generating the visual content of each of the tag elements based on the target data, and detecting whether there are layout conflicts in the initial pixel layout specifically include the following steps: Calculate the canvas pixel size required to generate the final label image based on the label size and the printing resolution in the printing parameters; Based on the print resolution and the initial layout parameters defined in each of the label elements, the initial pixel position and initial pixel size of each label element on the canvas are calculated, which together constitute the initial pixel layout of the canvas. Based on the target data determined for each of the tag elements and the corresponding tag element type, the corresponding element processor is called to generate the estimated visual content corresponding to each of the tag elements, and the actual pixel size of each of the estimated visual contents is obtained. The actual pixel size of each estimated visual content is combined with the initial pixel layout to determine the actual area occupied by each estimated visual content on the canvas. Based on the preset layout rules, it is determined whether there is a layout conflict in the actual occupied area.

6. The printing method for generating label images based on configuration according to claim 3, characterized in that, If a layout conflict exists, the initial pixel layout of the detected conflicting tag elements is automatically adjusted to generate an optimized final layout, specifically including the following steps: Based on the detected layout conflicts, all conflicting tag elements that need to be adjusted are identified, forming a set of conflicting elements; based on the tag element type of each conflicting tag element in the set of conflicting elements, the adjustment strategy for the conflicting tag elements is determined. The adjustment strategy is used to calculate the new first layout parameters of the corresponding conflicting tag element in the final layout. The first layout parameters include the first pixel position or the first visual content size. The initial pixel layout is updated based on the first layout parameters of all the conflicting tag elements to generate the optimized final layout.

7. The printing method for generating label images based on configuration according to claim 6, characterized in that, The step of compositing the visual content onto the canvas based on the final layout to generate and output the final label image specifically includes the following steps: Based on the tag element type of each tag element in the final layout, the corresponding target data, and the first layout parameters, a corresponding bitmap image is generated, and the bitmap image is used as the final visual content of the current tag element. Based on the hierarchical information of each tag element contained in the final layout, the final visual content corresponding to all tag elements is sorted to determine the order in which they are composited onto the canvas. According to the determined sequence, based on the first pixel position of the tag element corresponding to each final visual content in the final layout, each final visual content is sequentially drawn onto the canvas; The final drawn canvas is encoded into a bitmap file and output, and the bitmap file is the final label image.

8. A printing device for generating label images based on configuration, characterized in that, Includes the following modules: The configuration and data acquisition module is used to acquire the label definition configuration file and the data to be filled from at least one preset external data source. The label definition configuration file includes the label size, printing parameters and at least one label element definition. The data arbitration module is used to arbitrate and determine the target data according to preset arbitration rules when a data conflict is detected for the same tag element. The layout calculation module is used to calculate the initial pixel layout of the canvas and each of the label elements according to the label definition configuration file; Based on the target data, the estimated visual content of each of the label elements is generated and the layout conflict in the initial pixel layout is detected. The layout optimization module is used to automatically adjust the pixel position of the detected conflicting label elements or the size of the estimated visual content if the layout conflict exists, so as to generate an optimized final layout. The label image synthesis module is used to synthesize various visual contents onto the canvas according to the final layout, and generate and output the final label image.

9. A smart terminal, characterized in that, The method includes a memory and a processor, wherein the memory stores at least one instruction, at least one program, code set, or instruction set, and the at least one instruction, at least one program, code set, or instruction set is loaded and executed by the processor to implement the printing method for generating label images based on configuration as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The readable storage medium stores at least one instruction, at least one program, code set, or instruction set, which is loaded and executed by a processor to implement the configuration-based label image printing method as described in any one of claims 1 to 7.