Method for converting HTML document into PDF file and storing PDF file into MinIO storage service
By using the FreeMarker template engine and iText library to convert HTML documents into PDF files, and combining MinIO storage services for efficient storage and distribution, the problems of complexity and high resource consumption of HTML to PDF conversion in the prior art are solved, and efficient and reliable document processing and distribution are achieved.
Patent Information
- Application Number
- CN202411602759.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-11
- Publication Date
- 2025-02-28
AI Technical Summary
In the prior art, when converting HTML documents into PDF files and depositing them into MinIO storage services, there are problems of complexity and high resource consumption, resulting in low document processing efficiency.
The FreeMarker template engine and iText library are used to convert HTML documents into PDF files, and the generated PDF files are uploaded and managed through the MinIO object storage system, and finally sent to the user via email. This solution uses temporary file management intermediate results, saves memory and storage resources, and efficiently stores it through MinIO's API.
It greatly improves document processing efficiency, solves the problems of complexity and high resource consumption, and realizes efficient document conversion, storage and distribution, meeting users' needs for document format conversion, storage management and convenient access.
Smart Images

Figure CN119538869A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information processing technology, and in particular to a method for converting an HTML document into a PDF file and storing it in a MinIO storage service. Background Art
[0002] iText is a common solution that includes the use of open source tools and libraries, which can effectively render and save HTML content as PDF files, meeting users' needs for document format conversion. However, these solutions face some problems in actual applications, such as complex installation and configuration, storage and management issues, and electronic document distribution.
[0003] Therefore, the prior art has defects and needs to be improved. Summary of the invention
[0004] The technical problem to be solved by the present invention is: to provide a method for converting HTML documents into PDF files and storing them in MinIO storage service, which solves the complexity and high resource consumption problems in the prior art and greatly improves the document processing efficiency.
[0005] The technical solution of the present invention is as follows: Provide a method for converting an HTML document into a PDF file and storing it in a MinIO storage service, comprising the following steps:
[0006] S1: The user performs a business operation, triggering the corresponding transaction;
[0007] S2: After completing the corresponding business operation, the user provides the corresponding HTML template type and corresponding parameters; the parameters are filled into the HTML template through the FreeMarker template engine to generate a complete HTML document containing user data.
[0008] S3: Convert the generated HTML document to a PDF file through the iText library; this process includes loading HTML content, setting fonts, processing page layout, and rendering PDF. Use the FreeMarker template engine and the iText library to convert HTML to PDF; the FreeMarker template engine is used to process HTML templates, and iText is used to generate PDF files.
[0009] S4: Configure the MinIO object storage system, including the bucket name, access key, and access key secret; then upload the generated PDF file to the MinIO storage.
[0010] S5: Generate the access URL of the PDF file in MinIO and perform necessary URL processing and conversion.
[0011] S6: Generate a corresponding PDF file using the generated URL and send it to the user as an attachment via email; create and send an email using the email sending service to ensure that the user can receive the PDF file.
[0012] The FreeMarker template engine uses a parameter replacement mechanism, allowing users to dynamically replace fields in HTML templates according to actual needs to process HTML templates.
[0013] In the process of converting the generated HTML document into a PDF file, a temporary file is used to manage the intermediate results generated in the conversion process, which effectively saves memory and storage resources. The intermediate results include: the page after loading HTML content, the page after setting fonts, the page after processing page layout, and the page for rendering PDF.
[0014] After the generated HTML document is converted to a PDF file, the temporary files are cleaned up.
[0015] In step S2, it also includes: the user provides a required PDF file name.
[0016] In step S4, the file is converted into a byte array during the upload process and stored in the specified bucket through MinIO's API.
[0017] By adopting the above scheme, the present invention provides a method for converting HTML documents into PDF files and storing them in MinIO storage service, and finally sending the generated PDF files to users as email attachments. The present invention solves the problems of complexity, high resource consumption and inefficient file distribution in the prior art. Cloud storage service (MinIO) provides a high-availability and scalable file storage solution. As a high-performance, distributed object storage system, MinIO is particularly suitable for the storage and management of large-scale files. It supports the standard S3 API and can be seamlessly integrated with existing cloud storage services, providing users with a flexible and reliable storage solution. The present invention combines HTML to PDF conversion technology with MinIO storage service to provide an efficient and reliable document conversion and storage solution. The present invention realizes the conversion of HTML documents into PDF files and stores them in MinIO, which are then sent to users as email attachments. In this way, not only the utilization rate of computing resources is improved, but also the needs of users for document format conversion, storage management and convenient access are met, thereby solving the business needs in e-commerce and online services. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 The figure is a flow chart of the method of the present invention. DETAILED DESCRIPTION
[0019] The present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments.
[0020] See also Figure 1 The present invention provides a method for converting HTML documents into PDF files and storing them in MinIO storage service, which solves the complexity and high resource consumption problems in the prior art and greatly improves the document processing efficiency.
[0021] The technical solution of the present invention is as follows: Provide a method for converting an HTML document into a PDF file and storing it in a MinIO storage service, comprising the following steps:
[0022] S1: A user (such as a client user) performs a business operation, triggering a corresponding transaction;
[0023] S2: After completing the corresponding business operation, the user provides the corresponding HTML template type and corresponding parameters; the parameters are filled into the HTML template through the FreeMarker template engine to generate a complete HTML document containing user data. In this step, it also includes: the user provides the required PDF file name.
[0024] S3: Convert the generated HTML document to a PDF file through the iText library; this process includes loading HTML content, setting fonts, processing page layout, and rendering PDF. Use the FreeMarker template engine and the iText library to convert HTML to PDF; the FreeMarker template engine is used to process HTML templates, and iText is used to generate PDF files.
[0025] S4: Configure the MinIO object storage system, including the bucket name, access key, and access key secret; then upload the generated PDF file to the MinIO storage. In this step, the file is converted into a byte array during the upload process and stored in the specified bucket through the MinIO API.
[0026] S5: Generate the access URL of the PDF file in MinIO and perform necessary URL processing and conversion.
[0027] S6: Generate a corresponding PDF file using the generated URL and send it to the user as an attachment via email; create and send an email using the email sending service to ensure that the user can receive the PDF file.
[0028] The FreeMarker template engine uses a parameter replacement mechanism, allowing users to dynamically replace fields in HTML templates according to actual needs to process HTML templates.
[0029] In the process of converting the generated HTML document into a PDF file, a temporary file is used to manage the intermediate results generated in the conversion process, which effectively saves the memory and storage resources. The intermediate results include: a page after loading HTML content, a page after setting fonts, a page after processing page layout, and a page for rendering PDF. After the generated HTML document is converted into a PDF file, the temporary file is cleaned up. The conversion process of the present invention performs performance optimization, and a temporary file is used to manage the intermediate results generated in the conversion process, which effectively saves the memory and storage resources. At the same time, through the reasonable management of resources, such as the timely cleaning of temporary files, the stability and reliability of the system are ensured.
[0030] The present invention provides a flexible parameter replacement mechanism, allowing users to dynamically replace fields in the template according to actual needs. This flexibility enables users to generate PDF documents customized according to specific business needs, greatly improving the customization and applicability of the documents.
[0031] Compared with the traditional method, the present invention adopts the iText library to realize the efficient conversion function from HTML to PDF. Compared with the traditional browser-based conversion method, the present invention can perform the conversion in the background without relying on the browser environment, thereby improving the conversion efficiency and stability.
[0032] The present invention is compatible with multiple fonts, and users can specify the required fonts as needed, which can ensure that the generated PDF document has good font display effects in different language environments.
[0033] In summary, the present invention provides a method for converting HTML documents into PDF files and storing them in MinIO storage service, and finally sending the generated PDF files to users as email attachments. The present invention solves the problems of complexity, high resource consumption and inefficient file distribution in the prior art. Cloud storage service (MinIO) provides a highly available and scalable file storage solution. As a high-performance, distributed object storage system, MinIO is particularly suitable for the storage and management of large-scale files. It supports the standard S3 API and can be seamlessly integrated with existing cloud storage services, providing users with a flexible and reliable storage solution. The present invention combines HTML to PDF conversion technology with MinIO storage service to provide an efficient and reliable document conversion and storage solution. The present invention realizes the conversion of HTML documents into PDF files and stores them in MinIO, which are then sent to users as email attachments. In this way, not only the utilization rate of computing resources is improved, but also the needs of users for document format conversion, storage management and convenient access are met, thereby solving the business needs in e-commerce and online services.
[0034] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for converting an HTML document into a PDF file and storing it in a MinIO storage service, characterized in that: The following steps are involved: S1: The user performs a business operation, triggering the corresponding transaction; S2: After completing the corresponding business operation, the user provides the corresponding HTML template type and corresponding parameters; the parameters are filled into the HTML template through the FreeMarker template engine to generate a complete HTML document containing user data; S3: Convert the generated HTML document into a PDF file through the iText library; this process includes loading HTML content, setting fonts, processing page layout, and rendering PDF; S4: Configure the MinIO object storage system, including the bucket name and access key; then upload the generated PDF file to the MinIO storage; S5: Generate the access URL of the PDF file in MinIO and perform necessary URL processing and conversion; S6: Generate a corresponding PDF file using the generated URL and send it to the user via email as an attachment; Create and send an email using a mailing service to ensure that the user receives the PDF file.
2. According to claim 1, a method for converting an HTML document into a PDF file and storing it in a MinIO storage service is characterized in that: The FreeMarker template engine uses a parameter replacement mechanism, allowing users to dynamically replace fields in HTML templates according to actual needs to process HTML templates.
3. According to claim 1, a method for converting an HTML document into a PDF file and storing it in a MinIO storage service is characterized in that: In the process of converting the generated HTML document into a PDF file, a temporary file is used to manage the intermediate results generated in the conversion process, and the intermediate results include: the page after loading the HTML content, the page after setting the font, the page after processing the page layout, and the page for rendering the PDF.
4. A method for converting an HTML document into a PDF file and storing it in a MinIO storage service according to claim 3, characterized in that: After the generated HTML document is converted to a PDF file, the temporary files are cleaned up.
5. According to claim 1, a method for converting an HTML document into a PDF file and storing it in a MinIO storage service is characterized in that: In step S2, it also includes: the user provides a required PDF file name.
6. A method for converting an HTML document into a PDF file and storing it in a MinIO storage service according to claim 1, characterized in that: In step S4, the file is converted into a byte array during the upload process and stored in the specified bucket through MinIO's API.
7. The method of converting an HTML document into a PDF file and storing it in a MinIO storage service according to claim 1, characterized in that: Configuring the MinIO object storage system also includes: a key to access the key.