Word template engine method supporting HTML (Hypertext Markup Language) local rendering

Through the Word template engine that supports HTML local rendering, the combination of template parsing and HTML parsing is used to solve the problem of insufficient template flexibility in the existing technology, and achieve rapid customization and efficient updates, improving the personalization and document of printed content interactive.

CN119227637APending Publication Date: 2024-12-31SUZHOU REKTEC INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411246309.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-06
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

The existing Word template engine does not provide enough flexibility to meet customers’ needs for local customization of printed content, and must start from scratch every time a new template is required, resulting in increased repetitive work.

Method used

It provides a Word template engine that supports HTML local rendering. Through the combination of template parsing, HTML parsing, content filling and attribute style injection, it allows users to quickly adjust and customize print templates, achieving flexible adjustment of local content and efficient updates of the overall document.

Benefits of technology

It improves the flexibility and rendering effect of templates, reduces the need for global updates, optimizes resource usage, reduces time and cost consumption, and enhances dynamic adaptability to templates and interactive documents.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119227637A_ABST
    Figure CN119227637A_ABST
Patent Text Reader

Abstract

The invention discloses a Word template engine method supporting HTML (Hypertext Markup Language) local rendering, which comprises the following steps: S1, initiating a template printing request, and sending the template printing request to a template engine in combination with a printing template and printing data; s2, receiving and analyzing the printing template by the template engine, identifying elements in the template, and extracting a template label on the template; s3, the template engine searches for an HTML tag needing local rendering, and HTML content is converted into a format needed by Word; s4, rendering the analyzed HTML (Hypertext Markup Language) content into a Word document; s5, other parts in the template are rendered until all elements of the whole document are processed; and S6, generating a Word document, and outputting and printing the Word document. By providing flexible template customization and local content adjustment functions, the problem of insufficient template flexibility in the prior art is effectively solved. According to the method, the user is allowed to quickly adjust and customize the printing template according to different business scenes, the personalized printing requirement is met, and meanwhile, the specialty and consistency of the document are kept.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of electronic digital data processing, in particular to the technical field of digital output on a printing device, and specifically to a method of a Word template engine supporting HTML local rendering. Background Art

[0002] Word template engine is a software tool that allows users to create and use Word document templates. These templates can contain predefined formats, styles, text placeholders, etc. Users can generate documents with uniform formatting and styles by filling in the placeholders in the template. Template printing is a document processing technology that allows users to generate documents using predefined formats and layouts. HTML partial rendering usually refers to updating only a part of the page instead of the entire page in web page development. This technology can improve user experience and page performance because it reduces the need for data transfer and page redrawing.

[0003] The prior art, the traditional Word template engine cannot provide sufficient flexibility to meet the customer's demand for partial customization of printed content, because these technologies rely on pre-defined templates, which limits the ability to dynamically adjust the templates, but customers hope to be able to quickly adjust and customize the printing templates in different business scenarios to adapt to specific printing needs. The prior art "Nuclear Power Plant Word File to Template-based HTML File Conversion Method and Device" mainly focuses on converting the Word file content into a format based on HTML templates. The core of this conversion method is to create an HTML file template, and then inject the text content and graphic content in the Word file into the HTML template. Although this method realizes the conversion from Word to HTML to a certain extent, it has obvious limitations in meeting the customer's personalized needs for partial customization of printed content. The prior art injects the Word file content into a pre-defined HTML template. This method requires the template to be created in advance, and once the template is determined, its flexibility will be greatly limited. The user cannot flexibly adjust the local content or style of the template according to his own needs; and every time a new template needs to be made, it must start from scratch, which will lead to a lot of repetitive work.

[0004] Therefore, it is necessary to improve the Word template engine in the prior art to solve the above problems. Summary of the invention

[0005] The present invention overcomes the shortcomings of the prior art and provides a method for a Word template engine supporting HTML local rendering, aiming to solve the problem of creating templates in advance in the prior art and the problem that a new template must be created from scratch each time it is needed.

[0006] To achieve the above object, the technical solution adopted by the present invention is: a method of a Word template engine supporting HTML partial rendering, comprising the steps of:

[0007] S1. Initiate a template printing request, and send the combined printing template and printing data to the template engine;

[0008] S2, the template engine receives and parses the print template, identifies the elements in the template, and extracts the template tags on the template;

[0009] S3, the template engine searches for HTML tags that need to be partially rendered and converts the HTML content into the format required by Word;

