A method and system for defining a contract form based on a WORD template without code
By embedding replaceable expressions in Word templates and combining them with PDF rendering and coordinate transformation, code-free automated generation of contract forms was achieved, solving the problem of low coupling between forms and print templates and improving development efficiency and document generation quality.
Patent Information
- Application Number
- CN202511341166.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-19
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2045-09-19
AI Technical Summary
In existing technologies, the form and printing modules of contract and agreement documents have low development coupling, resulting in long development cycles, high maintenance costs, and easy introduction of errors, making it difficult to quickly adapt to changes in document structure.
By adopting a no-code definition method based on Word templates, a list of control objects is generated by embedding replaceable expressions in the Word template and combining PDF rendering and coordinate transformation to achieve the automatic generation and synchronization of floating web contract forms.
It enables automatic synchronization between the form interface and the print template, reducing repetitive development work, improving the system's ability to respond to business changes, enhancing maintenance efficiency and document generation quality, and avoiding the process of manually locating text boxes.
Smart Images

Figure CN120832877B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the field of contract or agreement content filling in government affairs system and enterprise management system, and particularly relates to a method and system for defining a contract form based on a WORD template without coding. BACKGROUND
[0002] In a government affairs management system or an enterprise management system, contract and agreement content filling is a common functional requirement. This kind of function is usually used in various administrative examination and approval, business cooperation and legal document generation scenarios, and its implementation generally includes two main technical links: one is to develop a WEB contract form page for data collection, and the user fills in the key information of the contract through the form; the other is to generate a standardized report that can be printed or archived according to the filled information, and the commonly used technical means include customized WEB printing page, dynamically generating a PDF document based on a WORD template, etc.
[0003] However, the prior art has obvious defects. First, contract and agreement documents usually have complex structures and various formats, and need to be frequently adjusted due to changes in business types, laws and regulations or internal specifications of the unit. Whenever the document structure or content requirements change, the developer must modify both the form entry interface and the corresponding printing generation module, and the two parts of code are usually low in coupling degree and greatly different in technical implementation, resulting in the need to repeatedly adjust the same business logic in multiple locations. Second, the traditional form and report development method relies heavily on manual coding, which not only has a long development cycle and high maintenance cost, but also easily introduces errors due to inconsistent modifications in multiple places, reducing the reliability and consistency of the system. Therefore, there is an urgent need for a technical method that can automatically generate forms and their corresponding printouts. SUMMARY
[0004] The purpose of the present application is to solve the problem of large development workload of filling report form pages in the prior art when developing contract agreement filling functions, and to provide a method and system for defining a contract form based on a WORD template without coding.
[0005] In order to achieve the above-mentioned purpose of the application, the following technical solutions are specifically adopted in the present application:
[0006] In the first aspect, the present application provides a method for defining a contract form based on a WORD template without coding, which includes the following steps:
[0007] S1. The backend obtains a Word template file input from the front end through an interactive protocol, wherein the Word template file is pre-defined with replaceable expressions, and the replaceable expressions are formed by embedding a specific markup language in the text form field domain of the Word contract document, and each text form field domain corresponds to a to-be-filled form field of the Word contract document;
[0008] S2. After the backend receives the Word template file and stores it to the specified directory, it parses and extracts all replaceable expressions in the file as form parameters, and creates a corresponding control object for each form parameter to form a list of control objects, and encapsulates the control object attributes;
[0009] S3. The backend generates an empty parameter mapping according to the list of control objects obtained by parsing, and then combines the Word template file with the parameter mapping to perform template rendering, replacing all replaceable expressions in the Word template file with corresponding empty values or initial values, and generates an uncompleted Word document with the same control object attributes as the Word template file and converts it to PDF format, and outputs a PDF template file;
[0010] S4. The backend reads the byte stream of the PDF template file, creates a PDF document object to represent the PDF template file, and obtains the total number of pages of the PDF template file through the PDF document object, and then renders the PDF template file page by page and saves the images obtained by rendering each page of the PDF template file in page order;
[0011] S5. The backend obtains the interactive form object through the PDF document object and traverses all fields in the interactive form object, filters out the fields of type text as text input fields, creates a new control object for each text input field and sets the attributes, and adds the newly created control object to a list to form a new list of control objects parsed from the PDF template file;
[0012] S6. The front end obtains the images obtained in S4 and the new list of control objects generated in S5, takes the images as the background, obtains text boxes based on the new list of control objects and suspends them on the images, forms a suspended WEB contract form and visualizes the output.
[0013] On the basis of the above scheme, each step can be implemented in the following preferred specific manner.
[0014] As a preferred embodiment of the first aspect, in step S2, the control object attributes include four types, the first type is style and appearance attributes, including font, font size, text alignment and format; the second type is layout and position attributes, including X-axis offset, Y-axis offset, page number, width, height, page width and page height; the third type is identification and logic attributes, including name, control type, whether required, value list and placeholder text; the fourth type is extension and advanced attributes, including extension options, interface parameter name, handwriting content and editing type.
[0015] As a preferred embodiment of the first aspect, in step S4, the following operations are performed on each page of the PDF template file to realize rendering: converting the current page of the PDF template file to a PNG format image at a preset rendering resolution.
[0016] As a preferred embodiment of the first aspect, in step S5, the specific process of creating a new control object for a text input field is as follows: all display components corresponding to the text input field on a page of the PDF template file are obtained, and the position rectangular frame information of each display component is extracted, and the height and width of the page are obtained, and after the coordinate system conversion of the PDF template file, a new control object is created for the text input field; wherein the position rectangular frame information includes the two-dimensional coordinates of the lower left corner of the display component, the width and the height.
[0017] As a preferred embodiment of the first aspect, in step S5, when the PDF template file is subjected to coordinate system conversion, the origin of coordinates is modified from the lower left corner to the upper left corner, and when moving from the origin along the vertical direction downward, the vertical direction coordinate increases.
[0018] As a preferred embodiment of the first aspect, in step S6, when the Word template file has a case where list information needs to be inserted, the field type is expanded to a div table element, and when forming a floating WEB contract form, the list of control objects is dynamically rendered and the form unit data is saved.
[0019] In a second aspect, the present application provides a system for defining a contract form based on a WORD template without coding, which comprises:
[0020] A document acquisition module for acquiring an original Word template for form generation;
[0021] A form generation module for processing the original Word template according to the method for defining a contract form based on a WORD template without coding according to any one of the first aspect to generate a floating WEB contract form;
[0022] A contract form switching module for establishing a page navigation index based on the page number attribute in the new list of control objects on the front end, and when receiving a user page calling request, the front end automatically loads the picture of the corresponding page and the control object bound to the page to dynamically render the floating WEB contract form of the page, realizing seamless switching;
[0023] A data interaction module for associating the floating control rendered by the control object on the front end with the parameter mapping through bidirectional data binding, and when a data update event is triggered, the parameter mapping is updated in real time, and based on the interaction configuration of the control object, the state of other control objects associated with the control object is changed;
[0024] The check and storage module is used for reading the control object attribute by the front end when monitoring the data submission or page switching event, performing real-time check, returning visual prompt in the case of empty, format mismatch or value not in the preset list, and synchronizing the actual filling data in the parameter mapping to the runtime parameter list of the back end according to the key-value pair structure of the control name-actual filling data after the check, and updating the runtime parameter list by calling the staging interface.
[0025] The PDF file generation module is used for serializing the runtime parameter list into a JSON format file as the input parameter of Word to PDF after the back end receives the user confirmation filling completion instruction, matching the key-value pair in the JSON format file with the replaceable expression in the original Word template to replace the actual filling data to generate a filled Word document, and converting the filled Word document into a PDF format by a document conversion tool to form a complete contract PDF file for the user to download or sign.
[0026] In a third aspect, the present application provides a computer program product, comprising computer programs / instructions, which, when executed by a processor, can realize the method for defining a contract form based on a WORD template without code according to any one of the first aspect.
[0027] In a fourth aspect, the present application provides a computer readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the method for defining a contract form based on a WORD template without code according to any one of the first aspect is realized.
[0028] In a fifth aspect, the present application provides a computer electronic device, comprising a memory and a processor.
[0029] The memory is used for storing a computer program.
[0030] The processor is used for realizing the method for defining a contract form based on a WORD template without code according to any one of the first aspect when the computer program is executed.
[0031] Compared with the prior art, the present application has the following beneficial effects:
[0032] The method of the present application is based on WORD template codeless configuration of the suspended WEB contract form, through form input box definition on the contract and agreement template, form information can be directly filled in on the contract and agreement template, PDF is generated according to the example data, which has good configurability and flexibility, can quickly adapt to the change of document structure, realizes the automatic synchronization between the form interface and the printing template, thereby reducing the repeated development work, improving the ability of the system to respond to business changes, improving the maintenance efficiency and document generation quality, avoiding the workload of coding and filling form function on the contract full text or key field. More importantly, the present application solves the problem that the Word template cannot obtain the position information of the text box in the form conversion process: the present application converts the text field into PDF to obtain the positioning information, and then converts the coordinates into the positioning information of the text box, realizes the automatic positioning of the text box position, simplifies the process of manually dragging the text box to the correct position and the parameter mapping process during form definition. In addition, the present application introduces an automatic generation mechanism, which has important practical application value and significant economic benefits, especially in the processing of variable documents such as contracts and agreements. BRIEF DESCRIPTION OF DRAWINGS
[0033] Figure 1 The step flow chart of the method of the present application is shown in the figure;
[0034] Figure 2 The Word template file schematic diagram of the method of the present application is shown in the figure;
[0035] Figure 3 The generated suspended WEB contract form schematic diagram of the method of the present application is shown in the figure;
[0036] Figure 4 The system component module schematic diagram of the present application is shown in the figure;
[0037] Figure 5 The computer electronic equipment component schematic diagram of the present application is shown in the figure. DETAILED DESCRIPTION
[0038] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and easy to understand, the specific embodiments of the present application will be described in detail below. In the following description, a lot of specific details are set forth in order to fully understand the present application. However, the present application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar improvements without departing from the connotation of the present application, therefore the present application is not limited by the specific embodiments disclosed below. The technical features in each embodiment of the present application can be combined accordingly without conflict.
[0039] In the description of the present application, it should be understood that the terms "first", "second" are only used for distinguishing purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the technical features indicated. Therefore, the features defined with "first", "second" can be explicitly or implicitly included at least one of the features.
[0040] As shown in the preferred implementation of the present application, the method for defining contract form based on WORD template without code includes the following steps S1-S6. The specific implementation process will be described below. Figure 1
[0041] I. Word template definition
[0042] S1. The backend obtains the Word template file input from the front end through the interactive protocol, and the Word template file is pre-defined with replaceable expressions, which are embedded in the text form field of the Word contract document using a specific markup language, and each text form field corresponds to a form field to be filled in the Word contract document.
[0043] It should be noted that in step S1 of the present application, in Microsoft Word, click "Insert" - "Document Parts" - "Form" - "Text Form Field" in the menu bar in sequence, which is usually displayed in the form of a gray bottom line input box in the document, used to define a field for user to fill in the text in the form, thereby defining a text field (form field) in the Word contract document.
[0044] It should be noted that in step S1 of the present application, the markup language is POI-TL, which can generate a markup placeholder in the Word contract document. The placeholder can be parsed and replaced by POI-TL and the like in the subsequent process, thereby dynamically replacing {{company Name} with specific company name data, achieving batch automatic generation of document content, as shown in Figure 2
[0045] It should be noted that in step S1 of the present application, the front end sends the Word template file to the back end through the pre-set front-end and back-end interactive protocol, and the back end receives the Word template file and stores it in a specified directory.
[0046] As an implementation, the front end can send the Word template file to the back end through a file selection form (e.g. a file selection form in the browser) <input type="file"> The local Word template file is selected, and the file is sent to the file upload API address provided by the backend through an HTTP request. The Word template file can be transmitted to the backend in the form of a binary stream through the network. The backend receives the HTTP request through the file upload API, parses the request, extracts the file stream and file name metadata, and writes the received Word template file to a pre-configured directory. The Word template file is persistently saved in the directory, and the storage path, name and other information of the file are recorded for subsequent searching and using. Thus, the file uploading and storage process is completed.
[0047] In addition, it should be noted that the front end of step S1 of the present application refers to any code running on the user side responsible for collecting files and initiating requests. The backend runs on the server and is responsible for receiving byte streams and persisting applications and server environments. It can be a server program (such as an application written in Java, Python, C#, Node.js, etc.), an API interface, or a server resource (physical server, cloud server, or container), etc. The front-end and back-end interaction protocol can be regarded as an agreement between the front-end and back-end on "how to transfer data". All fields, paths, and return formats of the Word template file during transmission are defined by the pre-defined front-end and back-end interaction protocol. In the implementation process of the present application, the specific protocol used can be selected by a person skilled in the art according to the description to implement the corresponding language and framework, and therefore is not limited in the present application. The specified directory can be regarded as an absolute path on the server or a mapped cloud storage space.
[0048] II. Parsing the Word template file
[0049] S2. The backend parses the Word template file, extracts all replaceable expressions in the Word template file as form parameters, and creates a corresponding control object for each form parameter to form a control object list and encapsulate the control object attributes.
[0050] It should be noted that in step S2 of the present application, the Word template file is input and parsed and scanned to find all text segments (i.e. replaceable expressions) surrounded by specific markers. Each time a form parameter is found, a control object is instantiated. Finally, a control object list is obtained, and each control object in the list corresponds to a form parameter in the Word template file.
[0051] It should be noted that in step S2 of the present application, the control object attributes are of four types, the first type is the style and appearance attribute (Styling & Appearance), including font, font size, text alignment and format; the second type is the layout and position attribute (Layout & Position), including X-axis offset, Y-axis offset, page number, width, height, page width and page height; the third type is the identification and logic attribute (Identification & Logic), including name, control type, whether mandatory, value list and placeholder text; the fourth type is the extension and advanced attribute (Extension & Advanced), including extension options, interface parameter name, handwritten content and editing type.
[0052] In the present embodiment, the font Family property is used to define the font type adopted by the text content of the control, ensuring that the final generated document is completely consistent with the font style of the original Word template file. The fontSize property is used to define the size of the text content of the control, maintaining visual consistency of the text size; the text Align property is used to define the horizontal alignment of the text within the control, controlling the layout of the text, such as centering the title; the format property is used to define the display or validation format rules of the control value, standardizing the input and display of data, ensuring data compliance; the offset X property is the horizontal distance of the top-left corner of the control relative to the top-left corner of the page it is located on, and the offset Y property is the vertical distance of the top-left corner of the control relative to the top-left corner of the page it is located on, both of which can uniquely determine the position of the control on the page; the page property is the page number of the control, used to locate the control in a multi-page Word template file; the width property is the width of the control itself, and the height property is the height of the control itself, both of which determine the width or height of the display area of the control, and content that is too long or too high may be automatically hidden; the page Width property and the page Height property represent the total width and total height of the page where the control is located, respectively, providing a reference for the page coordinate system; the name property is the unique identifier of the control, which can be extracted from the above expression; the type property is used to define the behavior and presentation of the control, telling the front end how to render the control; the is Required property is used to identify whether the user must input a value for the control; the value List property is a pre-defined list of optional values for controls such as drop-down selection boxes, providing options for the user to choose, ensuring data specification; the place holder property is used to display a gray prompt text in the control before user input, guiding the user to input correctly; the extend Options property is a key-value pair set, used to store any non-standard or future extended configuration parameters; the interface Param Name property is the parameter name corresponding to the control value during data transmission between the front and back ends; the written property is used to store special input content such as handwritten signatures and handwriting, for processing non-text special inputs; the editType property further refines the interaction mode of the control, which is a supplement to the type.
[0053] III. Word to PDF Conversion
[0054] S3. The backend generates an empty parameter map according to the parsed control object list, combines the parameter map with the Word template file, and performs template rendering to replace all replaceable expressions in the Word template file with corresponding empty values or initial values, generates an uncompleted Word document with the same control object properties as the Word template file, and converts it into a PDF format, and outputs the PDF template file.
[0055] It should be noted that in step S3 of the embodiment of the present application, an empty parameter map (Map) is generated according to the parsed control object list. The key (Key) of the map is the name (name) or interface parameter name (interface Param Name) of each control, and the value (Value) is an empty string (") or an initial value generated according to the placeholder text (place holder), default value, etc. in the control attribute. Then the original Word template file is combined with the empty parameter map, and template rendering is performed. This process will replace all replaceable expressions in the Word template file with corresponding empty values or initial values. Since the parameter values are empty, the final generated is a Word document that retains all form field structures and formats, but the content is empty (i.e. the uncompleted Word document described above). The style, layout (such as font, font size, position) of the document are precisely controlled by the control object properties parsed and encapsulated before, ensuring visual consistency with the Word template file. Considering the powerful layout fixing characteristics of the PDF format, the new Word document is finally converted into a PDF format through a standard document conversion tool (such as LibreOffice, Microsoft Office API or a special library). As a result, this uncompleted Word document will be "locked" as an electronic form that cannot be easily edited and has a high degree of format fidelity, facilitating distribution, printing or online display for user filling. The final PDF template file perfectly reproduces the layout design of the Word template file, and all form fields in it are presented in blank form, waiting for user filling.
[0056] After the above process, the front end or user can obtain a blank form (PDF) with a specified format without installing Word. The backend obtains sufficient metadata (control object list) by first deeply parsing the Word template file, making subsequent batch generation of blank forms, user data backfilling, etc. become efficient and accurate. The final generated PDF template file retains the form fields (such as text fields, drop-down boxes), and the user experience is better than a static picture or a flat PDF that cannot directly input content.
[0057] Four, parse PDF to generate picture list
[0058] S4. The backend reads the byte stream of the PDF template file, creates a PDF document object to represent the PDF template file, and obtains the total number of pages of the PDF template file through the PDF document object, and then renders the PDF template file page by page and saves the images rendered by each page of the PDF template file in page order.
[0059] It should be noted that in step S5 of the present application, the following operations are performed on each page of the PDF template file to achieve rendering: the current page of the PDF template file is converted into a PNG format image at a preset rendering resolution.
[0060] In step S4 of the present embodiment, the backend first loads the PDF document, i.e. uses the Loader.loadPDF() method of the Apache PDFBox library to read the byte stream of the above-mentioned PDF template file, and creates a PDDocument object to represent the entire PDF template file. Then, the page information is obtained, i.e. the total number of pages of the PDF template file is obtained by calling the getNumberOfPages() method of the PDDocument object. Then, page-by-page rendering is performed, i.e. the following operations are performed on each page of the PDF template file: the renderImageWithDPI(pageIndex, resolution) method of the PDF Renderer is called to specify the resolution (default 90 DPI) to control the output quality, and each page of the PDF template file is rendered into a BufferedImage object, and the rendered BufferedImage object is encoded into a PNG format byte stream through the ImageIO.write() method. Finally, the file list is assembled in order, i.e. the PNG byte stream converted from each page is added to the file list in page order, and finally a complete image file list is assembled as the output.
[0061] It should be noted that the Loader.loadPDF(), getNumberOfPages(), renderImageWithDPI(pageIndex, resolution) and ImageIO.write() used in the present embodiment are all API functions from existing mature open source libraries. Among them, Loader.loadPDF() is used to load the PDF byte stream and create a document object; getNumberOfPages() is used to obtain the total number of pages of the PDF document; renderImageWithDPI(pageIndex, resolution) is used to convert a certain page of the PDF into a high-quality image; and ImageIO.write() is used to encode and write the image object in memory to the output stream, and the execution logic of each API function is not described in detail in the present application.
[0062] V. Coordinate reference point conversion
[0063] S5. The backend obtains the interactive form object from the PDF document object and traverses all the fields therein, filters out the fields of the text type as text input fields; creates a new control object for each text input field and sets the attributes, adds the newly created control object to a list, thereby forming a new control object list parsed from the PDF template file.
[0064] It should be noted that in step S5 of the present application, the specific process of creating a new control object for a text input field is as follows: obtaining all the display components corresponding to the text input field on a page of the PDF template file, extracting the position rectangular frame information from each display component, obtaining the height and width of the page, and creating a new control object for the text input field after coordinate system conversion of the PDF template file; wherein the position rectangular frame information includes the two-dimensional coordinates of the lower left corner of the display component, the width and the height.
[0065] Further, when the PDF template file is subjected to coordinate system conversion, the origin is modified from the lower left corner to the upper left corner, and when moving from the origin along the vertical direction downward, the vertical direction coordinate increases.
[0066] In step S5 of the present embodiment, the backend obtains the interactive form object (PD AcroForm) from the PDF document object, which contains the complete definition and data of all interactive form fields in the PDF template file. All the fields in the form are processed in a loop, and the text input fields (PD Text Field type) are filtered out and processed. For each text input field, it may correspond to one or more display components (Widget), and each display component contains the specific display information of the field on a page. For each display component, the backend extracts the precise position rectangular frame (PD Rectangle) information therefrom, including the X coordinate of the lower left corner (Lower Left X), the Y coordinate of the lower left corner (Lower Left Y), the width and the height. At the same time, the page height and the page width are obtained from the Media Box of the page, which are used for subsequent coordinate conversion. In the coordinate system conversion process, the PDF coordinate system (with the lower left corner as the origin, and the Y axis upward) is converted into the commonly used coordinate system of the application (with the upper left corner as the origin, and the Y axis downward). After the coordinate system conversion, the X coordinate of the upper left corner of the display component remains unchanged, and the converted Y coordinate of the upper left corner The specific calculation can be as follows:
[0067]
[0068] wherein, represents the height of the page; represents the Y coordinate of the lower left corner of the display component before conversion; represents the height of the display component itself.
[0069] Six, front-end display pictures and all text boxes
[0070] S6. The front end obtains the picture obtained in S4 and the new control object list generated in S5, takes the picture as the background, obtains the text box based on the new control object list, and suspends the text box on the picture to form a suspended WEB contract form and visually output.
[0071] In step S6 of the embodiment, according to the picture of each page generated by the PDF, the picture is taken as the background, and a user-inputtable text box is suspended and displayed at a position where information needs to be input, to form a suspended WEB contract form, as shown in Figure 3 The user can edit the field value and adjust the position, for example, the text box information can be further fine-tuned, such as the text box type, dictionary options, text box position, and the like. The user can also move the position and length, height according to the positioning position in a drag-and-drop manner, and can also allow the user to set variable Chinese, parameter name, type, prompt information, enumeration type, and check rule (including whether to fill in, length, numerical value size, and the like) settings. The mouse is clicked or the tab key is pressed to define the next input box position.
[0072] In the contract template, when there is a need to insert list information, such as multiple family members or houses, the “field type” is expanded to a div table element in the implementation of the present application, and the control object list is dynamically rendered and the form unit data is saved when the suspended WEB contract form is formed.
[0073] In summary, the core innovative features of the present application are:
[0074] 1) Direct suspended form input box definition is performed on the contract and agreement template, input field information can be configured without code and with light weight, a large amount of code development is avoided, and input range box drag-and-drop function, multiple type input boxes (including text, single / multiple options, drop-down box, table input, etc.), check rules, and the like are integrated.
[0075] 2) The present application unifies the traditional separated WEB contract form and the printed WORD template, and based on the same set of WORD templates, the WEB contract form can be used for generating PDF, and simultaneously used as a carrier for defining the suspended WEB contract form.
[0076] 3) Based on the definition and dynamic rendering of components, the present application realizes the interaction between components, such as the display and hiding of components being mutually exclusive, and data value associated check.
[0077] The component interaction implementation idea of the present application is as follows below taking component display and hiding as an example:
[0078] a. A binding target component id, event type (such as display and hide, data linkage, pop-up box, etc.) configuration item is added on the basis attribute of the source component;
[0079] b. Related public methods of display and hide and data linkage are encapsulated;
[0080] c. Various events are bound to each component as needed, and various events and binding ids are executed.
[0081] For example, when the value of component A is xxx, component B needs to be hidden, so the embodiment needs to listen to whether the value of component A is xxx, and if it is satisfied, the public method of display and hide is called to hide component B. The difficulty of the above process lies in how to dynamically identify that the value of A is xxx, and execute the public display and hide method. To solve this problem, two implementation methods are provided. The first is coding. In the component attribute panel, the user customizes the display and hide method, and the disadvantage is that the code needs to be written manually. The second is a code-free dynamic configuration method. In the component attribute panel, the expression that meets the condition is arranged through a visual interface, such as the value of the source component> (such as <, >=, <=,!=) 4 (which can be customized) and the like. At the same time, when the condition expression is met, the public method that meets the requirements is selected.
[0082] The present application realizes real-time listening to the value of the component through the set of the encapsulated components through the principle of two-way binding of vue, and dynamically creates a function through new Function to determine whether the condition expression is met, and when it is met, the public method that meets the requirements is selected.
[0083] The component interaction implementation idea of the present application is as follows below taking data value association verification as an example:
[0084] For example, when the value of the source component is equal to something, the target component is set to be mandatory.
[0085] a. Event binding (component attribute link). The source component is bound with an event, such as a change event, and the interaction mode is single click or double click.
[0086] b. Function writing. That is, the method body executed when the change event is triggered.
[0087] c. Dynamic component binding and execution of the bound component method are performed inside the source component.
[0088] It should be noted that the method for defining a contract form based on a WORD template without code in the above embodiment can be essentially executed by a computer program or module. Therefore, based on the same inventive concept, another preferred embodiment of the present application also provides a system for defining a contract form based on a WORD template without code, which corresponds to the method for defining a contract form based on a WORD template without code provided by the above embodiment, as shown in Figure 4 The system comprises:
[0089] a document acquisition module for acquiring an original Word template that needs to be generated into a form;
[0090] a form generation module for processing the original Word template according to the method for defining a contract form based on a WORD template without code described in the above embodiment to generate a floating WEB contract form;
[0091] a contract form switching module for establishing a page navigation index based on the page number attribute in the new control object list on the front end, and when a user page calling request is received, the front end automatically loads the picture of the corresponding page and the control object bound to the page according to the target page number, dynamically renders the floating WEB contract form of the page, and realizes seamless switching;
[0092] a data interaction module for associating the floating control generated by rendering the control object on the front end with the parameter mapping, and when a data update event is triggered, updating the parameter mapping in real time, and based on the interaction configuration of the control object, triggering the state change of other control objects associated with the control object;
[0093] a verification and storage module for reading the control object attribute on the front end when a data submission or page switching event is monitored, performing real-time verification: returning a visual prompt for the case that a required item is empty, the format is not matched, or the value is not in the preset list; after the verification is passed, synchronizing the actual reporting data in the parameter mapping to the runtime parameter list on the back end according to the key-value pair structure of the control name-actual reporting data, and updating the runtime parameter list by calling a staging interface;
[0094] a PDF file generation module for serializing the runtime parameter list into a JSON format file as an input parameter for Word to PDF conversion when the back end receives a user confirmation of reporting completion instruction, and calling a template rendering engine to match the key-value pair in the JSON format file with the replaceable expression in the original Word template, replace it with the actual reporting data to generate a filled Word document, and then convert the filled Word document into a PDF format through a document conversion tool to form a complete contract PDF file for user download or signature.
[0095] It should be noted that the contract form switching module of the present application can realize the calling of the contract page during the running period. Specifically, the front end establishes a page navigation index based on the page number attribute contained in the control object list in S5, and supports the user to trigger the loading and rendering of the contract page: when the user triggers the page calling by page switching, scrolling or directory jumping, the front end loads the picture of the corresponding page and the control object bound to the page according to the target page number, dynamically renders the floating form of the target page, and realizes the seamless switching of the multi-page contract form.
[0096] It should be noted that the data interaction module of the present application can realize the data filling and interaction during the running period. Specifically, the front end maps and associates the floating control and the parameters generated in S3 through bidirectional data binding. When the user inputs, selects or edits data in the floating control, the front end internally triggers a data update event to update the above-mentioned parameter mapping in real time; at the same time, based on the interaction configuration (such as display and hide association, data linkage rule) in the "extension and advanced attributes" of the control object, the state change of other control objects associated with the control object is triggered. For example, when the "contract type" is selected as "rental contract", the "rental period" control is displayed and the "loan amount" control is hidden.
[0097] It should be noted that the verification and storage module of the present application can realize the data verification and parameter list storage during the running period. When the user completes the filling or switches the page, a data submission or page switching event is triggered, the front end reads the "identification and logical attributes" (such as whether it is required, format rule, value list) of the control object, and performs real-time verification: for the cases that the required item is empty, the format is not matched (such as mobile phone number, date) or the value is not in the preset list, a visual prompt (such as red control border, pop-up prompt) is returned; after the verification is passed, the data in the parameter mapping is synchronized to the running period parameter list in the back end in the form of "control name-filling value" key-value pair structure, and the user can manually trigger the "temporary storage" operation to update the running period parameter list.
[0098] It should be noted that the PDF file generation module of the present application can generate a contract PDF file. When the user confirms that the filling is completed, the back end serializes the "running period parameter list" into a JSON format file as the input parameter for Word to PDF conversion; the back end calls the template rendering engine to match the key-value pairs in the JSON file with the replaceable expressions in the original Word template, replace them with the actual filling data to generate a filled Word document, and then convert it into a complete contract PDF file through a document conversion tool for the user to download or sign.
[0099] It can be understood that the method for defining a contract form based on a WORD template without code described in S1-S6 can be realized by a computer program. Therefore, based on the same inventive concept, another preferred embodiment of the present application also provides a computer program product corresponding to the method for defining a contract form based on a WORD template without code provided by the above-mentioned embodiments, which includes a computer program / instruction, and when the computer program / instruction is executed by a processor, the method for defining a contract form based on a WORD template without code described in the above-mentioned embodiments can be realized.
[0100] Similarly, based on the same inventive concept, another preferred embodiment of the present application also provides a computer electronic device corresponding to the method for defining a contract form based on a WORD template without code provided by the above-mentioned embodiments, as shown in Figure 5 The computer electronic device includes a memory and a processor.
[0101] The memory is used to store a computer program.
[0102] The processor is used to realize the method for defining a contract form based on a WORD template without code in the above-mentioned embodiments when the computer program is executed.
[0103] In addition, the logical instructions in the above-mentioned memory can be realized in the form of a software functional unit and sold or used as an independent product, which can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application or the part of the technical solutions that make essential contributions to the prior art or the part of the technical solutions can be embodied in the form of a software product, which is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the embodiments of the present application.
[0104] Therefore, based on the same inventive concept, another preferred embodiment of the present application also provides a computer readable storage medium corresponding to the method for defining a contract form based on a WORD template without code provided by the above-mentioned embodiments, and the storage medium stores a computer program, and when the computer program is executed by a processor, the method for defining a contract form based on a WORD template without code in the above-mentioned embodiments can be realized.
[0105] Specifically, in the computer readable storage medium of the above-mentioned three embodiments, the computer program stored in the computer readable storage medium is executed by a processor, and the steps of S1-S6 can be executed.
[0106] It can be understood that the storage medium can include a random access memory (RAM) and can also include a non-volatile memory (NVM), such as at least one disk memory. Meanwhile, the storage medium can also be a U disk, a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.
[0107] It can be understood that the processor can be a general processor, including a central processing unit (CPU), a network processor (NP), etc.; can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
[0108] In addition, it should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system described above can refer to the corresponding process in the foregoing method embodiments, which will not be described here. In the embodiments provided in the present application, the division of steps or modules in the system and method is only a logical functional division, and there can be another division mode in actual implementation, for example, a plurality of modules or steps can be combined or integrated together, or a module or step can be split.
[0109] The above-described embodiments are only a preferred scheme of the present application, and are not intended to limit the present application. Those skilled in the art can make various changes and modifications without departing from the spirit and scope of the present application. Therefore, any technical scheme obtained by equivalent replacement or equivalent transformation falls within the protection scope of the present application.
Claims
1. A method for defining contract forms without code based on WORD templates, characterized in that, Includes the following steps: S1. The backend obtains the Word template file input from the frontend through the interaction protocol. The Word template file has predefined replaceable expressions. The replaceable expressions are formed by embedding them in the text form fields of the Word contract document using a specific markup language. Each text form field corresponds to a form field to be filled in the Word contract document. S2. After the backend receives the Word template file and stores it in the specified directory, it parses and extracts all replaceable expressions as form parameters, creates a corresponding control object for each form parameter, forms a list of control objects, and encapsulates the properties of the control objects. S3. The backend generates an empty parameter mapping based on the parsed list of control objects, then combines the Word template file with the parameter mapping, performs template rendering, replaces all replaceable expressions in the Word template file with corresponding empty or initial values, generates an unfilled Word document with the same control object properties as the Word template file, converts it to PDF format, and outputs a PDF template file. S4. The backend reads the byte stream of the PDF template file, creates a PDF document object to represent the PDF template file, obtains the total number of pages of the PDF template file through the PDF document object, renders the PDF template file page by page, and saves the rendered images of each page of the PDF template file in page number order; S5. The backend obtains the interactive form object from the PDF document object and iterates through all the fields in it, filtering out the fields of type text and using them as text input fields; it creates a new control object for each text input field and sets its properties, then adds the newly created control objects to a list to form a new list of control objects parsed from the PDF template file; S6. The front-end retrieves the image obtained in S4 and the new list of control objects generated in S5. Using the image as the background, it generates a text box based on the new list of control objects and floats it on the image, forming a floating web contract form and displaying it visually.
2. The method for defining contract forms without code based on WORD templates as described in claim 1, characterized in that, In step S2, there are four categories of control object properties. The first category is style and appearance properties, including font, font size, text alignment, and format. The second category is layout and position properties, including X-axis offset, Y-axis offset, page number, width, height, page width, and page height. The third category is identification and logical properties, including name, control type, whether it is required, value list, and placeholder text. The fourth category is extended and advanced properties, including extended options, interface parameter names, handwritten content, and editing type.
3. The method for defining contract forms without code based on WORD templates as described in claim 1, characterized in that, In step S4, the following operation is performed on each page of the PDF template file to achieve rendering: the current page of the PDF template file is converted into a PNG image at a preset rendering resolution.
4. The method for defining contract forms without code based on WORD templates as described in claim 1, characterized in that, In step S5, the specific process of creating a new control object for a text input field is as follows: obtain all display components corresponding to the text input field on a page of the PDF template file, extract the position rectangle information of each display component, and obtain the height and width of the page. After performing coordinate system transformation on the PDF template file, create a new control object for the text input field. The position rectangle information includes the two-dimensional coordinates of the lower left corner of the display component, its width, and its height.
5. The method for defining contract forms without code based on WORD templates as described in claim 4, characterized in that, In step S5, when the PDF template file undergoes coordinate system transformation, the origin of the coordinate system is changed from the lower left corner to the upper left corner, and when it moves downwards in the vertical direction from the origin, the vertical coordinate increases.
6. The method for defining contract forms without code based on WORD templates as described in claim 1, characterized in that, In step S6, when the Word template file contains information that needs to be inserted into a list, the field type is expanded to a div table element. At the same time, when a floating web form is formed, the list of control objects is dynamically rendered and the form metadata is saved.
7. A system for defining contract forms based on WORD templates without code, characterized in that, include: The document acquisition module is used to obtain the original Word template that needs to be used for form generation. The form generation module is used to process the original Word template and generate a floating WEB contract form according to the method of defining a contract form based on a WORD template without code, as described in any one of claims 1 to 6. The contract form switching module is used to build a page navigation index on the front end based on the page number attribute in the new control object list. When a user page call request is received, the front end automatically loads the corresponding page image and the control object bound to the page according to the target page number, and dynamically renders the floating web contract form of the page to achieve seamless switching. The data interaction module is used to associate the floating control rendered on the front end with the parameter mapping through two-way data binding. When a data update event is triggered, the parameter mapping is updated in real time. At the same time, based on the interaction configuration of the control object, the state changes of other control objects associated with this control object are triggered. The validation and storage module is used to read the properties of control objects and perform real-time validation when data submission or page switching events are detected. For cases where required fields are empty, the format does not match, or the value is not in the preset list, a visual prompt is returned. After the verification is successful, the actual data entered in the parameter mapping will be synchronized to the runtime parameter list in the backend according to the key-value pair structure of control name-actual data, and the runtime parameter list will be updated by calling the temporary storage interface. The PDF file generation module is used to serialize the runtime parameter list into a JSON format file after the backend receives the user's confirmation of completion of the form. This JSON file is then used as input parameters for the Word to PDF conversion. The module calls the template rendering engine to match the key-value pairs in the JSON file with the replaceable expressions in the original Word template. After replacing them with the actual filled-in data, a fillable Word document is generated. Finally, the fillable Word document is converted into PDF format by a document conversion tool to form a complete contract PDF file for the user to download or sign.
8. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instruction is executed by the processor, it can implement the method for defining contract forms based on WORD templates without code, as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the method for defining contract forms based on WORD templates without code, as described in any one of claims 1 to 6.
10. A computer electronic device, characterized in that, Including memory and processor; The memory is used to store computer programs; The processor is configured to, when executing the computer program, implement the method for defining a contract form based on a WORD template without code, as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Online structure digital document template generation method and system
CN117113957A
Visual zero-code custom form generation system and method
CN118860370A