Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for generating a template file, which can reduce errors and operation steps of a customized template, improve format universality and compatibility, reduce labor cost and customization cost, reduce maintenance cost, and solve the problem of difficult program upgrade and maintenance.
To achieve the above object, according to an aspect of an embodiment of the present invention, a method for generating a template file is provided.
A template file generation method comprises the following steps: determining a template element and a setting of the template element based on a user operation; obtaining a self-defined template based on the template elements and the setting of the template elements; and generating a template file according to the self-defined template.
Optionally, the template element is determined from the elements to be selected based on an element dragging operation of a user.
Optionally, determining the setting of the template element comprises: and determining the position setting of the template element according to the dragging position of the template element.
Optionally, the determining the position setting of the template element according to the dragging position of the template element includes: recording a start position, an end position, and size information of the template element being dragged, and determining a position setting of the template element based on the recorded start position, end position, and size information.
Optionally, the custom template is displayed in a page of a user; after determining the position setting of the template element, the method includes: and saving the position setting of the template element, and displaying the position setting of the template element in a specific display area of the page.
Optionally, the page is a browser page of the user.
Optionally, the user operates the user's operations sent as browsers of one or more users.
Optionally, the determining the setting of the template element includes: and for a first template element of the template elements to be input with the content, determining the content setting of the first template element based on the content input operation of a user.
Optionally, the determining the setting of the template element includes: and for a second template element of the template elements with the pattern to be set, acquiring the pattern corresponding to the second template element from the pattern to be selected according to the pattern configuration operation of the user so as to determine the pattern setting of the second template element.
Optionally, the pattern comprises one or more of size, color, alignment.
Optionally, the type of the template element includes one or more types of text, image, and table.
Optionally, the template file is in a JSON format; after the template file is generated according to the custom template, the method comprises the following steps: and converting the template file in the JSON format into a file in a specific format which can be used for browser preview and/or printing.
Optionally, the template element is set by a Canvas element of a hypertext markup language, and the setting includes one or more of a position setting, a content setting, and a style setting.
Optionally, the template file is a credential file.
According to another aspect of the embodiments of the present invention, an apparatus for generating a template file is provided.
An apparatus for generating a template file, comprising: a template element determination module for determining a template element and a setting of the template element based on a user operation; the custom template generating module is used for obtaining a custom template based on the template elements and the setting of the template elements; and the template file generation module is used for generating a template file according to the self-defined template.
Optionally, the template element determination module is further configured to: and determining the template element from the elements to be selected based on element dragging operation of a user.
Optionally, the template element determination module is further configured to: and determining the position setting of the template element according to the dragging position of the template element.
Optionally, the template element determination module is further configured to: recording a start position, an end position, and size information of the template element being dragged, and determining a position setting of the template element based on the recorded start position, end position, and size information.
Optionally, the custom template is displayed in a page of a user; the template element determination module is further configured to: and saving the position setting of the template element, and displaying the position setting of the template element in a specific display area of the page.
Optionally, the page is a browser page of the user.
Optionally, the user operates the user's operations sent as browsers of one or more users.
Optionally, the template element determination module is further configured to: and for a first template element of the template elements to be input with the content, determining the content setting of the first template element based on the content input operation of a user.
Optionally, the template element determination module is further configured to: and for a second template element of the template elements with the pattern to be set, acquiring the pattern corresponding to the second template element from the pattern to be selected according to the pattern configuration operation of the user so as to determine the pattern setting of the second template element.
Optionally, the pattern comprises one or more of size, color, alignment.
According to yet another aspect of an embodiment of the present invention, an electronic device is provided.
An electronic device, comprising: one or more processors; a memory for storing one or more programs, which when executed by the one or more processors, cause the one or more processors to implement the method for generating a template file provided by an embodiment of the present invention.
According to yet another aspect of an embodiment of the present invention, a computer-readable medium is provided.
A computer-readable medium, on which a computer program is stored, the computer program, when being executed by a processor, implementing a method for generating a template file according to an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: determining a template element and a setting of the template element based on a user operation; obtaining a self-defined template based on the template elements and the setting of the template elements; and generating a template file according to the self-defined template. The method can reduce errors and operation steps of the customized template, improve format universality and compatibility, reduce labor cost and customization cost, reduce maintenance cost and solve the problem of difficult program upgrading and maintenance.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Fig. 1 is a main flow diagram of a method for generating a template file according to an embodiment of the present invention.
As shown in fig. 1, the method for generating a template file according to an embodiment of the present invention mainly includes the following steps S101 to S103.
Step S101: the template element and the setting of the template element are determined based on a user operation.
The user actions may be user actions sent by one or more of the user's browsers. The user's operation is generated by the user terminal in response to the user instruction, and includes, but is not limited to, an element drag operation, a content input operation, a style configuration operation, and the like. The device such as the server executing the template file generation method according to the embodiment of the present invention may receive the user operation sent by the browser.
And determining the template elements from the elements to be selected based on element dragging operation of a user. The elements dragged by the user at the terminal are the template elements, and the terminal generates element dragging operation of the user according to a dragging instruction of the user.
Determining the settings of the template elements may include: and determining the position setting of the template element according to the dragging position of the template element.
In one embodiment, determining the position setting of the template element according to the dragging position of the template element may include: recording the start position, end position and size information of the dragged template element, and determining the position setting of the template element based on the recorded start position, end position and size information.
In another embodiment, determining the position setting of the template element according to the dragging position of the template element may include: the start position and the end position of the dragging of the template element are recorded, and the position setting of the template element is determined based on the recorded start position and end position.
After determining the position setting of the template element, the method may include: the position setting of the template element is saved, and the position setting of the template element is displayed in a specific display area of the page.
The page may be a browser page of the user's terminal.
Determining the settings of the template elements may include: for a first template element of contents to be input among the template elements, a content setting of the first template element is determined based on a content input operation by a user.
Determining the settings of the template elements may include: and for a second template element of the pattern to be set in the template elements, acquiring the pattern corresponding to the second template element from the pattern to be selected according to the pattern configuration operation of the user so as to determine the pattern setting of the second template element.
The first template element of the content to be input and the second template element of the style to be set are determined according to corresponding selection instructions sent by a browser of a user. The selection instruction is for selecting the first template element or the second template element accordingly.
The pattern may comprise one or more of size, color, alignment.
The type of the template element may include one or more types of text, image, and table.
The template elements are set through a Canvas element of the hypertext markup language, and the setting can comprise one or more of position setting, content setting and style setting.
The Canvas element of the hypertext markup language is specifically a Canvas element in the HTML5 technology.
Step S102: and obtaining the self-defined template based on the template elements and the setting of the template elements.
The custom template is displayed in a user's page, such as a browser page of the user terminal.
Step S103: and generating a template file according to the self-defined template.
And generating a template file according to the custom template, specifically, saving the custom template as a JSON format file to obtain the template file.
After generating the template file according to the custom template, the method may include: the template file in the JSON format is converted into a file in a specific format, such as a file in a PDF format, which can be used for preview and/or printing by a browser.
The template file may be a credential file.
The following describes the template file generation method according to an embodiment of the present invention in detail, taking the credential template customization based on the Web (global wide area network) as an example.
The embodiment of the invention provides a graphical, universal, flexible and low-cost voucher template customizing method based on a B/S (Browser/Server) framework (Browser/Server structure), supports a user to access through a Browser, realizes an operation customizing function based on the Browser mode, can perform visual customized operation in the template customizing process, is not limited by a platform environment, supports cross-platform (independent of an operating system and a hardware environment), reduces the voucher template customizing and maintaining cost, generates a customized template file into a file in a JSON (JavaScript Notation) format, wherein the JSON format is a light data exchange format and can be used as a format for data exchange between a Server and an application, and the JSON format is a data expression mode and a data exchange standard on the Web, the method has the characteristics of no relation with platforms and manufacturers in use and universality. The embodiment of the invention optimizes and unifies the voucher generation format, so that the voucher can be previewed and generated conveniently and quickly, the operation efficiency and the user experience are improved, the data safety is ensured, the voucher template customization cost is reduced, and a solution is provided for the informatization and the standardization of the voucher template.
The embodiment of the invention is based on the canvas characteristic in the HTML5 technology, and can realize the acquisition of the position coordinates of the dynamic elements in the image on the Web and the customization of the template style by the method and the attribute provided in the Javascript technology. HTML5 is a specification of core language HTML (hypertext markup language) in Web, HTML format is converted into recognizable information through technical processing in a browser so as to facilitate Web browsing for a user, JavaScript is a computer program development language and is widely used in a scripting language on the browser, methods and attributes provided in JavaScript technology can include methods of drawing lines, tables and texts and obtaining mouse position coordinates, for example, attributes of canvas include colors, thicknesses and the like, and methods include drawing lines, drawing frames and the like.
FIG. 2 is a flow diagram of generating a credential template file according to one embodiment of the invention.
As shown in fig. 2, a method for generating a template file is implemented by template element definition and template design in a template customization module, and a credential template file (i.e., JSON file) in JSON format is generated; filling dynamic template elements through transaction data transmission service in the template generation module, and generating a certificate through the certificate generation service; the voucher template file and the voucher can be converted into a PDF file for previewing and printing to obtain a PDF voucher and a paper voucher.
The template elements are contents to be displayed on the template and can be divided into fixed template elements and dynamic template elements, the contents of the template can be texts, images or forms, wherein the fixed template elements are text elements with fixed template contents, the contents cannot be changed in subsequent operations, and the dynamic template elements refer to template elements with template contents needing to be filled in the subsequent operations. For example, data such as customer information, money amount, remarks, etc. are generated in the process of banking transaction and processing, and when the voucher template is generated, the dynamic data is filled in dynamic text elements (i.e. dynamic template elements whose contents are texts), and fixed data such as voucher titles, operation instructions, etc. are filled in fixed text elements (i.e. fixed template elements whose contents are texts).
In template design, the position setting, content setting, and style setting of template elements are determined. Specifically, on the page, the user pulls the position of the required template element and the position of the mobile template element by means of mouse dragging, and the server of the embodiment of the present invention obtains the position information of the element by obtaining the start position, the end position and the size information (for example, length, width, height, etc.) of the mouse during dragging. Fig. 3 is a schematic diagram of setting a border template element according to an embodiment of the present invention, and as shown in fig. 3, position information (position setting) is also displayed on the right side of the page in real time during the mouse dragging process, and the position information of the border element is represented by the position of the upper left corner of the border, and the width and height (i.e., size information) of the border. Fig. 4 is a schematic diagram of setting a text template element according to an embodiment of the present invention, and as shown in fig. 4, position information of a fixed text element and a dynamic text element may be represented by recording a start position when a mouse is dragged and size information of a text content.
Fig. 5 is a schematic diagram of setting a style of a template element according to an embodiment of the present invention.
As shown in fig. 5, in the embodiment of the present invention, style setting of template elements may be performed, where the style may include size, color, alignment, and the like, for example, font size, font color, text alignment mode, and the like of a text, and the style and the layout basis are used in later template generation.
Fig. 6 is a schematic diagram of setting an image template element according to an embodiment of the present invention.
As shown in fig. 6, the image template element according to the embodiment of the present invention may be set by importing an image material, and setting the position of the image template element and the length and width (i.e., size information) of the image template element by dragging with a mouse, where the image material may be a two-dimensional code picture, an enterprise trademark picture, or the like.
After the template elements are set, the user-defined template is obtained, the user-defined template is stored as a template file in a JSON format through the embodiment of the invention so as to store the user-defined template elements and information such as position setting, style setting and the like of the template elements, and the template file in the JSON format can be converted into a file in a PDF format so as to facilitate the preview and printing of a user on a browser.
In one embodiment, a template file in JSON format is as follows:
fig. 7 is a schematic diagram of main blocks of a template file generation apparatus according to an embodiment of the present invention.
As shown in fig. 5, a templatefile generating apparatus 700 according to an embodiment of the present invention mainly includes: a templateelement determining module 701, a customtemplate generating module 702 and a templatefile generating module 703.
A templateelement determining module 701, configured to determine a template element and a setting of the template element based on a user operation.
And a customtemplate generating module 702, configured to obtain a custom template based on the template elements and the settings of the template elements.
The templatefile generating module 703 is configured to generate a template file according to the custom template.
In one embodiment, the template element determination module is specifically configured to: and determining the template elements from the elements to be selected based on element dragging operation of a user.
In one embodiment, the template element determination module is specifically configured to: and determining the position setting of the template element according to the dragging position of the template element.
In one embodiment, the template element determination module is specifically configured to: recording the start position, end position and size information of the dragged template element, and determining the position setting of the template element based on the recorded start position, end position and size information.
In one embodiment, the custom template is displayed in the user's page; the template element determination module is specifically configured to: the position setting of the template element is saved, and the position setting of the template element is displayed in a specific display area of the page.
In one embodiment, the page may be a browser page of the user.
In one embodiment, the user actions may be user actions sent by one or more of the user's browsers.
In one embodiment, the template element determination module is specifically configured to: for a first template element of contents to be input among the template elements, a content setting of the first template element is determined based on a content input operation by a user.
In one embodiment, the template element determination module is specifically configured to: and for a second template element of the pattern to be set in the template elements, acquiring the pattern corresponding to the second template element from the pattern to be selected according to the pattern configuration operation of the user so as to determine the pattern setting of the second template element.
In one embodiment, the pattern may include one or more of size, color, alignment.
In one embodiment, the types of template elements may include one or more types of text, images, tables.
In one embodiment, the template file is in a JSON format; the template previewing module can be further included for: and converting the template file in the JSON format into a file in a specific format which can be used for previewing and/or printing by a browser.
In one embodiment, template elements are set by a Canvas element of the hypertext markup language, and the settings may include one or more of location settings, content settings, and style settings.
In one embodiment, the template file may be a credential file.
In addition, the detailed implementation of the template file generation device in the embodiment of the present invention has been described in detail in the above template file generation method, and therefore, the repeated description is not repeated here.
Fig. 8 shows anexemplary system architecture 800 of a template file generation method or a template file generation apparatus to which an embodiment of the present invention can be applied.
As shown in fig. 8, thesystem architecture 800 may includeterminal devices 801, 802, 803, anetwork 804, and aserver 805. Thenetwork 804 serves to provide a medium for communication links between theterminal devices 801, 802, 803 and theserver 805.Network 804 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use theterminal devices 801, 802, 803 to interact with aserver 805 over anetwork 804 to receive or send messages or the like. Theterminal devices 801, 802, 803 may have installed thereon various communication client applications, such as shopping-like applications, web browser applications, search-like applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only).
Theterminal devices 801, 802, 803 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
Theserver 805 may be a server that provides various services, such as a back-office management server (for example only) that supports shopping-like websites browsed by users using theterminal devices 801, 802, 803. The backend management server may analyze and perform other processing on the received data such as the product information query request, and feed back a processing result (for example, target push information, product information — just an example) to the terminal device.
It should be noted that the method for generating the template file provided by the embodiment of the present invention is generally executed by theserver 805, and accordingly, the apparatus for generating the template file is generally disposed in theserver 805.
It should be understood that the number of terminal devices, networks, and servers in fig. 8 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 9, a block diagram of acomputer system 900 suitable for use with a terminal device or server implementing an embodiment of the invention is shown. The terminal device or the server shown in fig. 9 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 9, thecomputer system 900 includes a Central Processing Unit (CPU)901 that can perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)902 or a program loaded from astorage section 908 into a Random Access Memory (RAM) 903. In theRAM 903, various programs and data necessary for the operation of thesystem 900 are also stored. TheCPU 901,ROM 902, andRAM 903 are connected to each other via abus 904. An input/output (I/O)interface 905 is also connected tobus 904.
The following components are connected to the I/O interface 905: aninput portion 906 including a keyboard, a mouse, and the like; anoutput section 907 including components such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; astorage portion 908 including a hard disk and the like; and acommunication section 909 including a network interface card such as a LAN card, a modem, or the like. Thecommunication section 909 performs communication processing via a network such as the internet. Thedrive 910 is also connected to the I/O interface 905 as necessary. Aremovable medium 911 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on thedrive 910 as necessary, so that a computer program read out therefrom is mounted into thestorage section 908 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through thecommunication section 909, and/or installed from theremovable medium 911. The above-described functions defined in the system of the present invention are executed when the computer program is executed by a Central Processing Unit (CPU) 901.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor comprises a template element determining module, a self-defined template generating module and a template file generating module. Here, the names of these modules do not constitute a limitation of the module itself in some cases, and for example, the template element determination module may also be described as "a module for determining the template element and the setting of the template element based on a user operation".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: determining a template element and a setting of the template element based on a user operation; obtaining a self-defined template based on the template elements and the setting of the template elements; and generating a template file according to the self-defined template.
According to the technical scheme of the embodiment of the invention, the template elements and the setting of the template elements are determined based on user operation; obtaining a self-defined template based on the template elements and the setting of the template elements; and generating a template file according to the self-defined template. The method can reduce errors and operation steps of the customized template, improve format universality and compatibility, reduce labor cost and customization cost, reduce maintenance cost and solve the problem of difficult program upgrading and maintenance.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.