[0010] S4, rendering the parsed HTML content into a Word document;

[0011] S5. Render the rest of the template until all elements of the entire document are processed;

[0012] S6. Generate a Word document for output and printing.

[0013] In a preferred embodiment of the present invention, in step S1,

[0014] S11. Clarify printing requirements;

[0015] S12, determining the printing template;

[0016] S13, collecting printing data to be filled into the template;

[0017] S14, sending the printing template and printing data to the template engine.

[0018] In a preferred embodiment of the present invention, in step S2, the template parsing process includes:

[0019] S21, obtaining a template file, and parsing all elements in the template file;

[0020] S22, traverse all elements and check whether they contain template HTML tags;

[0021] S23, when there is a template HTML tag, parse the type, attribute and style through the HTML tag parser, and store the data in the metadata structure;

[0022] S24. When there is no template HTML tag, skip the step of parsing the tag.

[0023] In a preferred embodiment of the present invention, in step S3, HTML is parsed to find HTML tags that need to be partially rendered, and the process includes:

[0024] S31, searching for the type in the metadata structure created by the template parsing process;

[0025] S32, select the structure type as HTML;

[0026] S33, searching the HTML element data from the data model by the field name defined in the tag;

[0027] S34, passing the HTML data to the HTML parser, and traversing the document object model tree of the HTML;

[0028] S35. Parse the content, attributes, and styles, and store them into HTML elements.

[0029] In a preferred embodiment of the present invention, in step S3, the HTML content is converted into the format required by Word, and the content filling, attributes and styles are injected. The process includes:

[0030] S36, obtaining the assembled HTML element;

[0031] S37, extracting content from the HTML element and selecting a corresponding content parser;

[0032] S38. Get a list of attributes from the HTML element, traverse the attributes and select a corresponding attribute parser;

[0033] S39. Get a style list from the HTML element, traverse the styles and select a corresponding style parser.

[0034] In a preferred embodiment of the present invention, in step S4, the local rendering process includes:

[0035] S41, obtaining the partially rendered HTML tag content that has been filled with content and injected with attributes and styles;

[0036] S42, binding the locally rendered HTML tag content to the position to be rendered by Word;

[0037] S43, rendering the locally rendered HTML tag content into the entire Word document.

[0038] In a preferred embodiment of the present invention, in step S6, the generated Word document is stored as a print template file.

[0039] The present invention provides a product of a Word template engine supporting HTML local rendering, including: a computer program product, wherein the computer program product includes a computer program.

[0040] The present invention provides a device of a Word template engine supporting HTML local rendering, comprising: an electronic device, wherein the electronic device comprises a memory, a processor, and a computer program stored in the memory and executable on the processor.

[0041] The present invention solves the defects existing in the background technology and has the following beneficial effects:

[0042] (1) The present invention provides a method for a Word template engine that supports HTML partial rendering. The engine effectively solves the problem of insufficient template flexibility in the prior art by providing flexible template customization and partial content adjustment functions. This method allows users to quickly adjust and customize printing templates according to different business scenarios to meet personalized printing needs while maintaining the professionalism and consistency of the document.

[0043] (2) The present invention utilizes the combination of template parsing and HTML parsing, as well as content filling and attribute style injection, which together constitute the core process of the template engine processing HTML templates and data models, and are the basis for realizing HTML local rendering. In the template parsing stage, the system searches for HTML type data in the metadata and traverses the document object model tree, thereby ensuring the accuracy of data processing and the efficiency of resource utilization; in the content filling and attribute style injection stage, the assembled HTML elements are obtained, and then the appropriate parser is selected for filling according to the specific content of the elements. The highly fine-grained processing method not only improves the flexibility of the template, but also enhances the richness and accuracy of the rendering effect; it realizes the precise mapping and efficient conversion from the data model to the HTML template. Template parsing and HTML parsing ensure the accuracy of the data and the comprehensiveness of the parsing, while content filling and attribute style injection further enhance the flexibility of the template and the rendering effect.

[0044] (3) The present invention utilizes a combination of local rendering technology and overall document integration. Local rendering technology allows users to update only specific parts of a document without affecting other content; improves the efficiency of document updates and reduces the need for comprehensive document reconstruction; compared with existing technologies, which usually require the entire document to be regenerated to achieve updates; optimizes resource usage and reduces the time and cost consumption caused by comprehensive document updates.

