Portable printing method and system based on custom templates

The visual template configuration and protocol adaptation implemented through the WebExcel control solve the problems of fixed templates and compatibility for portable printing devices, and achieve flexible adjustment and consistency in printing across devices.

CN121233063BActive Publication Date: 2026-02-27蒲惠智造科技股份有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511794765.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-02
Publication Date
2026-02-27
Estimated Expiration
2045-12-02

AI Technical Summary

Technical Problem

Existing portable printing devices use fixed templates, which cannot flexibly adjust the format and content according to specific needs. This forces backend developers to redevelop templates, and there are compatibility issues between different brands and models of printers.

Method used

It adopts a visual template configuration interface based on WebExcel control, which allows users to customize or automate the configuration of template format and content, and parse the printer protocol through the protocol adaptation module to generate image printing instructions that conform to the target protocol.

Benefits of technology

It reduces the workload of backend staff, improves template configuration efficiency, solves cross-device compatibility issues, and ensures consistent printing results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121233063B_ABST
    Figure CN121233063B_ABST
Patent Text Reader

Abstract

The application discloses a portable printing method and system based on a self-defined template, and a server method comprises the following steps: receiving a document printing request sent by a mobile terminal, wherein the document printing request carries a target template ID and to-be-printed data; obtaining target template configuration information corresponding to the target template ID from a mapping relationship between pre-established template IDs and template configuration information; the mapping relationship is configured based on a visual template configuration interface of a WebExcel control; performing template rendering and protocol adaptation according to the to-be-printed data and the target template configuration information, generating an image printing instruction, and sending the image printing instruction to a current printer through Bluetooth. Therefore, by adopting the embodiment of the application, a user can flexibly adjust the format and content of a template according to specific requirements, without the need of a backend staff to develop a new template, thereby greatly reducing the workload of the backend staff. Meanwhile, the rendered image can be encapsulated into a printing instruction according to the protocol of different printers, thereby solving the cross-device compatibility problem.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computers, and in particular to a portable printing method and system based on a custom template. BACKGROUND

[0002] In the field of industrial production and logistics management, portable printing devices are widely used in the rapid printing of workshop flow cards, warehouse labels, inspection sheets, logistics sheets, etc. These scenarios usually require the generation and printing of documents in a specific format on mobile devices to meet the instant needs of on-site operations. For example, in warehouse management, workers need to print labels immediately to identify the information of goods.

[0003] In related technologies, existing portable printing devices rely on fixed format templates for printing. Common standard protocols for printing devices include TSPL (TSC Instruction Set Printing Language) and CPCL (Zebra Compatible Printing Language). These protocols control the printing behavior of the printer through predefined instruction sets to achieve the printing output of the document.

[0004] However, the existing printing templates are fixed, and users cannot flexibly adjust the format and content of the templates according to specific needs, resulting in the need for backend personnel to redevelop templates when facing different printing needs, increasing the workload of backend personnel. Different brands and models of printers support different printing protocols, making existing printing templates have compatibility problems when used across devices. SUMMARY

[0005] The embodiments of the present application provide a portable printing method and system based on a custom template. In order to have a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. This summary is not a general review, nor does it determine the key / important components or delineate the protection scope of these embodiments. Its only purpose is to present some concepts in a simple form as a prelude to the detailed description that follows.

[0006] In a first aspect, the embodiments of the present application provide a portable printing method based on a custom template, applied to a server, the method comprising:

[0007] receiving a document printing request sent by a mobile terminal, the document printing request carrying a target template ID and to-be-printed data;

[0008] obtaining target template configuration information corresponding to the target template ID from a mapping relationship between pre-established template IDs and template configuration information; the mapping relationship is configured based on a visual template configuration interface of a WebExcel control;

[0009] According to the to-be-printed data and the target template configuration information, template rendering and protocol adaptation are performed, image printing instructions are generated, and the image printing instructions are sent to a current printer that establishes a connection with the server.

[0010] Optionally, according to the to-be-printed data and the target template configuration information, template rendering and protocol adaptation are performed, and the image printing instructions are generated, including:

[0011] According to the to-be-printed data and the target template configuration information, to-be-printed content is generated.

[0012] A Node.js server-side rendering engine is called to render the to-be-printed content, and a target image to be printed is obtained.

[0013] A target protocol of a current printer that establishes a connection with the server is obtained.

[0014] In a case where a printing protocol existing in the target template configuration information is inconsistent with the target protocol, the target image is adapted to the target protocol, and image printing instructions corresponding to the target image are obtained.

[0015] Optionally, the target image is adapted to the target protocol, and the image printing instructions corresponding to the target image are obtained, including:

[0016] The target protocol is parsed to obtain printing protocol information.

[0017] According to the printing protocol information, a printing format parameter supported by the current printer is determined.

[0018] A Pillow image processing library or an OpenCV image processing library is called to convert the target image into an image format conforming to the printing format parameter, and a monochrome bitmap image after conversion is obtained.

[0019] Based on the monochrome bitmap image, the image printing instructions corresponding to the target image are generated.

[0020] Optionally, the image printing instructions corresponding to the target image are generated based on the monochrome bitmap image, including:

[0021] In a case where a printing protocol supported by the current printer is a TSPL protocol, the monochrome bitmap image is encapsulated into a BITMAP instruction of the TSPL protocol; or

[0022] In a case where a printing protocol supported by the current printer is a CPCL protocol, the monochrome bitmap image is encapsulated into an EG instruction of the CPCL protocol; wherein instruction attributes in the BITMAP instruction or the EG instruction include starting coordinates of the image on printing paper, a width and a height of the image, and binary data of the image.

[0023] The BITMAP instruction or the EG instruction is combined with preset control instructions of the current printer to obtain image printing instructions corresponding to the target image.

[0024] Optionally, before receiving the document printing request sent by the mobile terminal, the method further includes:

[0025] In response to a template configuration instruction for the target template type, a visual template configuration interface realized based on a WebExcel control is displayed, and the visual template configuration interface includes a custom configuration component and an automatic configuration component.

[0026] In response to a trigger instruction for the displayed custom configuration component or the automatic configuration component, template configuration information of the target template type is generated.

