Methods, apparatus, devices, and storage media for batch output of HTML web pages to PDF.
By creating template files for HTML web forms and utilizing database mapping matching technology, PDF files can be automatically generated in batches, solving the problem of cumbersome operations in existing technologies and improving work efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- WUXI BOTON IOT TECH CO LTD
- Filing Date
- 2022-11-23
- Publication Date
- 2026-04-21
AI Technical Summary
In existing technologies, the process of generating PDF files in batches is cumbersome, requiring operators to frequently and manually set web form information for each person, resulting in low work efficiency.
By creating matching template files for specific HTML web page forms, determining the HTML style layout, dynamic areas, and static elements, and storing batch data in a database, PDF files are automatically generated using mapping matching, avoiding manual data entry.
It enables automatic batch generation of PDF files without the need for manual data entry, significantly improving work efficiency.
Smart Images

Figure CN115935908B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, device, and storage medium for batch outputting HTML web pages to PDF. Background Technology
[0002] Converting HTML web pages to PDF allows for the quick saving and transmission of web page information in text format. This is particularly useful for company OA systems or office approval systems, where operators can export web page form information as PDFs for storage and approval procedures.
[0003] In related technologies, printing PDFs typically involves using the browser's built-in PDF printing function or an installed PDF generation plugin to extract elements from the webpage's HTML and then creating interface images and text on a canvas. As described in application 201910739182.7, a Canvas is generated on an HTML webpage using JavaScript code, and then converted into a target PDF attachment for saving. This conversion is entirely based on the webpage content. However, in certain webpages and situations, such as when auditing or forms require batch generation of PDF files based on personnel information, operators must frequently set up webpage forms for each person and then print the PDFs. Therefore, the process is extremely cumbersome and inefficient. Summary of the Invention
[0004] This application provides a method, apparatus, device, and storage medium for batch outputting HTML web pages to PDF. It solves the problem of low efficiency in batch generating PDF files.
[0005] On one hand, this application provides a method for batch outputting PDFs from HTML web page forms, the method comprising:
[0006] Select the target template file corresponding to the webpage form in the HTML webpage, and determine the HTML style layout, dynamic area, static elements, and static element layout of the HTML webpage based on the target template file; wherein the HTML style is used to determine the layout of the PDF file, the static elements are fixed elements in the batch output PDF files, and the dynamic area is the filling area of dynamic elements in different output PDFs;
[0007] In response to the batch operation instruction of the web page form, the batch data information in the database corresponding to the target template file is read and mapped and matched with the dynamic area and corresponding fill character field in the target template file to determine the target dynamic data of the dynamic area;
[0008] Create a PDF virtual canvas and batch generate PDF files based on the HTML style layout, the static elements, the static element layout, and the target dynamic data.
[0009] On the other hand, this application provides an apparatus for batch outputting HTML web page forms to PDF, the apparatus comprising:
[0010] The first determining module is used to select the target template file corresponding to the web page form in the HTML web page, and determine the HTML style layout, dynamic area, static elements and static element layout of the HTML web page according to the target template file; wherein the HTML style is used to determine the layout of the PDF file, the static elements are fixed elements in the batch output PDF files, and the dynamic area is the filling area of dynamic elements in different output PDFs;
[0011] The second determining module is used to respond to the batch operation instructions of the web page form, read the batch data information in the database corresponding to the target template file, and perform mapping and matching with the dynamic area and the corresponding fill character segment in the target template file to determine the target dynamic data of the dynamic area.
[0012] The batch generation module is used to create a PDF virtual canvas and generate PDF files in batches based on the HTML style layout, the static elements, the static element layout, and the target dynamic data.
[0013] In another aspect, this application provides a computer device including a processor and a memory, wherein the memory stores at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, the at least one program, the code set, or instruction set is loaded and executed by the processor to implement the method for batch outputting HTML web page forms to PDF as described above.
[0014] In another aspect, this application provides a computer-readable storage medium storing at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement the method for batch outputting HTML web page forms to PDF as described above.
[0015] The beneficial effects of the technical solution provided in this application include at least the following: This solution creates a matching template file for a specific HTML webpage form, and sets the HTML style layout, dynamic areas, static elements, and static element layout of the HTML webpage according to the specific style of the webpage form. Simultaneously, it stores the batch data information requiring batch operations in a database. During batch operations, the HTML style layout, dynamic areas, static elements, and static element layout of the webpage form are determined based on the selected target template file. The batch data information is stored in the database, and the target dynamic data for the dynamic areas is determined by reading and mapping it to the dynamic areas and corresponding fill character segments in the target template file. Finally, a virtual canvas is created, and multiple PDF files are generated in batches according to the specified format and layout to complete the batch operation. In other words, this process automatically reads and determines the data to be filled and replaced without manual input, and automatically generates PDF files in batches, significantly improving work efficiency. Attached Figure Description
[0016] Figure 1 This is a flowchart of a method for batch outputting HTML web page forms to PDF according to an embodiment of this application;
[0017] Figure 2 This is a flowchart of a method for batch outputting HTML web page forms to PDF according to another embodiment of this application;
[0018] Figure 3 This is a structural block diagram of the HTML web page form batch output PDF device provided in the embodiments of this application. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0020] In this article, "multiple" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0021] Because browsers' built-in "Save As PDF" function does not provide an SDK for developers to perform secondary development, and its functionality is relatively limited—it can only generate a single PDF file from a single set of data on the opened webpage—users cannot dynamically load and export form data based on form query conditions within the same webpage layout. Furthermore, since only one PDF file can be generated at a time, the efficiency is extremely low when users need to export PDFs in batches.
[0022] like Figure 1 The diagram shown is a flowchart of a method for batch outputting PDFs from HTML web page forms according to an embodiment of this application, including the following steps:
[0023] Step 101: Select the target template file corresponding to the webpage form in the HTML webpage, and determine the HTML style layout, dynamic areas, static elements, and static element layout of the HTML webpage based on the target template file.
[0024] HTML web pages are web page information displayed in a browser interface. This application mainly targets batch operations, therefore the operation objects are limited to web page forms displayed on HTML web pages. Web page forms include, but are not limited to, company OA systems, approval systems, and workflow systems, involving web page content that frequently operates on web page forms to generate unique form information. For example, a company's accounting system generates PDF files for employee or partner billing information, name information, and amount information. Normally, the operator must manually fill in each item and generate a PDF file one by one.
[0025] In this solution, a unique template file will be created for each specific webpage form; for example, a matching template file will be designed for a company's accounting system. When performing batch operations, the corresponding target template file will be selected in advance. The target template file specifies the HTML style layout, dynamic areas, static elements, and static element layout of the HTML webpage. After selection, the computer will first extract all element information from the HTML webpage and directly identify the HTML style layout, dynamic areas, static elements, and static element layout based on the target template file.
[0026] HTML styles determine the layout of a PDF file, ensuring the overall style and layout of the generated PDF file matches the webpage style. Static elements are elements that remain unchanged in batch-output PDF files, while dynamic areas are the filled areas for dynamic elements in different PDFs, i.e., the areas that the operator needs to modify or fill for each PDF file individually.
[0027] Step 102: In response to the batch operation command of the web page form, read the batch data information in the database corresponding to the target template file, and perform mapping and matching with the dynamic area and corresponding fill character field in the target template file to determine the target dynamic data of the dynamic area.
[0028] Batch operations between web forms and target template files are implemented based on a database. The database stores the batch data information required for batch operations; that is, when generating multiple PDF files, the indexed database is used for replacement and population. After the computer device reads the batch data information, it maps and matches it with the dynamic areas and corresponding fill character fields in the target template file to determine the target dynamic data in the dynamic areas. For example, in a company's accounting system, the location of the invoice party's name information is a dynamic area, which usually needs to be manually entered by the operator. This step involves mapping and matching specific batch data information with this dynamic area and its corresponding fill character fields to determine the target dynamic data in the dynamic area, which is the invoice party's information name.
[0029] Step 103: Create a PDF virtual canvas and batch generate PDF files based on HTML style layout, static elements, static element layout, and target dynamic data.
[0030] A PDF file may contain multiple target dynamic data. The computer device needs to determine all the target dynamic data, create a PDF virtual canvas after determination, and then batch generate PDF files based on HTML style layout, static elements, static element layout, and target dynamic data. During the PDF generation process, the computer device will generate multiple corresponding PDF files according to the specific content of the instructions, such as 50 invoices or leave approval forms.
[0031] In summary, this application creates a matching template file for a specific HTML webpage form and sets the HTML style layout, dynamic areas, static elements, and static element layout of the HTML webpage according to the specific style of the webpage form. Simultaneously, it stores batch data information requiring batch processing in a database. During batch processing, the HTML style layout, dynamic areas, static elements, and static element layout of the webpage form are determined based on the selected target template file. Batch data information is stored in the database, and the target dynamic data for the dynamic areas is determined by reading and mapping it against the dynamic areas and corresponding fill character fields in the target template file. Finally, a virtual canvas is created, and multiple PDF files are generated in batches according to the specified format and layout, completing the batch processing. In other words, this process automatically reads and determines the data to be filled and replaced, and automatically generates PDF files in batches, significantly improving work efficiency without manual input.
[0032] Figure 2 This is a flowchart of a method for batch outputting PDF from an HTML web page form according to another embodiment of this application, including the following steps:
[0033] Step 201: Select the target template file corresponding to the web page form in the HTML web page, and determine the HTML style layout, dynamic areas, static elements, and static element layout of the HTML web page based on the target template file.
[0034] Step 202: In response to receiving a batch operation instruction for the web page form, read and load the batch data information in the database, and match all batch data information belonging to the same PDF file with the dynamic area in the target template file respectively.
[0035] For database information, it should include all batch data information capable of generating the target dynamic data. Optionally, when storing in the database, all batch data information belonging to the same PDF file can be grouped or related links can be established to facilitate the classification and display of information when the computer retrieves and loads it. As shown in Table 1, this is the batch information stored in the company's accounting system database. This information is grouped and related by worker name or personnel name affiliation.
[0036] Table 1. Batch information stored in the company's accounting system database
[0037]
[0038] Once the computer reads this data, it loads it onto the webpage interface and displays it as form information that represents the PDF name, making it easy for the user to select options. For example, a "Name" option might be displayed on the side of the webpage; the user selects options from this column, and the number of selected options corresponds to the number of PDF copies generated. Each "Name" row is interconnected with other form information; selecting "Name" automatically confirms the selection of other form information. For webpage forms, invoicing information and other necessary data must be filled in; this information is dynamic, and the areas that should be filled in are dynamic areas that must match the dynamic areas in the target template file.
[0039] Step 203: When there is a batch of data information that matches the padding character field of the dynamic region position, establish a mapping relationship between the batch of data information and the target dynamic region.
[0040] The matching process is based on the filler character fields in the dynamic area of the template. Different positions can be represented by specific characters; for example, the filler character field "%name123%" for "name / name" in the target template matches the "name / name" column in the database. When the batch data "Zhang San" matches "name / name", the matching relationship is confirmed, and a mapping relationship is established between the batch data information and the target dynamic area. Similarly, after determining this mapping relationship, other data in Table 1 can be directly mapped without repeating the steps of searching and establishing matching relationships.
[0041] Step 204: Based on the HTML style layout, convert and / or sum the field names and field values of all batch data information belonging to the same PDF file and mapped to the same target dynamic area to obtain the target dynamic data of the dynamic area.
[0042] The format of text, font size, color, and image size displayed in web forms is determined by the system, while the database only stores raw data. Therefore, when generating dynamic data, it is necessary to perform transformation and / or summation operations on the field names and values of batch data. Transformations include font format, size, and color conversion; image size cropping and color conversion; case conversion; and Chinese / English conversion. Summing field names and values is an operation for specific data options, such as the amount, time, or options involving calculating differences or totals between multiple related batch data. These transformations and summations need to be predefined in the template, and the content obtained after the transformation is the target dynamic data for the corresponding dynamic area.
[0043] After identifying the target dynamic data, the next step is to replace the original fill field; otherwise, the fill field from the web form will be directly displayed on the canvas during composition. However, for some special dynamic area options, the corresponding batch data information does not exist in the database. For example, the gender field for "xxx company" in Table 1 does not exist. Since the template specifies the fill field, the default fill field will be displayed in the PDF file if no operation is performed on this data. Therefore, when the fill field of a dynamic area does not match any batch data information in the database, the fill field of that dynamic area needs to be replaced with an empty value, and the empty value should be identified as the target dynamic data for the current dynamic area. The empty value can be a space or displayed with " / ", indicating that the option information does not exist.
[0044] Step 205: Create a PDF virtual canvas based on batch operation instructions, and composite the static elements in the web page form onto the PDF virtual canvas according to the HTML style layout and static element layout to draw static text, shapes, icons and lines.
[0045] Batch operation instructions are generated based on form query conditions, which are the options selected by the operator. These options include the number of PDF files to be generated in batches and the username of the user to whom the dynamic data belongs. All batch data information under the same username in the database is interconnected. Form query conditions include at least the user's name, identity information, and form information matching the user. These query conditions are interconnected; that is, all information from the same person or belonging to the same data type is grouped together.
[0046] For each PDF file to be generated, the computer needs to create a PDF virtual canvas. Static elements related to form information extracted from each HTML webpage are composited onto the PDF virtual canvas according to the HTML style layout and static element layout. This process includes compositing the line layout, chart layout, text layout, chart attributes, and font attributes in the webpage form onto the canvas according to preset rules, and drawing static text, shapes, icons, and lines.
[0047] As an example, for the PDF file saved in the company's leave approval process, the operator only needs to select the "Leave Form Template." The computer system directly extracts the interface elements and layout from the web form, treating the table, name, department, and time as dynamic areas, and the corresponding content to be filled in are dynamic elements (specific fillable character fields in the template). After the operator selects the personnel's names, the system will directly generate PDF leave forms for all personnel who need to apply for leave, so manual filling is no longer required.
[0048] 206. The synthesized target dynamic data is placed into the corresponding dynamic region position according to the mapping relationship to generate a PDF file.
[0049] In summary, this application addresses the issue of HTML webpage form content requiring batch processing by creating one-to-one template files. The template files are configured with HTML style layouts, dynamic areas, static elements, and static element layouts according to the form style specifications. This allows for the targeted categorization of extracted HTML interface elements, determining the PDF file style layout and static elements. For dynamic elements in dynamic areas, special filler characters are used in the template to match the batch data information, facilitating the establishment of a mapping relationship between the batch data information and the target dynamic areas. For target dynamic data in specific dynamic areas within the PDF file, the field names and values of the batch data are converted and / or summed based on font and image attribute settings to obtain the target dynamic data corresponding to the dynamic areas specified in the webpage form. Since the batch processing can directly select the quantity and associated batch information data in each PDF, the operator only needs to select the required form information to batch create a PDF virtual canvas. The captured HTML style layouts, static elements, static element layouts, and target dynamic data are then combined to generate PDF files in batches, eliminating the need for individual filling and saving, significantly improving the efficiency of exporting PDF files.
[0050] Figure 3 This is a structural block diagram of the HTML webpage form batch output PDF device provided in the embodiments of this application, including:
[0051] The first determining module 301 is used to select the target template file corresponding to the web page form in the HTML web page, and determine the HTML style layout, dynamic area, static elements and static element layout of the HTML web page according to the target template file; wherein the HTML style is used to determine the layout of the PDF file, the static elements are fixed elements in the batch output PDF files, and the dynamic area is the filling area of dynamic elements in different output PDFs.
[0052] The second determining module 302 is used to respond to the batch operation instruction of the web page form, read the batch data information in the database corresponding to the target template file, and perform mapping and matching with the dynamic area and corresponding fill character segment in the target template file to determine the target dynamic data of the dynamic area.
[0053] The batch generation module 303 is used to create a PDF virtual canvas and generate PDF files in batches based on the HTML style layout, the static elements, the static element layout, and the target dynamic data.
[0054] This application also provides a computer device, which includes a processor and a memory; the memory stores at least one instruction, which is executed by the processor to implement the method for batch outputting HTML web page forms to PDF provided in the above-described method embodiments.
[0055] This application also provides a computer-readable storage medium storing at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by the processor to implement the method for batch outputting HTML web page forms to PDF as described above.
[0056] This application also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method for batch outputting HTML web page forms to PDF as described in any of the above aspects.
[0057] The preferred embodiments of the present invention have been described above. It should be understood that the present invention is not limited to the specific embodiments described above. The devices and structures not described in detail should be understood as being implemented in a conventional manner in the art. Any person skilled in the art can make many possible changes and modifications, or equivalent changes to equivalent embodiments without departing from the technical solution of the present invention. This does not affect the substantive content of the present invention. Therefore, any simple modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention shall still fall within the protection scope of the technical solution of the present invention.
Claims
1. A method for batch outputting PDFs from HTML web page forms, characterized in that, The method includes: Select the target template file corresponding to the webpage form in the HTML webpage, and determine the HTML style layout, dynamic area, static elements, and static element layout of the HTML webpage based on the target template file; wherein the HTML style is used to determine the layout of the PDF file, the static elements are fixed elements in the batch output PDF files, and the dynamic area is the filling area of dynamic elements in different output PDFs; In response to the batch operation instruction of the web page form, the batch data information in the database corresponding to the target template file is read and mapped and matched with the dynamic area and corresponding fill character field in the target template file to determine the target dynamic data of the dynamic area; specifically, in response to receiving the batch operation instruction for the web page form, the batch data information in the database is read and loaded, and all batch data information belonging to the same PDF file is matched with the dynamic area in the target template file respectively. When there is a match between the batch data information and the padding character segment at the location of the dynamic region, a mapping relationship is established between the batch data information and the target dynamic region; Based on the HTML style layout, the field names and field values of all batch data information belonging to the same PDF file and having a mapping relationship with the same target dynamic area are transformed and / or summed to obtain the target dynamic data of the dynamic area. Create a PDF virtual canvas and batch generate PDF files based on the HTML style layout, the static elements, the static element layout, and the target dynamic data.
2. The method according to claim 1, characterized in that, Different web page forms correspond to different template files, and the template files are configured with mapping relationships between the dynamic areas, static elements, static element layouts, and HTML style layouts in the web page forms; The HTML style layout includes the line layout, chart layout, text layout, chart attributes, and font attributes in the web page form.
3. The method according to claim 2, characterized in that, After obtaining the target dynamic data of the dynamic region, the method further includes: Replace the padding character segment of the dynamic region with the target dynamic data; When the padding character field of the dynamic region does not match all the batch data information in the database, the padding character field of the dynamic region is replaced with an empty value, and the empty value is determined as the target dynamic data of the current dynamic region.
4. The method according to claim 3, characterized in that, The process of creating a PDF virtual canvas and batch generating PDF files based on the HTML style layout, the static elements, the static element layout, and the target dynamic data includes: Based on the batch operation instructions, the PDF virtual canvas is created, and the static elements in the web page form are combined on the PDF virtual canvas according to the HTML style layout and the static element layout to draw static text, shapes, icons and lines. The synthesized target dynamic data is placed into the corresponding dynamic region position according to the mapping relationship to generate a PDF file.
5. The method according to any one of claims 1-4, characterized in that, Batch operation instructions are generated based on form query conditions, including the number of PDF files to be generated in batches and the user name to which the dynamic data belongs, and all batch data information under the same user name in the database are interconnected.
6. The method according to claim 5, characterized in that, The form query conditions include at least the user's name, identity information, and form information that matches the user.
7. An apparatus for batch outputting HTML web page forms to PDF, characterized in that, The apparatus is used to implement the method for batch outputting HTML web page forms to PDF as described in any one of claims 1-6, and the apparatus includes: The first determining module is used to select the target template file corresponding to the web page form in the HTML web page, and determine the HTML style layout, dynamic area, static elements and static element layout of the HTML web page according to the target template file; wherein the HTML style is used to determine the layout of the PDF file, the static elements are fixed elements in the batch output PDF files, and the dynamic area is the filling area of dynamic elements in different output PDFs; The second determining module is used to respond to the batch operation instruction of the web page form, read the batch data information in the database corresponding to the target template file, and perform mapping and matching with the dynamic area and corresponding fill character segment in the target template file to determine the target dynamic data of the dynamic area; specifically, in response to receiving the batch operation instruction for the web page form, it reads and loads the batch data information in the database, and matches all the batch data information belonging to the same PDF file with the dynamic area in the target template file respectively; When there is a match between the batch data information and the padding character segment at the location of the dynamic region, a mapping relationship is established between the batch data information and the target dynamic region; Based on the HTML style layout, the field names and field values of all batch data information belonging to the same PDF file and having a mapping relationship with the same target dynamic area are transformed and / or summed to obtain the target dynamic data of the dynamic area. The batch generation module is used to create a PDF virtual canvas and generate PDF files in batches based on the HTML style layout, the static elements, the static element layout, and the target dynamic data.
8. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one instruction, at least one program, a code set, or an instruction set, the at least one instruction, the at least one program, the code set, or the instruction set being loaded and executed by the processor to implement the method for batch outputting HTML web page forms to PDF as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The readable storage medium stores at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement the method for batch outputting HTML web page forms to PDF as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Method and device for converting webpage data into PDF attachments
CN110674437A
Report printing method and system based on HTML (Hyper Text Markup Language) template
CN104571977A
Method and system for visually generating webpage template
CN106096049A