[0045] (4) The present invention utilizes the combination of template element recognition and tag extraction. The template engine can recognize elements in the template and extract tags, providing precise control for local rendering; enhancing the ability to locate and adjust the local content of the template, improving the dynamic adaptability of the template; simplifying the template modification process, and speeding up the template customization.

[0046] (5) The present invention utilizes the combination of HTML content conversion and Word format compatibility to convert HTML content into a format supported by Word, thereby ensuring consistent display of content from different sources; allowing users to seamlessly integrate HTML elements into Word documents, thereby enriching the expressiveness of the documents; and expanding the application scope of Word templates, thereby improving the interactivity and visual appeal of documents. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art are briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work.

[0048] Figure 1 is a flowchart of the overall HTML local rendering execution of a preferred embodiment of the present invention;

[0049] Figure 2 is a template parsing flow chart of a preferred embodiment of the present invention;

[0050] Figure 3 It is a flow chart of HTML parsing of a preferred embodiment of the present invention;

[0051] Figure 4 is a flow chart of content filling, attribute and style injection in a preferred embodiment of the present invention;

[0052] Figure 5 is a local rendering flow chart of a preferred embodiment of the present invention;

[0053] Figure 6 It is a maintenance information template diagram of a preferred embodiment of the present invention;

[0054] Figure 7 It is a maintenance information effect diagram of a preferred embodiment of the present invention;

[0055] Figure 8 It is a maintenance waveform HTML page diagram of a preferred embodiment of the present invention;

[0056] Fig. 9 It is a template diagram after adding HTML page tags in a preferred embodiment of the present invention;

[0057] Fig.10 It is the final effect diagram of the preferred embodiment of the present invention. DETAILED DESCRIPTION

[0058] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0059] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein. Therefore, the protection scope of the present invention is not limited to the specific embodiments disclosed below.

[0060] In the description of this application, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be directly connected or indirectly connected through an intermediate medium, and it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood by specific circumstances.

[0061] A method for a Word template engine supporting HTML partial rendering comprises the following steps:

[0062] S1. Initiate a template printing request, and send the combined printing template and printing data to the template engine;

[0063] S2, the template engine receives and parses the print template, identifies the elements in the template, and extracts the template tags on the template;

[0064] S3, the template engine searches for HTML tags that need to be partially rendered and converts the HTML content into the format required by Word;

[0065] S4, rendering the parsed HTML content into a Word document;

[0066] S5. Render the rest of the template until all elements of the entire document are processed;

[0067] S6. Generate a Word document for output and printing.

[0068] Specifically in step S1, the printing template includes the structure and format of the document, and the printing data is the specific content filling the template.

[0069] S11. Clarify printing requirements; requirements include printing content, format, quantity, etc.

[0070] S12, determining the printing template;

[0071] S13. Collect the printing data to be filled into the template; the printing data includes: text, numbers, pictures, videos and other data; ensure the accuracy and completeness of the data so that the data can be correctly inserted into the template;

[0072] S14, sending the printing template and printing data to the template engine.

[0073] Furthermore, in step S12, the requirements for determining the printing template include: determining the type of document, ensuring that the visual effects of the document meet the requirements, identifying the locations in the document that need to be filled with actual data, and determining the locations and formats of pictures and tables; by clarifying the above requirements, ensure that a printing template that meets actual needs is developed, laying a solid foundation for the subsequent document generation process.

[0074] The purpose of step S1 is to prepare and send a print request to the template engine, ensuring that the template engine can receive the correct print template and print data, so that the template can be parsed and rendered step by step, and finally generate and output the Word document to be printed. Step S1 provides the necessary foundation and initial data for the entire printing process, paving the way for subsequent template parsing and rendering, and ensuring that the final output Word document is consistent with user needs.

[0075] like Figure 2 As shown, in the specific step S2, after obtaining the printing template and template data, the template engine first needs to parse the template. The template parsing process includes:

[0076] S21, obtaining a template file, and parsing all elements in the template file;

[0077] S22, traverse all elements and check whether they contain template tags;

[0078] S23. When there is a template tag, the type, attribute and style are parsed by the tag parser, and the data is stored in the metadata structure;

[0079] Furthermore, the parsed type, attribute, and style information will be stored in a data structure called ElementMetadata; this metadata structure is used to record the key information of each HTML tag so that this information can be used in subsequent steps to guide data filling and style application.

[0080] S24, when there is no template tag, skip the step of parsing the tag;

[0081] Specifically, in step S2, the elements include all paragraphs and tables in the template.