[0027] A template ID of the target template type is obtained.

[0028] A mapping relationship between the template ID and the template configuration information is stored.

[0029] Optionally, generating the template configuration information of the target template type includes:

[0030] In a case where the trigger instruction is that a user triggers the custom configuration component, a template editing form of the target template type is displayed.

[0031] In response to a field dragging instruction and / or a field format setting instruction and / or a template element layout planning instruction for the template editing form, a final position and a format of each field are obtained, and a final template layout is determined.

[0032] A data source and a binding rule for field attribute setting of each field of the template editing form are received, and attribute strategies of each field are obtained.

[0033] The final position and the format of each field, the strategy attribute, and the final template layout are taken as the template configuration information of the target template type.

[0034] Optionally, generating the template configuration information of the target template type includes:

[0035] In a case where the trigger instruction is that a user triggers the automatic configuration component, template requirement description information and an example graph sent by the mobile terminal are received.

[0036] The template requirement description information is parsed to extract existing key fields and attributes, and structured field data is obtained.

[0037] From the structured field data, a final position and a format of each field, a strategy attribute are obtained.

[0038] From the structured field data, determine the data source corresponding to the field attribute of each field and the binding rule, and obtain the attribute strategy of each field;

[0039] Based on the layout analysis of the example graph, determine the final template layout;

[0040] The final position and format of each field, the strategy attribute, and the final template layout are used as template configuration information of the target template type.

[0041] Optionally, based on the layout analysis of the example graph, the final template layout is determined, including:

[0042] The example graph is binarized to segment out a gray-scale image containing text / graphics and background regions;

[0043] All text content and its position in the gray-scale image are recognized to obtain a text detection result;

[0044] All graphic elements existing in the gray-scale image are detected to obtain a graphic detection result;

[0045] According to the text detection result and the graphic detection result, the gray-scale image is segmented into multiple layout regions, each of which contains at least one text box or graphic;

[0046] Each layout region is classified based on the at least one text box or graphic contained in each layout region to obtain an information presentation type of each layout region;

[0047] The center point of each layout region is used as the relative position of each layout region;

[0048] The relative position of each layout region and the information presentation type of each layout region are used as the final template layout.

[0049] Optionally, the target template configuration information includes the final position and format of each field, the data source and binding rule of each field, the relative position and information presentation type of each layout region;

[0050] According to the to-be-printed data and the target template configuration information, generate the to-be-printed content, including:

[0051] From the to-be-printed data, determine whether there is a target character with the same placeholder name as the format or data source of each field;

[0052] If yes, process the target field through the formatting instruction in the binding rule of each field to obtain a print-ready value of each field;

[0053] If not, perform numerical completion through the default value or calculation expression in the binding rule of each field to obtain a print-ready value of each field;

[0054] combining the print-ready value of each field with the final position and format of each field, obtaining a positioning value object of each field;

[0055] matching the relative position and information presentation type of each layout area with the positioning value object of each field to group all positioning value objects in the same area, obtaining print data of each layout area;

[0056] caching the print data of each layout area, obtaining the to-be-printed content.

[0057] In a second aspect, an embodiment of the present application provides a portable printing system based on a custom template, the system comprising:

[0058] a request receiving module, configured to receive a document printing request sent by a mobile terminal, the document printing request carrying a target template ID and to-be-printed data;

[0059] a template configuration information obtaining module, configured to obtain target template configuration information corresponding to the target template ID from a mapping relationship between template IDs and template configuration information, the mapping relationship being configured based on a visual template configuration interface realized by a WebExcel control;

[0060] a printing instruction sending module, configured to perform template rendering and protocol adaptation according to the to-be-printed data and the target template configuration information, generate an image printing instruction, and send the image printing instruction to a current printer connected to the server.

[0061] The technical scheme provided by the embodiment of the present application can include the following beneficial effects:

[0062] In the embodiment of the present application, on the one hand, the visual template configuration interface realized by the WebExcel control enables the user to flexibly adjust the format and content of the template according to specific requirements, and the manual or automatic template configuration mode enables the user to quickly adjust the template according to different printing requirements without the need for the back-end personnel to redevelop the template, thereby reducing the workload of the back-end personnel and improving the efficiency of template configuration. On the other hand, the protocol adaptation module can parse the printing protocol of the target printer and adapt the generated image according to the protocol to generate a corresponding image printing instruction. The protocol adaptation mechanism ensures that the printing template can be normally printed on different brands and models of printers, thereby solving the cross-device compatibility problem. Regardless of whether the printer supports the TSPL or CPCL protocol, the system can generate a printing instruction conforming to the protocol, thereby ensuring the consistency of the printing effect.

[0063] It should be understood that the foregoing general description and the following detailed description are only exemplary and explanatory, and cannot limit the present application. Attached Figure Description

[0064] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0065] Figure 1 This is a schematic diagram of a portable printing method based on a custom template provided in an embodiment of this application;

[0066] Figure 2 This is a schematic diagram of an interaction scenario between a mobile terminal and a server provided in an embodiment of this application;

[0067] Figure 3 This is a schematic diagram of a custom configuration UI provided in an embodiment of this application;

[0068] Figure 4 This is a schematic diagram of a UI interface for automated configuration provided in an embodiment of this application;

[0069] Figure 5 This is an example diagram of a template layout provided in an embodiment of this application;

[0070] Figure 6 This is a schematic flowchart illustrating a portable printing process based on a custom template, provided in an embodiment of this application.

[0071] Figure 7 This is a schematic diagram of the structure of a portable printing system based on a custom template provided in an embodiment of this application;

[0072] Figure 8 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0073] The following description and accompanying drawings fully illustrate specific embodiments of this application to enable those skilled in the art to practice them.

[0074] It should be understood that the described embodiments are merely some, not all, of the embodiments in this application. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.

[0075] In the following description, when referring to the accompanying drawings, the same numbers in different drawings denote the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0076] In the description of the present application, it is understood that the terms "first", "second" and the like are only for the purpose of description and cannot be understood as indicating or implying relative importance. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood in specific cases. In addition, in the description of the present application, "a plurality of" means two or more, unless otherwise specified. The association relationship of the associated objects is described, which means that there can be three relationships, for example, A and / or B can represent the three cases of A alone, A and B together, and B alone. The character " / " generally represents an "or" relationship between the associated objects before and after it.

[0077] At present, the existing portable printing equipment mostly relies on fixed format templates for printing. Common standard protocols of printing equipment include TSPL (TSC instruction set printing language) and CPCL (Zebra compatible printing language). These protocols control the printing behavior of the printer through a predefined instruction set to achieve the printing output of the document.

[0078] The applicant of the present application realizes that the existing printing template is fixed, and the user cannot flexibly adjust the format and content of the template according to specific needs, resulting in the need for the back-end personnel to redevelop the template when facing different printing needs, which increases the workload of the back-end personnel. Different brands and models of printers support different printing protocols, so that the existing printing template has compatibility problems when used across devices.

[0079] In order to solve the above problems, the present application provides a portable printing method and system based on a custom template to solve the problems existing in the above related technical problems. In the embodiments of the present application, on the one hand, the visual template configuration interface realized by the WebExcel control allows the user to flexibly adjust the format and content of the template according to specific needs. The manual or automatic template configuration method enables the user to quickly adjust the template according to different printing needs, without the need for back-end personnel to redevelop the template, which not only reduces the workload of the back-end personnel, but also improves the efficiency of template configuration. On the other hand, the protocol adaptation module can parse the printing protocol of the target printer and adapt the generated image according to the protocol to generate corresponding image printing instructions. The protocol adaptation mechanism ensures that the printing template can be normally printed on different brands and models of printers, solving the cross-device compatibility problem. Whether the printer supports TSPL or CPCL protocol, the system can generate printing instructions conforming to the protocol, ensuring the consistency of the printing effect. The following will be described in detail by way of exemplary embodiments.

[0080] The following will be described in detail by way of exemplary embodiments. Figure 1 -Appendix Figure 6This application provides a detailed description of the portable printing method based on a custom template, as provided in its embodiments. This method can be implemented using a computer program and can run on a portable printing system based on a custom template and the von Neumann architecture. The computer program can be integrated into an application or run as a standalone utility application.

[0081] Please see Figure 1 This document provides a flowchart illustrating a portable printing method based on a custom template, applicable to a server-side application. For example... Figure 1 As shown, the method in this application embodiment includes the following steps:

[0082] S101, The server receives a document printing request sent by the mobile terminal. The document printing request carries the target template ID and the data to be printed.

[0083] In this context, "mobile device" refers to the user's mobile device, such as a smartphone or tablet. A document print request is a request initiated by the user via their mobile device, indicating a need for printing. The document print request includes a target template ID and the data to be printed. The target template ID is a unique identifier specifying the print template the user is currently using in the workshop.

[0084] In some embodiments of this application, a user selects the template type to be printed in a mobile application and enters or selects the data to be printed. The mobile application generates a document print request, which includes the target template ID and the data to be printed. The mobile application sends the document print request to the server via a network (such as HTTP / HTTPS). The server's API interface receives the print request from the mobile application. The server parses the request data and extracts the target template ID and the data to be printed.

[0085] For example Figure 2 As shown, the user opens the mobile application 120 and selects the "Product Label" template. The user enters the product name "Smartwatch", product number "12345", and production date "2023-10-01". The user clicks the "Print" button, and the mobile application 120 generates a print request. The mobile application 120 sends the above request packet to the API interface of the server 110 via HTTPS. The content of the print request packet is as follows:

[0086] {"templateId": "product_label_template",

[0087] "printData": {

[0088] "productName": "Smartwatch",

[0089] "productNumber": "12345",

[0090] "productionDate": "2023-10-01"

[0091] }

[0092] }。

[0093] S102, the server obtains target template configuration information corresponding to the target template ID from a mapping relationship between the pre-established template ID and the template configuration information; the mapping relationship is configured based on a visual template configuration interface implemented by a WebExcel control;

[0094] The template configuration information includes detailed information such as the specific layout, field position, format setting, and data source binding rule of the template. The template configuration information is used to guide the server to render the template, fill the to-be-printed data into the template, and generate the final print content. The WebExcel control is a Web-based Excel-like control used to provide Excel-like table operation functions in a browser. The WebExcel control is used to implement the visual template configuration interface, which facilitates users to configure templates through operations such as dragging and inputting. The visual template configuration interface allows users to configure the layout and content of the template through graphical operations. Users can freely design the format and content of the template through the interface without writing code.

[0095] In some embodiments of the present application, the server receives a print request sent by the mobile terminal, and parses the target template ID and the to-be-printed data in the request. The server can quickly obtain complete template configuration information from the mapping relationship.

[0096] In some embodiments of the present application, when the template type required to be printed in the mobile terminal application does not meet the user's requirements, the user can trigger the template editing application in the mobile terminal application, and at this time, the specific process of generating the mapping relationship between the pre-established template ID and the template configuration information includes: in response to a template configuration instruction for the target template type, a visual template configuration interface implemented based on a WebExcel control is displayed, and the visual template configuration interface includes a custom configuration component and an automatic configuration component; in response to a trigger instruction for the displayed custom configuration component or the automatic configuration component, template configuration information of the target template type is generated; a template ID of the target template type is obtained; and the mapping relationship between the template ID and the template configuration information is stored.

[0097] The target template type is the kind or category of the template that the user wants to configure, such as "flow card", "warehouse label", "logistics single", and the like. The template configuration instruction is an instruction initiated by the user, indicating that the configuration of a certain type of template is needed. The trigger instruction is an operation initiated by the user in the configuration interface, such as clicking the custom configuration component or the automated configuration component.

[0098] In a possible implementation, the user selects the template type that needs to be configured on the Web side, such as "warehouse label". The user clicks the "configure template" button, and the system receives the template configuration instruction. The system displays a visual template configuration interface implemented based on a Web Excel control according to the template type selected by the user. The configuration interface includes a custom configuration component and an automated configuration component. The user can choose to manually adjust the template using the custom configuration component or automatically generate template configuration information using the automated configuration component. The system stores the mapping relationship between the template ID and the template configuration information in the database.