[0082] The purpose of step S2 is to ensure that the template engine can correctly and completely parse all elements in the template file, identify the template tags, and build the corresponding metadata structure for each tag to prepare for subsequent rendering and data filling operations, ensuring that the template can be correctly presented according to the design requirements and contain the correct data content.

[0083] like Figure 3 As shown, in step S3, the HTML parsing process is as follows:

[0084] S31. Find the type in the metadata structure created by the template parsing process.

[0085] S32, select a structure of HTML type; ensure that only HTML type data is processed, avoid processing non-HTML type data, and reduce resource waste;

[0086] S33, searching the HTML element data from the data model by the field name defined in the tag;

[0087] S34, passing the HTML data to the HTML parser, and traversing the document object model tree of the HTML;

[0088] S35, parsing content, attributes and styles, and storing them into HTML elements;

[0089] Furthermore, the execution steps of the HTML parser include:

[0090] a. Pass HTML data to the HTML parser; the HTML data is HTML content in string form or a data structure that has been parsed into a document object model;

[0091] b. The HTML parser traverses the nodes and elements of the document object model tree; starting from the root node, it visits each node level by level to check its type, attributes, and child nodes, etc.; ensuring that the HTML data is fully parsed without missing any part;

[0092] c. Determine the type, attributes, and style information for each visited node;

[0093] d. Build metadata structure;

[0094] Furthermore, the step of searching for HTML element data includes:

[0095] a. Get the specified field name from the label;

[0096] b. Find the HTML element data corresponding to the field name in the data model;

[0097] c. Find the matching HTML element data and return it to the caller;

[0098] Furthermore, the data model is DataModel, which stores the structure of data used to fill the template. In the template engine, DataModel is a collection of various data fields, which correspond to the tags in the template. The template engine retrieves the corresponding data from the DataModel through these fields.

[0099] Furthermore, the HTML element is HTMLElement, which is a data structure used by the template engine to represent the parsed HTML tag. HTMLElement contains detailed information about the HTML element, such as tag name, attributes, content, and style. The template engine uses HTMLElement to store the data collected during the parsing process to ensure that the data can be accurately filled into the corresponding position of the template during the rendering phase.

[0100] The document object model tree is a programming interface for HTML or XML documents. It represents documents in the form of a tree structure, where each node is an element, attribute, or text. In the template engine, the HTML parser accesses and manipulates the various parts of the HTML document by traversing the document object model tree in order to parse the content, attributes, and styles.

[0101] like Figure 4 As shown in the content filling, attribute and style injection flow chart, specifically, in step S3, after template parsing and HTML parsing are completed, the data has been parsed and assembled into the target data structure. The next step is to fill the elements with content and inject attributes. This process is mainly implemented through various parsers.

[0102] S36, obtaining the assembled HTML element;

[0103] S37, extracting content from the HTML element and selecting a corresponding content parser;

[0104] Furthermore, if the content is text, a text content parser is used to fill it; if the content is a picture, a picture content parser is used to fill it.

[0105] S38. Get a list of attributes from the HTML element, traverse the attributes and select a corresponding attribute parser;

[0106] Furthermore, if the attribute involves size, the size attribute parser is used to set the length and width of the element. If the attribute involves links, class names, etc., the link attribute parser and class name attribute parser are used to set the resources and visual performance of the element.

[0107] S39. Get a style list from the HTML element, traverse the styles and select a corresponding style parser.

[0108] Furthermore, if the style type is color, a color style parser is used to set a specified color for the element. If the style type involves fonts, margins, etc., a font style parser and a margin style parser are used to set specified font styles and margin lengths for the element.

[0109] Specifically, in step S4,

[0110] After template parsing, HTML parsing, content filling, attribute and style injection, the pre-steps of HTML partial rendering have been completed. The next step is to render this part of the content. The partial rendering process is as follows Figure 5 As shown:

[0111] S41, obtaining the partially rendered HTML tag content that has been filled with content and injected with attributes and styles;

[0112] S42, binding the locally rendered HTML tag content to the position to be rendered in Word; associating the prepared HTML content with a specific position in the Word document.

[0113] S43, rendering the locally rendered HTML tag content into the entire Word document.

[0114] Furthermore, in step S42, the HTML content is converted into a format recognizable by Word, and it is necessary to ensure that the style and format of the HTML content can be correctly rendered and displayed in Word; adjust the style and format settings of the HTML and Word documents, and then insert them into the corresponding position in the document.

[0115] Specifically, in step S5, the rendering process ensures that each element in the document is processed, whether by data filling, style application, or layout adjustment;