[0099] In the embodiments of the present application, the user can configure the template through the visual template configuration interface on the Web side, and the system stores the mapping relationship of the template configuration. The service side can quickly obtain the corresponding template configuration information through the template ID, thereby providing a basis for subsequent template rendering and printing operations.

[0100] The pre-established mapping relationship between the template ID and the template configuration information is shown in Table 1, for example.

[0101] Table 1

[0102]

[0103] In some embodiments of the present application, the specific process of generating the template configuration information of the target template type includes: in the case where the trigger instruction is that the user triggers the custom configuration component, displaying a template editing form of the target template type; in response to a field dragging instruction and / or a field format setting instruction and / or a template element layout planning instruction for the template editing form, obtaining the final position and format of each field and determining the final template layout; receiving the data source and binding rule of the field attribute setting of each field of the template editing form to obtain the attribute strategy of each field; and taking the final position and format, the strategy attribute, and the final template layout of each field as the template configuration information of the target template type.

[0104] The template editing form is a user-friendly web interface that allows users to configure the layout and content of a template through graphical operations. It provides an intuitive environment for users to freely design the format and content of a template without writing code. The field drag instruction is obtained by the user adjusting the position of the field in the template through a drag operation. This instruction allows users to freely adjust the position of the field. The template element layout planning instruction is obtained by the user planning the overall layout of each element (such as fields, graphics, lines, etc.) in the template. This instruction allows users to design the overall structure of the template to ensure its rationality and aesthetics.

[0105] In one possible implementation, the user selects the "custom configuration" component in the visual template configuration interface. The system displays a template editing form for the target template type, which includes adjustable fields and layout elements. The user adjusts the position of the field in the template through a drag operation, and the system updates the position information of the field in real time. The user selects the font, font size, color, and other format settings in the field attribute setting interface, and the system updates the format information of the field. The user adjusts the relative positions of the fields and graphics through the layout planning tool, and the system updates the overall layout information of the template. The user sets the data source and binding rules for each field, such as binding to the database field ProductName or the API return value {{productName}}. The user can set default values and formatting rules, such as formatting the date as YYYY-MM-DD. The system records the final position, format, data source, and binding rules of each field according to the user's operations, and generates complete template configuration information. The system assigns a unique template ID to the generated template configuration information, and stores the mapping relationship between the template ID and the template configuration information in the database.

[0106] For example, after the user triggers the custom configuration component, a template editing form for the target template type is displayed, such as Figure 3As shown, the user selects the "Customize Configuration" option in the interface, and the system displays a template editing form of the "Warehouse Label". The user clicks the "Field Drag" button, and drags the field "Product Name" to the upper left corner of the template (coordinates: x = 10, y = 10). The user drags the field "Product Number" to the lower left corner of the upper left corner of the template (coordinates: x = 10, y = 30). The user drags the field "Production Date" to the lower left corner of the lower left corner of the upper left corner of the template (coordinates: x = 10, y = 50). The system records the final position of each field. The user clicks the "Format Setting" button, and sets the font of the field "Product Name" to Arial, font size 12, and color black. The user sets the font of the field "Product Number" to Arial, font size 10, and color black. The user sets the font of the field "Production Date" to Arial, font size 10, and color gray. The system records the format information of each field. The user clicks the "Layout Planning" button, and adjusts the overall layout of the template, such as paper width 80 mm. The system records the overall layout information of the template. The user sets the data source of the field "Product Name" to {{productName}}, and the binding rule to the default value of empty. The user sets the data source of the field "Product Number" to {{productNumber}}, and the binding rule to the default value of empty. The user sets the data source of the field "Production Date" to {{productionDate}}, and the binding rule to the date format YYYY-MM-DD. The system records the attribute strategy of each field. The system can generate the final template configuration information according to the user's operation.

[0107] In some embodiments of the present application, the specific process of generating the template configuration information of the target template type includes: in the case where the trigger instruction is that the user triggers the automatic configuration component, receiving the template requirement description information and the example diagram sent by the mobile terminal; parsing the template requirement description information to extract the existing key fields and their attributes, obtaining structured field data; from the structured field data, obtaining the final position and format, strategy attributes of each field; from the structured field data, determining the data source corresponding to the field attribute of each field and the binding rule, obtaining the attribute strategy of each field; based on the example diagram, performing layout analysis to determine the final template layout; taking the final position and format, strategy attributes of each field and the final template layout as the template configuration information of the target template type.

[0108] The automatic configuration component is configured by the user providing a requirement description and an example image, and the system automatically parses and generates a template configuration. The automatic configuration component can simplify the template configuration process, reduce user manual operation, and quickly generate a template. The template requirement description information is a text description of the user's template requirements, including required fields, formats, layouts, etc. The template requirement description information provides basic information for system parsing to automatically generate template configurations. The example image is a template example image uploaded by the user, showing the user's desired template layout and style. The example image is used to assist the system in understanding the visual effect and layout requirements of the template.

[0109] In one possible implementation, the user uploads a requirement description and an example image on a mobile terminal. The system uses natural language processing technology to parse the requirement description and extract key fields and their attributes. Structured field data is extracted from the parsed results, including field names, required attributes, etc. Based on the structured field data, the final position and format of each field in the template are determined. Data sources and binding rules are determined for each field, such as database fields, API paths, etc. Based on the example image, the overall layout of the template is determined. The position, format, data source, and binding rule of each field, as well as the template layout, are integrated into template configuration information.

[0110] For example, after the user triggers the automatic configuration component, an automatic configuration form for the target template type is displayed, as shown in FIG. 1. Figure 4 As shown in FIG. 2, the user inputs in the text box: "I need a product label, including product name, product number, and production date. The product name is centered, with a font size of 12 and a color of black; the product number and production date are at the bottom, with a font size of 10 and a color of gray." The user uploads an example image showing the desired label layout. The server uses NLP technology to parse the requirement description and extract key fields: product name, product number, and production date, as well as their format requirements. The system extracts structured field data, including field names and format requirements. The system determines the position and format of the fields in the template based on the structured field data. The system determines the data source and binding rule for each field, for example: product name: data source {{productName}}, no default value. Product number: data source {{productNumber}}, no default value. Production date: data source {{productionDate}}, formatted as YYYY-MM-DD. The system performs layout analysis based on the example image to determine the overall layout of the template. The system generates template configuration information, including field position, format, data source, and binding rule, as well as template layout. The example image is shown in FIG. 3, for example. Figure 5

[0111] ​Specifically, based on the example image, the specific process of determining the final template layout includes: performing binaryzation processing on the example image to segment out a gray image containing text / graphics and background regions; identifying all text contents and their positions in the gray image to obtain a text detection result; detecting all graphic elements existing in the gray image to obtain a graphic detection result; segmenting the gray image into multiple layout regions according to the text detection result and the graphic detection result, each layout region containing at least one text box or graphic; classifying each layout region based on the at least one text box or graphic contained in each layout region to obtain an information presentation type of each layout region; taking the center point of each layout region as the relative position of each layout region; and taking the relative position of each layout region and the information presentation type of each layout region as the final template layout.

[0112] In S103, the server performs template rendering and protocol adaptation according to the to-be-printed data and the target template configuration information, generates image printing instructions, and sends the image printing instructions to the current printer that has established a connection with the server.

[0113] In some embodiments of the present application, the specific process of generating image printing instructions according to the to-be-printed data and the target template configuration information includes: generating to-be-printed content according to the to-be-printed data and the target template configuration information; calling a Node.js server rendering engine to render the to-be-printed content to obtain a target image to be printed; obtaining a target protocol of the current printer that has established a connection with the server; and in the case where the printing protocol existing in the target template configuration information is inconsistent with the target protocol, performing protocol adaptation on the target image based on the target protocol to obtain image printing instructions corresponding to the target image.

[0114] Further, in the case where the printing protocol existing in the target template configuration information is consistent with the target protocol, it is indicated that the template configuration information has been adapted to the printer, and no further adaptation is needed. The protocol instructions supported by the printer are directly used to generate printing instructions. For example, if the printer supports the TSPL protocol, BITMAP instructions of the TSPL can be directly generated.

[0115] The target template configuration information includes the final position and format of each field, the data source and binding rule of each field, and the relative position and information presentation type of each layout region.

[0116] Specifically, according to the to-be-printed data and the target template configuration information, a specific process of generating the to-be-printed content includes: determining, from the to-be-printed data, whether there is a target character that is the same as a placeholder name in a format of each field or a data source; if yes, processing the target field through a formatting instruction in a binding rule of each field to obtain a print-ready value of each field; if no, performing value completion through a default value or a calculation expression in the binding rule of each field to obtain the print-ready value of each field; combining the print-ready value of each field with a final position and a format of each field to obtain a positioning value object of each field; matching the relative position and the information presentation type of each layout area with the positioning value object of each field to group all the positioning value objects in a same area to obtain print data of each layout area; and caching the print data of each layout area to obtain the to-be-printed content.

[0117] Specifically, based on the target protocol, a specific process of performing protocol adaptation on the target image to obtain an image print instruction corresponding to the target image includes: parsing the target protocol to obtain print protocol information; determining a print format parameter supported by a current printer according to the print protocol information; calling a Pillow image processing library or an OpenCV image processing library to convert the target image into an image format conforming to the print format parameter to obtain a converted monochrome bitmap image; and generating the image print instruction corresponding to the target image based on the monochrome bitmap image.

[0118] Specifically, a specific process of generating the image print instruction corresponding to the target image based on the monochrome bitmap image includes: in a case where a print protocol supported by the current printer is a TSPL protocol, encapsulating the monochrome bitmap image into a BITMAP instruction of the TSPL protocol; or in a case where the print protocol supported by the current printer is a CPCL protocol, encapsulating the monochrome bitmap image into an EG instruction of the CPCL protocol; wherein instruction attributes in the BITMAP instruction or the EG instruction include a starting coordinate of the image on a printing paper, a width and a height of the image, and binary data of the image; and combining the BITMAP instruction or the EG instruction with a preset control instruction of the current printer to obtain the image print instruction corresponding to the target image.

[0119] For example Figure 6 As shown, Figure 6The application provides a process schematic block diagram of a portable printing process based on a self-defined template. In response to a template configuration instruction for a target template type, a server displays a visual template configuration interface realized based on a WebExcel control. The visual template configuration interface comprises a self-defined configuration component and an automatic configuration component. In response to a trigger instruction for the displayed self-defined configuration component or the automatic configuration component, template configuration information of the target template type is generated. A template ID of the target template type is obtained, and a mapping relationship between the template ID and the template configuration information is stored. A document printing request sent by a mobile terminal is received. The document printing request carries a target template ID and to-be-printed data. From a mapping relationship between the template ID and the template configuration information established in advance, target template configuration information corresponding to the target template ID is obtained. To-be-printed content is generated according to the to-be-printed data and the target template configuration information. A Node.js server-side rendering engine is called to render the to-be-printed content, so that a target image to be printed is obtained. A target protocol of a current printer connected to the server is obtained. It is determined whether a printing protocol existing in the target template configuration information is consistent with the target protocol. If yes, an image printing instruction corresponding to the target image does not need to be generated after protocol adaptation. If no, the target image is adapted based on the target protocol, so that the image printing instruction corresponding to the target image is obtained, and finally sent to the current printer connected to the server.

[0120] In the embodiment of the application, on the one hand, the visual template configuration interface realized by the WebExcel control enables the user to flexibly adjust the format and content of the template according to specific requirements. The manual or automatic template configuration mode enables the user to quickly adjust the template according to different printing requirements without the need for the back-end personnel to redevelop the template. This not only reduces the workload of the back-end personnel, but also improves the efficiency of template configuration. On the other hand, the protocol adaptation module can parse the printing protocol of the target printer and adapt the generated image according to the protocol to generate the corresponding image printing instruction. The protocol adaptation mechanism ensures that the printing template can be normally printed on different brands and models of printers, solves the cross-device compatibility problem, and enables the system to generate a printing instruction conforming to the protocol regardless of whether the printer supports the TSPL or CPCL protocol, thereby ensuring the consistency of the printing effect.

[0121] The following is an embodiment of the system of the application, which can be used to execute the method embodiments of the application. For details not disclosed in the system embodiments of the application, please refer to the method embodiments of the application.

[0122] Please refer to Figure 7Fig. 1 is a structural schematic diagram of a portable printing system based on a custom template according to an example embodiment of the present application. The portable printing system based on the custom template can be implemented as all or part of an electronic device through software, hardware, or a combination of both. The system 1 includes a request receiving module 10, a template configuration information obtaining module 20, and a printing instruction sending module 30.

[0123] The request receiving module 10 is configured to receive a document printing request sent by a mobile terminal, the document printing request carrying a target template ID and to-be-printed data.

[0124] The template configuration information obtaining module 20 is configured to obtain target template configuration information corresponding to the target template ID from a mapping relationship between template IDs and template configuration information, the mapping relationship being configured based on a visual template configuration interface of a WebExcel control.

[0125] The printing instruction sending module 30 is configured to perform template rendering and protocol adaptation according to the to-be-printed data and the target template configuration information, to generate an image printing instruction, and to send the image printing instruction to a current printer that has established a connection with the server.

[0126] It should be noted that the portable printing system based on the custom template provided in the above example embodiment is used to execute the portable printing method based on the custom template, and the above functions are only used as examples for the division of the functional modules. In actual applications, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the portable printing system based on the custom template and the portable printing method based on the custom template provided in the above example embodiment belong to the same concept, and the implementation process is detailed in the method embodiment. Therefore, no further description is given here.

[0127] The above example numbers of the present application are only for description, and do not represent the advantages and disadvantages of the examples.

[0128] In the embodiments of the present application, on the one hand, the visual template configuration interface realized by the WebExcel control allows the user to flexibly adjust the format and content of the template according to specific needs, and the manual or automatic template configuration mode enables the user to quickly adjust the template according to different printing needs without the need for the back-end personnel to redevelop the template, thereby reducing the workload of the back-end personnel and improving the efficiency of template configuration. On the other hand, the protocol adaptation module can parse the printing protocol of the target printer and adapt the generated image according to the protocol to generate corresponding image printing instructions. The protocol adaptation mechanism ensures that the printing template can be normally printed on different brands and models of printers, solves the cross-device compatibility problem, and enables the system to generate printing instructions conforming to the protocol regardless of whether the printer supports the TSPL or CPCL protocol, thereby ensuring the consistency of the printing effect.

[0129] The present application also provides a computer readable medium having program instructions stored thereon, which, when executed by a processor, implement the portable printing method based on the custom template provided by each of the method embodiments.

[0130] The present application also provides a computer program product containing instructions, which, when running on a computer, causes the computer to execute the portable printing method based on the custom template of each of the method embodiments.

[0131] Please refer to Figure 8 The present application provides a structural schematic diagram of an electronic device. As shown in Figure 8 The electronic device 1000 can include at least one processor 1001, at least one network interface 1004, a user interface 1003, a memory 1005, and at least one communication bus 1002.

[0132] The communication bus 1002 is used to realize the connection and communication between the components.

[0133] The user interface 1003 can include a display screen (Display) and a camera (Camera), and the optional user interface 1003 can also include a standard wired interface and a wireless interface.

[0134] The network interface 1004 can optionally include a standard wired interface and a wireless interface (such as a WI-FI interface).

[0135] The processor 1001 can include one or more processing cores. The processor 1001 connects various parts within the entire electronic device 1000 through various interfaces and lines, and performs various functions of the electronic device 1000 and processes data by running or executing instructions, programs, code sets, or instruction sets stored in the memory 1005, and calling data stored in the memory 1005. Alternatively, the processor 1001 can be implemented in at least one of a hardware form of a digital signal processor (DSP), a field-programmable gate array (FPGA), a programmable logic array (PLA). The processor 1001 can integrate a combination of one or several of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. Among them, the CPU mainly processes an operating system, a user interface, and an application program; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; and the modem is used for processing wireless communication. It can be understood that the above-mentioned modem can also not be integrated into the processor 1001, but can be realized by a separate chip.

[0136] The memory 1005 can include a random access memory (RAM) and can also include a read-only memory (ROM). Alternatively, the memory 1005 includes a non-transitory computer-readable storage medium. The memory 1005 can be used to store instructions, programs, codes, code sets, or instruction sets. The memory 1005 can include a program storage area and a data storage area, wherein the program storage area can store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area can store data involved in the above-mentioned various method embodiments, etc. The memory 1005 can alternatively be at least one storage system located away from the aforementioned processor 1001. As shown in the figure, the memory 1005 as a computer storage medium can include an operating system, a network communication module, a user interface module, and a portable printing application based on a custom template. Figure 8 As shown in the figure, the memory 1005 as a computer storage medium can include an operating system, a network communication module, a user interface module, and a portable printing application based on a custom template.

[0137] In Figure 8In the electronic device 1000 shown, the user interface 1003 is mainly used to provide an interface for user input and obtain user input data; and the processor 1001 can be used to call a portable printing application based on a customized template stored in the memory 1005, and specifically perform the following operations:

[0138] receiving a document printing request sent by the mobile terminal, the document printing request carrying a target template ID and to-be-printed data;

[0139] obtaining target template configuration information corresponding to the target template ID from a mapping relationship between the template ID and the template configuration information, the mapping relationship being configured based on a visual template configuration interface of a WebExcel control;

[0140] performing template rendering and protocol adaptation according to the to-be-printed data and the target template configuration information, generating an image printing instruction, and sending the image printing instruction to a current printer connected to the server.

[0141] In one embodiment, when the processor 1001 performs template rendering and protocol adaptation according to the to-be-printed data and the target template configuration information to generate an image printing instruction, it specifically performs the following operations:

[0142] generating to-be-printed content according to the to-be-printed data and the target template configuration information;

[0143] calling a Node.js server-side rendering engine to render the to-be-printed content to obtain a target image to be printed;

[0144] obtaining a target protocol of a current printer connected to the server;

[0145] in a case where a printing protocol existing in the target template configuration information is inconsistent with the target protocol, performing protocol adaptation on the target image based on the target protocol to obtain an image printing instruction corresponding to the target image.

[0146] In one embodiment, when the processor 1001 performs protocol adaptation on the target image based on the target protocol to obtain an image printing instruction corresponding to the target image, it specifically performs the following operations:

[0147] parsing the target protocol to obtain printing protocol information;

[0148] determining a printing format parameter supported by the current printer according to the printing protocol information;

[0149] calling a Pillow image processing library or an OpenCV image processing library to convert the target image into an image format conforming to the printing format parameter to obtain a converted monochrome bitmap image;

[0150] The target image corresponding image printing instruction is generated based on the monochrome bitmap image.

[0151] In one embodiment, the processor 1001, when executing the target image corresponding image printing instruction generated based on the monochrome bitmap image, specifically executes the following operations:

[0152] In the case where the printing protocol supported by the current printer is the TSPL protocol, the monochrome bitmap image is encapsulated as a BITMAP instruction of the TSPL protocol; or,

[0153] In the case where the printing protocol supported by the current printer is the CPCL protocol, the monochrome bitmap image is encapsulated as an EG instruction of the CPCL protocol; wherein the instruction attribute in the BITMAP instruction or the EG instruction includes the starting coordinates of the image on the printing paper, the width and height of the image, and the binary data of the image.

[0154] The BITMAP instruction or the EG instruction is combined with the preset control instruction of the current printer to obtain the target image corresponding image printing instruction.

[0155] In one embodiment, the processor 1001, when executing the target image corresponding image printing instruction generated based on the monochrome bitmap image, specifically executes the following operations:

[0156] In response to the template configuration instruction for the target template type, a visual template configuration interface implemented based on a WebExcel control is displayed, and the visual template configuration interface includes a custom configuration component and an automatic configuration component;

[0157] In response to the trigger instruction for the displayed custom configuration component or the automatic configuration component, the template configuration information of the target template type is generated;

[0158] The template ID of the target template type is obtained;

[0159] The mapping relationship between the template ID and the template configuration information is stored.

[0160] In one embodiment, the processor 1001, when executing the target template type template configuration information, specifically executes the following operations:

[0161] In the case where the trigger instruction is that the user triggers the custom configuration component, a template editing form of the target template type is displayed;

[0162] In response to the field dragging instruction and / or the field format setting instruction and / or the template element layout planning instruction for the template editing form, the final position and format of each field are obtained, and the final template layout is determined;

[0163] receive a data source and a binding rule for a field attribute setting of each field of the template editing form, to obtain an attribute strategy of each field;

[0164] take the final position and format of each field, the strategy attribute, and the final template layout as the template configuration information of the target template type.

[0165] In one embodiment, the processor 1001, when performing the generation of the template configuration information of the target template type, specifically performs the following operations:

[0166] In the case where the trigger instruction is triggered by a user to obtain the automation configuration component, receive the template requirement description information and the example graph sent by the mobile terminal;

[0167] Parse the template requirement description information to extract the existing key fields and their attributes, to obtain structured field data;

[0168] From the structured field data, obtain the final position and format of each field, the strategy attribute;

[0169] From the structured field data, determine the data source and the binding rule corresponding to the field attribute of each field, to obtain the attribute strategy of each field;

[0170] Perform layout analysis based on the example graph to determine the final template layout;

[0171] Take the final position and format of each field, the strategy attribute, and the final template layout as the template configuration information of the target template type.

[0172] In one embodiment, the processor 1001, when performing the layout analysis based on the example graph to determine the final template layout, specifically performs the following operations:

[0173] Perform binaryzation processing on the example graph to segment out a grayscale image containing text / graphics and background regions;

[0174] Recognize all text contents and their positions in the grayscale image to obtain a text detection result;

[0175] Detect all graphic elements existing in the grayscale image to obtain a graphic detection result;

[0176] According to the text detection result and the graphic detection result, segment the grayscale image into a plurality of layout regions, each of which contains at least one text box or graphic;

[0177] Based on the at least one text box or graphic contained in each layout region, classify each layout region to obtain an information presentation type of each layout region;

[0178] taking the center point of each layout area as the relative position of each layout area;

[0179] taking the relative position of each layout area and the information presentation type of each layout area as the final template layout.

[0180] In one embodiment, the processor 1001, when generating the to-be-printed content according to the to-be-printed data and the target template configuration information, specifically performs the following operations:

[0181] judging, from the to-be-printed data, whether there is a target character identical to the placeholder name in the format or the data source of each field;

[0182] if yes, processing the target field through the formatting instruction in the binding rule of each field to obtain a print-ready value of each field;

[0183] if no, performing numerical completion through the default value or the calculation expression in the binding rule of each field to obtain a print-ready value of each field;

[0184] combining the print-ready value of each field with the final position and the format of each field to obtain a positioning value object of each field;

[0185] matching the relative position and the information presentation type of each layout area with the positioning value object of each field to group all the positioning value objects in the same area to obtain print data of each layout area;

[0186] caching the print data of each layout area to obtain the to-be-printed content.

[0187] In the embodiments of the present application, on the one hand, the visual template configuration interface realized through the WebExcel control enables the user to flexibly adjust the format and content of the template according to specific needs, and the manual or automatic template configuration mode enables the user to quickly adjust the template according to different printing requirements without the need for the back-end personnel to redevelop the template, thereby reducing the workload of the back-end personnel and improving the efficiency of template configuration. On the other hand, the protocol adaptation module can parse the printing protocol of the target printer and adapt the generated image according to the protocol to generate corresponding image printing instructions. The protocol adaptation mechanism ensures that the printing template can be normally printed on different brands and models of printers, solves the cross-device compatibility problem, and enables the system to generate printing instructions conforming to the protocol regardless of whether the printer supports the TSPL or CPCL protocol, thereby ensuring the consistency of the printing effect.

[0188] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by a computer program instructing relevant hardware. The program for portable printing based on a custom template can be stored in a computer readable storage medium. When the program is executed, the program can include the processes of the above-mentioned embodiment methods. The storage medium of the program for portable printing based on a custom template can be a disk, an optical disk, a read-only memory, a random access memory, or the like.

[0189] The above disclosure is only the preferred embodiments of the present application, and of course cannot limit the scope of the rights of the present application, so the equivalent changes made according to the claims of the present application still fall within the scope of the present application.

Claims

1. A portable printing method based on a custom template, characterized by, Applied to a server side, the method comprises: receiving a document printing request sent by a mobile terminal, the document printing request carrying a target template ID and to-be-printed data; obtaining target template configuration information corresponding to the target template ID from a mapping relationship between template IDs and template configuration information, the mapping relationship being configured based on a visual template configuration interface implemented by a WebExcel control; performing template rendering and protocol adaptation according to the to-be-printed data and the target template configuration information, generating an image printing instruction, and sending the image printing instruction to a current printer connected with the server side; the performing template rendering and protocol adaptation according to the to-be-printed data and the target template configuration information, generating an image printing instruction, comprises: generating to-be-printed content according to the to-be-printed data and the target template configuration information, calling a Node.js server side rendering engine to render the to-be-printed content to obtain a target image to be printed, obtaining a target protocol of a current printer connected with the server side, and performing protocol adaptation on the target image based on the target protocol to obtain an image printing instruction corresponding to the target image in a case where a printing protocol existing in the target template configuration information is inconsistent with the target protocol.

2. The method of claim 1, wherein, the performing protocol adaptation on the target image based on the target protocol to obtain an image printing instruction corresponding to the target image, comprises: parsing the target protocol to obtain printing protocol information; determining a printing format parameter supported by the current printer according to the printing protocol information; calling a Pillow image processing library or an OpenCV image processing library to convert the target image into an image format conforming to the printing format parameter to obtain a converted monochrome bitmap image; generating the image printing instruction corresponding to the target image based on the monochrome bitmap image.

3. The method of claim 2, wherein, the generating the image printing instruction corresponding to the target image based on the monochrome bitmap image, comprises: in a case where a printing protocol supported by the current printer is a TSPL protocol, encapsulating the monochrome bitmap image into a BITMAP instruction of the TSPL protocol; or in a case where a printing protocol supported by the current printer is a CPCL protocol, encapsulating the monochrome bitmap image into an EG instruction of the CPCL protocol; wherein, instruction attributes in the BITMAP instruction or the EG instruction include starting coordinates of an image on printing paper, width and height of the image, and binary data of the image; combining the BITMAP instruction or the EG instruction with a preset control instruction of the current printer to obtain the image printing instruction corresponding to the target image.

4. The method of claim 1, wherein, before the receiving the document printing request sent by the mobile terminal, the method further comprises: in response to a template configuration instruction for a target template type, displaying a visual template configuration interface implemented based on a WebExcel control, the visual template configuration interface comprising a custom configuration component and an automatic configuration component; In response to the trigger instruction for the custom configuration component or the automatic configuration component of the display, generate template configuration information of the target template type; Obtain a template ID of the target template type; Store a mapping relationship between the template ID and the template configuration information.

5. The method of claim 4, wherein, The generation of the template configuration information of the target template type comprises: In the case where the trigger instruction is that a user triggers the custom configuration component, display a template editing form of the target template type; In response to a field dragging instruction and / or a field format setting instruction and / or a template element layout planning instruction for the template editing form, obtain a final position and format of each field, and determine a final template layout; Receive a data source and a binding rule of a field attribute setting of each field of the template editing form, to obtain an attribute strategy of the each field; The final position and format of the each field, the strategy attribute, and the final template layout are taken as the template configuration information of the target template type.

6. The method of claim 4, wherein, The generation of the template configuration information of the target template type comprises: In the case where the trigger instruction is that a user triggers the automatic configuration component, receive template requirement description information and an example graph sent by a mobile terminal; Parse the template requirement description information to extract existing key fields and their attributes, to obtain structured field data; From the structured field data, obtain a final position and format of each field, a strategy attribute; From the structured field data, determine a data source and a binding rule corresponding to a field attribute of each field, to obtain an attribute strategy of the each field; Based on the example graph, perform layout analysis to determine a final template layout; The final position and format of the each field, the strategy attribute, and the final template layout are taken as the template configuration information of the target template type.

7. The method of claim 6, wherein, The layout analysis based on the example graph to determine the final template layout comprises: Perform binaryzation processing on the example graph to segment a gray-scale image containing text / graphics and background regions; Identify all text contents and their positions in the gray-scale image to obtain a text detection result; Detect all graphic elements existing in the gray-scale image to obtain a graphic detection result; According to the text detection result and the graphic detection result, segment the gray-scale image into a plurality of layout regions, each of which contains at least one text box or graphic; Based on at least one text box or graphic contained in each layout region, classify the each layout region to obtain an information presentation type of the each layout region; Take a center point of the each layout region as a relative position of the each layout region; Take the relative position of the each layout region and the information presentation type of the each layout region as the final template layout.

8. The method of claim 1, wherein, The target template configuration information comprises a final position and format of each field, a data source and a binding rule of each field, a relative position and an information presentation type of each layout region; The generation of the to-be-printed content according to the to-be-printed data and the target template configuration information comprises: judging whether there is a target character same as a placeholder name in the format of each field or the data source from the to-be-printed data; if yes, processing the target field through a formatting instruction in the binding rule of each field to obtain a print-ready value of each field; if no, performing value completion through a default value or a calculation expression in the binding rule of each field to obtain the print-ready value of each field; combining the print-ready value of each field with a final position and format of each field to obtain a positioning value object of each field; matching the relative position and information presentation type of each layout area with the positioning value object of each field to group all positioning value objects in the same area to obtain print data of each layout area; caching the print data of each layout area to obtain to-be-printed content.

9. A custom template based portable printing system implemented using the method of any of claims 1-8, wherein, The system comprises: a request receiving module configured to receive a document printing request sent by a mobile terminal, the document printing request carrying a target template ID and to-be-printed data; a template configuration information obtaining module configured to obtain target template configuration information corresponding to the target template ID from a mapping relationship between template IDs and template configuration information, the mapping relationship being configured based on a visual template configuration interface of a WebExcel control; a printing instruction sending module configured to perform template rendering and protocol adaptation according to the to-be-printed data and the target template configuration information, generate an image printing instruction, and send the image printing instruction to a current printer connected to the server.

Citation Information

Patent Citations

  • Document output method and device based on printing template, computer equipment and medium

    CN115357201A

  • Dynamic configuration method and device of printing template, equipment and storage medium

    CN116009796A