[0116] In the specific step S6, all elements in the document are rendered, and the template engine compiles the entire document into a complete Word document, which now contains all dynamically filled data, correctly applied styles and layouts, and all necessary document elements; the generated Word document can be printed directly or used as a print template file for subsequent use.

[0117] Embodiment 1

[0118] In a specific scenario, the user uses a Word print template file to print maintenance information, such as Figure 6 As shown, the printed result is as Figure 7 At the same time, Figure 8As shown in the figure, there is also a form HTML page. In order to realize the requirement of printing the entire page after the maintenance information, a placeholder for the HTML page is added after the maintenance information when designing the template, as shown in the figure. Fig. 9 As shown,

[0119] #{$ds_CabinetPrint.ResultList.customPart(type:HTML)}, and set the type to HTML. Then, Fig. 9 After the HTML page of the template is passed to the template engine for processing, the result is as follows Fig.10 shown.

[0120] In this process, the original maintenance information printing template is retained. At the same time, the HTML page provided by the customer is embedded in the printing result by adding placeholders. The required HTML form page can be printed at the same time as the maintenance information, providing a more flexible solution for the workflow.

[0121] The above is based on the ideal embodiment of the present invention. Through the above description, relevant personnel can make various changes and modifications without departing from the technical concept of the present invention. The technical scope of the present invention is not limited to the content in the specification, and the technical scope must be determined according to the scope of the claims.

Claims

1. A method for a Word template engine supporting HTML partial rendering, characterized in that: Includes steps: S1. Initiate a template printing request, and send the combined printing template and printing data to the template engine; S2, the template engine receives and parses the print template, identifies the elements in the template, and extracts the template tags on the template; S3, the template engine searches for HTML tags that need to be partially rendered and converts the HTML content into the format required by Word; S4, rendering the parsed HTML content into a Word document; S5. Render the rest of the template until all elements of the entire document are processed; S6. Generate a Word document for output and printing.

2. A method for a Word template engine supporting HTML partial rendering according to claim 1, characterized in that: In step S1, S11. Clarify printing requirements; S12, determining the printing template; S13, collecting printing data to be filled into the template; S14, sending the printing template and printing data to the template engine.

3. The method of a Word template engine supporting HTML partial rendering according to claim 1, characterized in that: In step S2, the template parsing process includes: S21, obtaining a template file, and parsing all elements in the template file; S22, traverse all elements and check whether they contain template HTML tags; S23, when there is a template HTML tag, parse the type, attribute and style through the HTML tag parser, and store the data in the metadata structure; S24. When there is no template HTML tag, skip the step of parsing the tag.

4. The method of a Word template engine supporting HTML partial rendering according to claim 1, characterized in that: In step S3, the HTML is parsed to find HTML tags that need to be partially rendered. The process includes: S31, searching for the type in the metadata structure created by the template parsing process; S32, select the structure type as HTML; S33, searching the HTML element data from the data model by the field name defined in the tag; S34, passing the HTML data to the HTML parser, and traversing the document object model tree of the HTML; S35. Parse the content, attributes, and styles, and store them into HTML elements.

5. The method of a Word template engine supporting HTML partial rendering according to claim 1, wherein: In step S3, converting the HTML content into the format required by Word requires content filling, attribute and style injection. The process includes: S36, obtaining the assembled HTML element; S37, extracting content from the HTML element and selecting a corresponding content parser; S38. Get a list of attributes from the HTML element, traverse the attributes and select a corresponding attribute parser; S39. Get a style list from the HTML element, traverse the styles and select a corresponding style parser.

6. The method of a Word template engine supporting HTML partial rendering according to claim 1, characterized in that: In step S4, the local rendering process includes: S41, obtaining the partially rendered HTML tag content that has been filled with content and injected with attributes and styles; S42, binding the locally rendered HTML tag content to the position to be rendered by Word; S43, rendering the locally rendered HTML tag content into the entire Word document.

7. The method of a Word template engine supporting HTML partial rendering according to claim 1, characterized in that: In step S6, the generated Word document is stored as a print template file.

8. A product of a Word template engine supporting HTML partial rendering, based on a method of a Word template engine supporting HTML partial rendering according to any one of claims 1 to 7, comprising: A computer program product comprising a computer program.

9. A device for a Word template engine supporting HTML partial rendering, based on a method for a Word template engine supporting HTML partial rendering according to any one of claims 1 to 7, comprising: An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor.