Template-based multi-format layout file generation method and system
Through the template-based multi-format layout file generation method, the problems of content overflow and inefficiency in large-scale data processing in the existing technology are solved, dynamic paging and adaptive layout are realized, multi-format parallel output and resource reuse are supported, and the complex form requirements of government/financial scenarios are adapted.
Patent Information
- Application Number
- CN202510732332.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-03
- Publication Date
- 2025-09-12
AI Technical Summary
Existing technologies cannot effectively handle content overflow or blank page problems when dealing with large-scale data, cannot support multi-format parallel output, and have difficulty adapting to complex table requirements in government/financial scenarios. Repeated creation of resources leads to inefficiency.
A template-based multi-format layout file generation method is adopted. Through the parsing of template objects and data objects, dynamic paging calculation and resource reuse strategy, cross-page header association and multi-format parallel output are achieved. The font resource pool is used to reduce repeated rendering and script-defined paging rules are supported.
It implements dynamic paging and adaptive layout, supports efficient output in multiple formats, reduces memory consumption, improves rendering efficiency of complex layouts, and adapts to complex table requirements.
Smart Images

Figure CN120633622A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of software management technology, and more specifically, to a template-based multi-format layout file generation method and system. Background Art
[0002] With the advancement of e-government, various departments are gradually implementing electronic transformation of various business operations. Template files are widely used in e-government business processes to display voucher information (electronic invoices, various vouchers) to users. Template files with digital signatures are also valid reimbursement vouchers.
[0003] The main formats of layout files are PDF and OFD. Depending on business needs, you may also need to provide corresponding images or HTML files.
[0004] The process of generating layout files requires processing dynamic data and forms. The current mainstream solutions are:
[0005] ① Template printing: Replicate handwritten and machine-printed vouchers using a dot-matrix printer on electronically printed documents. This solution features a completely fixed voucher template. By specifying the absolute positioning of dynamic data fields, text, images, and attachments can be directly appended to existing PDF / OFD files. Typical implementations include the Youhong OFD Suite.
[0006] ②HTML to PDF: This solution combines dynamic data and FreeMarker template data into HTML and then converts it to PDF. This solution facilitates handling of dynamic, variable-length table data, resolving issues like the inability to adjust table size, the inability to dynamically adapt to content length, and difficulty with pagination when using templates.
[0007] Report-based solutions: There are some products on the market, such as Fanruan Report and Ruilang Report, which can directly generate a table of a certain data set through configuration and export it to a specified format file.
[0008] Prior art, such as Chinese patent application publication number "CN117786784A," discloses a document template design method based on a graphical combination of document controls and data sources. The method includes: Step S1: Designing the document template framework by combining different controls, which can be nested; Step S2: Specifying the document content to be generated by the different controls based on the document control combination; Step S3: Parsing the document template and matching it to the actual target system data based on a top-down, outside-in approach. The system provided by this invention can graphically design document templates that meet user needs, and by matching system data from different sources, it supports the automated generation of design documents of various styles.
[0009] The problems with the above-mentioned existing technologies are that this method relies on a fixed control combination and cannot automatically page according to the amount of data. When processing large-scale data, content overflow or blank pages are prone to occur; it only supports the generation of a single document format, and does not involve the coordinate system conversion and multi-format parallel output of layout files such as PDF / OFD; the nested control style adopts the "proximity principle", which is easy to cause style overlap between levels, and does not mention the global style inheritance mechanism, affecting consistency; no resource reuse strategy (such as font cache and image) is designed, and repeated creation of the same font and image objects will lead to increased I / O overhead and expansion of the exported document volume, especially in the generation of multi-page documents, which is inefficient; the printing function code is too highly coupled with the business data, making it difficult to adapt to changes in requirements and difficult to meet the complex form requirements of government / financial scenarios; the usage scenarios are mainly oriented towards single-user clients and databases, but less attention is paid to background batch processing and program-oriented data object requirements. Summary of the Invention
[0010] In order to solve the above technical problems, the present invention proposes a template-based multi-format layout file generation method and system.
[0011] The technical solutions of the present invention are as follows:
[0012] The present invention proposes a method for generating a multi-format layout file based on a template, comprising the following steps:
[0013] Step S1, obtaining a template file and a data file, and converting the template file and the data file into a template object and a data object through a parser;
[0014] Step S2, processing the template object and the data object into a document object with fixed pages and fixed contents through the page selection calculator and the preset strategy class diagram;
[0015] Step S3: construct the document object page by page and output it in a specified format.
[0016] As a preferred embodiment, the template object includes:
[0017] Parse the template file into a tree structure containing layout pages, flow partitions, and drawing elements. Fill the flow partitions with data objects using dynamic data keys.
[0018] Grid modeling is performed for table layout, cells are defined as dynamic containers occupying continuous grid areas, and the number of grid rows is automatically expanded according to the number of data rows. When triggering a page span, the association between the header grid and the last row of the previous page is retained.
[0019] As a preferred embodiment, the page selection and paging calculator includes:
[0020] Dynamic paging strategy generation: By parsing the streaming partition layout in the template object, dynamically binding the row range of the data object and the paging trigger threshold, the paging position can be adaptively adjusted according to the data volume;
[0021] The strategy extension interface supports users to customize paging conditions and page element rearrangement rules by inheriting preset strategy base classes or embedding scripting languages. The scripting languages support cell merging and repeated rendering of table headers across pages.
[0022] As a preferred embodiment, the preset strategy class diagram includes:
[0023] Dynamic resource reuse strategy: load font files through the font resource pool when constructing the document object. The font resource pool uses a lazy loading mechanism to cache the parsed font objects and reuse the same font reference in multiple page renderings;
[0024] The cross-page table association strategy automatically inserts a cross-page identifier when the table breaks, and generates a continued table on the next page that shares the grid alignment parameters with the last row of the previous page.
[0025] As a preferred embodiment, the document object is constructed page by page and outputted in a specified format, wherein the outputting in the specified format includes:
[0026] A multi-format parallel output mechanism generates an intermediate data layer when constructing a document object, wherein the intermediate data layer contains page element descriptions that are independent of the format;
[0027] The intermediate data layer is converted into the target format through a format converter, wherein the PDF converter performs a coordinate system mirror flip algorithm to convert the internal coordinate system of the text elements and image elements into the PDF coordinate system.
[0028] As a preferred embodiment, the internal coordinate system of the text element and the image element is converted into the PDF coordinate system through a transformation matrix, specifically:
[0029] The transformation matrix that transforms the internal coordinate system into the PDF coordinate system is:
[0030]
[0031] Where: H page The height of the output page;
[0032] The transformation matrix of text elements into the PDF coordinate system is:
[0033]
[0034] Where: y T is the vertical coordinate of the text element in the internal coordinate system; b Tis the baseline scale factor; f T is the text size;
[0035] The transformation matrix of image elements into PDF coordinate system is:
[0036]
[0037] Where: y is the vertical coordinate of the image element in the internal coordinate system; H picture is the image height.
[0038] On the other hand, the present invention also provides a template-based multi-format layout file generation system, comprising:
[0039] Parsing module, obtains template files and data files, and converts them into template objects and data objects through the parser;
[0040] The paging module processes the template object and data object into a document object with fixed pages and fixed content through the page selection calculator and preset strategy class diagram;
[0041] The output module constructs the document object page by page and outputs it in the specified format.
[0042] As a preferred embodiment, in the parsing module, the template object includes:
[0043] Parse the template file into a tree structure containing layout pages, flow partitions, and drawing elements. Fill the flow partitions with data objects using dynamic data keys.
[0044] Grid modeling is performed for table layout, cells are defined as dynamic containers occupying continuous grid areas, and the number of grid rows is automatically expanded according to the number of data rows. When triggering a page span, the association between the header grid and the last row of the previous page is retained.
[0045] On the other hand, the present invention further provides an electronic device having a computer program stored thereon, wherein when the computer program is executed by a processor, the method for generating a multi-format layout file based on a template as described in any embodiment of the present invention is implemented.
[0046] On the other hand, the present invention also provides a computer-readable medium for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to implement a template-based multi-format layout file generation method as described in any embodiment of the present invention.
[0047] The present invention has the following beneficial effects:
[0048] Dynamic paging and adaptive layout: By binding streaming partitions to data thresholds, data volume-driven intelligent paging is achieved, and cross-page tables are supported to automatically retain table headers and associated parameters.
[0049] Efficient multi-format output: Based on the intermediate data layer and the coordinate system mirror flip algorithm (such as PDF transformation matrix), it is compatible with the parallel generation of multiple formats such as PDF, OFD, and images, reducing repeated rendering.
[0050] Resource reuse and performance optimization: The font resource pool uses a lazy loading mechanism to avoid repeated parsing and reduce memory consumption; grid table modeling improves the rendering efficiency of complex layouts.
[0051] Flexible scalability: supports script-defined paging rules and style rearrangement, and adapts to the complexities of multi-layer headers, asymmetric grouping and totals in Chinese-style reports. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments of the present application. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.
[0053] Figure 1 Schematic diagram of the process of the present invention;
[0054] Figure 2 Schematic diagram of the mechanism for reducing font resource read I / O and preventing repeated creation of font objects;
[0055] Figure 3 This is a schematic diagram of the positioning description system of anchor point + coordinate;
[0056] Figure 4 This is a schematic diagram of mesh division using a table model;
[0057] Figure 5 Schematic diagram of cell boundary lines across the grid;
[0058] Figure 6 It is a diagram showing the definition and application examples of the common table activity data fields;
[0059] Figure 7 This is a conversion diagram of the PDF coordinate system;
[0060] Figure 8 This is a flowchart of the PDF text processing process. DETAILED DESCRIPTION
[0061] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.
[0062] It should be understood that the step numbers used herein are only for convenience of description and are not intended to limit the order in which the steps are to be executed.
[0063] It should be understood that the terms used in the present specification are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the present specification and the appended claims, the singular forms "a", "an" and "the" are intended to include the plural forms unless the context clearly indicates otherwise.
[0064] The terms “include” and “comprising” indicate the presence of described features, integers, steps, operations, elements and / or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0065] The term "and / or" refers to and includes any and all possible combinations of one or more of the associated listed items.
[0066] Example 1:
[0067] In order to make the purpose, technical solutions and advantages of the present invention more clear, the following will be combined with the specific embodiments of the present application and refer to the attached Figure 1 , clearly and completely describe the technical solution of the present invention.
[0068] To solve the problems of the prior art, the present invention provides a method for generating a multi-format layout file based on a template, comprising the following steps:
[0069] Step S1, obtaining a template file and a data file, and converting the template file and the data file into a template object and a data object through a parser;
[0070] The template object includes:
[0071] Parse the template file into a tree structure containing layout pages, flow partitions, and drawing elements. Fill the flow partitions with data objects using dynamic data keys.
[0072] Grid modeling is performed for table layout, cells are defined as dynamic containers occupying continuous grid areas, and the number of grid rows is automatically expanded according to the number of data rows. When triggering a page span, the association between the header grid and the last row of the previous page is retained.
[0073] In this embodiment, the template component considers layout pages, flow partitions, and drawing elements as a "component". FldDrawElement is the base class of all drawing elements, and its subclasses are divided into the following categories according to their functions:
[0074] FldGeometry (geometric graphics base class): responsible for the definition and implementation of the basic graphics structure, which is further subdivided into multiple specific graphics subclasses, including but not limited to common geometric shapes such as rectangles and polygons.
[0075] Text related classes:
[0076] FldTextFragment: used for processing basic text fragments, including subclass extensions for different text formats (such as fonts and font sizes).
[0077] FldRichTextArea: Supports complex layout and interactive control of rich text content.
[0078] Image processing class:
[0079] FldPicture: As the base class of image elements, it covers the unified processing logic of common images and special graphics such as barcodes.
[0080] Container and layout classes:
[0081] FldContainer: Provides the nesting function of secondary containers and supports group management and hierarchical control of child elements.
[0082] FldBoxModel (box model): dedicated to the layout and rendering of tables and cells, including two specific implementations:
[0083] FldSimpleTable: Suitable for simple tables with fixed structures.
[0084] FldGenericTable: A general table model that supports dynamic row and column expansion.
[0085] Dynamic data fields:
[0086] FldTableDataV3: Implements dynamic binding between data and tables, supporting real-time updates and data-driven rendering mechanisms.
[0087] Streaming partition elements:
[0088] FldFlowParagraph: Adaptive arrangement of paragraph content for flow layout.
[0089] FldFlowTable: Implements dynamic table resizing and content adaptation in streaming partitions.
[0090] Step S2, processing the template object and the data object into a document object with fixed pages and fixed contents through the page selection calculator and the preset strategy class diagram;
[0091] The page selection and paging calculator includes:
[0092] Dynamic paging strategy generation: By parsing the streaming partition layout in the template object, dynamically binding the row range of the data object and the paging trigger threshold, the paging position can be adaptively adjusted according to the data volume;
[0093] The strategy extension interface supports users to customize paging conditions and page element rearrangement rules by inheriting preset strategy base classes or embedding scripting languages. The scripting languages support cell merging and repeated rendering of table headers across pages.
[0094] In this example, PageStrategyCalculator, as an abstract base class for paging strategies, defines a common methodology for page selection and paging, providing a scalable algorithm framework for different business scenarios. Its core functionality encompasses the unified encapsulation of template page layout calculations, data sharding rules, and statistical logic.
[0095] The specific strategies implemented by inheriting the base class include:
[0096] SingleFactorPageStrategyCalculator: This is the default paging strategy for single-activity data models (standard business scenarios), providing paging rules and basic statistical calculation logic for layout templates. It is further subdivided into multiple subclasses, covering differentiated handling for typical scenarios such as data grouping, cross-page line breaking, and header and footer inheritance.
[0097] FlowDocumentCalculator: Dedicated to the conversion of flow partitions to document object pages, realizing dynamic content page cutting and automatic assembly of cross-page elements (such as repeated rendering of table headers after table rows are split).
[0098] DirectOutput series classes: A lightweight implementation for template printing scenarios, supporting direct filling of data fields under fixed layouts. They are suitable for batch output needs such as bills and labels that do not require complex paging.
[0099] Provides multi-level extension mechanisms to meet special business needs:
[0100] Inheritance and extension: Developers can rewrite the paging algorithm or statistical logic by inheriting PageStrategyCalculator or any existing subclass (such as SingleFactorPageStrategyCalculator), compile it into an independent Java class, and reference it in the template.
[0101] Script embedding: supports writing Groovy scripts directly in templates, and dynamically injecting code to intervene in the paging process in real time (such as dynamically inserting page breaks based on runtime data).
[0102] Operation permissions: Custom calculators can perform the following operations on template pages / sections:
[0103] Dynamic assembly and cropping (such as merging and splitting cells in cross-page tables);
[0104] Freely splice document fragments generated by multiple data sources;
[0105] Insert dynamic elements other than those predefined in the template (such as adding warning icons based on calculation results).
[0106] The preset strategy class diagram includes:
[0107] Dynamic resource reuse strategy: load font files through the font resource pool when constructing the document object. The font resource pool uses a lazy loading mechanism to cache the parsed font objects and reuse the same font reference in multiple page renderings;
[0108] The cross-page table association strategy automatically inserts a cross-page identifier when the table breaks, and generates a continued table on the next page that shares the grid alignment parameters with the last row of the previous page.
[0109] In this embodiment, the preset strategy has been adapted to the typical data structure of Chinese-style reports, including:
[0110] Multi-layer header nesting and dynamic merging (such as the "parent-child" structure of financial statements);
[0111] Asymmetric grouping and totaling (left tree and right table layout);
[0112] Cross-page accumulation and recalculation of paging statistics (such as linking the subtotal of each page with the global total).
[0113] In this embodiment, Figure 2 The following figure shows a mechanism for reducing font resource I / O and preventing duplicate font object creation during document generation. When processing print operations, font objects cannot be reused across different documents; instead, the source header files (ttf, ttc) must be read and independent reference objects created. Repeated font object creation consumes significant resources. To minimize this waste, this program uses a two-step approach to process fonts:
[0114] 1. Create a font file resource pool and adopt a lazy loading mechanism. When a font is used for the first time, the font file is loaded only once and resides in the memory to avoid repeated reading.
[0115] 2. For each font object required by a document, when a certain font needs to be used, first check whether the same font object has been created. If so, reuse it.
[0116] In this embodiment, in the process of parsing the streaming partition layout in the template object, dynamically binding the row number range of the data object and the paging trigger threshold, so that the paging position is adaptively adjusted according to the data volume:
[0117] like Figure 3 As shown, under normal circumstances, the standard positioning of an element should be based on the upper left corner of the page. However, in some cases, the actual generated page size may not be consistent with the template page, and some elements need to follow the bottom or right edge of the page as the width and height of the page change. To solve this problem, we use the anchor point + coordinate positioning method to describe the position of an element on the page;
[0118] like Figure 4 As shown in the figure, it is a grid representation definition method for a general table. Different from the general table defined by rows and columns, the present invention regards the bottom layer of the table as a grid, and the cells are defined based on the grid. The boundary line is not defined by the cell itself, but is defined based on the grid. Figure 5 As shown in the figure, the triple (x, y, d) represents the grid column, grid row, and direction (0 is horizontal, 1 is vertical) of the boundary line. In this way, the granularity of the boundary line style can be divided into the finest.
[0119] like Figure 6 The following shows the definition of dynamic data areas in a general table model and their application examples. This is accomplished by specifying a continuous grid of cells that form a rectangular grid as a dynamic data area in the table and binding it to a business data key. The program automatically expands when processing such a dynamic data area. If the associated calculator supports paging, the table will be paginated according to the corresponding strategy. A table can contain multiple dynamic data areas that occupy disjoint rows, and the internal definition of the data areas is not strictly based on traditional rows and columns.
[0120] Step S3: construct the document object page by page and output it in a specified format.
[0121] The document object is constructed page by page and outputted in a specified format, wherein the outputting in the specified format includes:
[0122] A multi-format parallel output mechanism generates an intermediate data layer when constructing a document object, wherein the intermediate data layer contains page element descriptions that are independent of the format;
[0123] The intermediate data layer is converted into the target format through a format converter, wherein the PDF converter performs a coordinate system mirror flip algorithm to convert the internal coordinate system of the text elements and image elements into the PDF coordinate system.
[0124] The conversion of the internal coordinate system of the text element and the image element into the PDF coordinate system is performed through a transformation matrix, specifically:
[0125] The transformation matrix that transforms the internal coordinate system into the PDF coordinate system is:
[0126]
[0127] Where: H page The height of the output page;
[0128] The transformation matrix of text elements into the PDF coordinate system is:
[0129]
[0130] Where: y T is the vertical coordinate of the text element in the internal coordinate system; b T is the baseline scale factor; f T is the text size;
[0131] The transformation matrix of image elements into PDF coordinate system is:
[0132]
[0133] Where: y is the vertical coordinate of the image element in the internal coordinate system; H picture is the image height.
[0134] In this embodiment, Figure 7 and Figure 8 As shown, the special processing for handling PDF printing actions is described. The coordinate system of PDF files is different from that of national standard OFD files and images. The coordinate system of OFD and images is based on the upper left corner as the origin, with the y-axis pointing downward. The original coordinate system of PDF is based on the lower left corner of the page as the origin, with the y-axis pointing upward. And the original unit used is pt. It is difficult to unify the processing methods when processing elements in such a coordinate system with different directions and units, which increases maintenance costs. Therefore, the present invention performs a mirror inversion and movement on its internal original coordinate system, in which the internal text and images are mirrored and moved a second time. These actions are encapsulated into methods for external code processing, shielding the details of inconsistent coordinates and units.
[0135] Example 2:
[0136] Parsing module, obtains template files and data files, and converts them into template objects and data objects through the parser;
[0137] The paging module processes the template object and data object into a document object with fixed pages and fixed content through the page selection calculator and preset strategy class diagram;
[0138] The output module constructs the document object page by page and outputs it in the specified format.
[0139] Example 3:
[0140] This embodiment provides an electronic device having a computer program stored thereon. When the computer program is executed by a processor, the method for generating a multi-format layout file based on a template as described in any embodiment of the present invention is implemented.
[0141] Example 4:
[0142] This embodiment provides a computer-readable medium for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement a template-based multi-format layout file generation method as described in any embodiment of the present invention.
[0143] In the embodiments of the present application, "at least one" refers to one or more, and "more" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent the existence of A alone, the existence of A and B at the same time, and the existence of B alone. Among them, A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" and similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b and c can represent: a, b, c, a and b, a and c, b and c or a and b and c, where a, b, c can be single or multiple.
[0144] Those skilled in the art will appreciate that the various units and algorithm steps described in the embodiments disclosed herein can be implemented using a combination of electronic hardware, computer software, and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0145] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0146] In the several embodiments provided in this application, if any function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of this application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory; hereinafter referred to as: ROM), random access memory (Random Access Memory; hereinafter referred to as: RAM), disk or optical disk, and other media that can store program code.
[0147] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention's description and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A template-based multi-format layout file generation method, characterized in that: The following steps are involved: Step S1, obtaining a template file and a data file, and converting the template file and the data file into a template object and a data object through a parser; Step S2, processing the template object and the data object into a document object with fixed pages and fixed contents through the page selection calculator and the preset strategy class diagram; Step S3: construct the document object page by page and output it in a specified format.
2. The method for generating a multi-format layout file based on a template according to claim 1, characterized in that: The template object includes: Parse the template file into a tree structure containing layout pages, flow partitions, and drawing elements. Fill the flow partitions with data objects using dynamic data keys. Grid modeling is performed for table layout, cells are defined as dynamic containers occupying continuous grid areas, and the number of grid rows is automatically expanded according to the number of data rows. When triggering a page span, the association between the header grid and the last row of the previous page is retained.
3. The method for generating a multi-format layout file based on a template according to claim 1, characterized in that: The page selection and paging calculator includes: Dynamic paging strategy generation: By parsing the streaming partition layout in the template object, dynamically binding the row range of the data object and the paging trigger threshold, the paging position can be adaptively adjusted according to the data volume; The strategy extension interface supports users to customize paging conditions and page element rearrangement rules by inheriting preset strategy base classes or embedding scripting languages. The scripting languages support cell merging and repeated rendering of table headers across pages.
4. The method for generating a multi-format layout file based on a template according to claim 1, wherein: The preset strategy class diagram includes: Dynamic resource reuse strategy: load font files through the font resource pool when constructing the document object. The font resource pool uses a lazy loading mechanism to cache the parsed font objects and reuse the same font reference in multiple page renderings; The cross-page table association strategy automatically inserts a cross-page identifier when the table breaks, and generates a continued table on the next page that shares the grid alignment parameters with the last row of the previous page.
5. The method for generating a multi-format layout file based on a template according to claim 1, characterized in that: The document object is constructed page by page and outputted in a specified format, wherein the outputting in the specified format includes: A multi-format parallel output mechanism generates an intermediate data layer when constructing a document object, wherein the intermediate data layer contains page element descriptions that are independent of the format; The intermediate data layer is converted into the target format through a format converter, wherein the PDF converter performs a coordinate system mirror flip algorithm to convert the internal coordinate system of the text elements and image elements into the PDF coordinate system.
6. The method for generating a multi-format layout file based on a template according to claim 5, characterized in that: The conversion of the internal coordinate system of the text element and the image element into the PDF coordinate system is performed through a transformation matrix, specifically: The transformation matrix that transforms the internal coordinate system into the PDF coordinate system is: Where: H page The height of the output page; The transformation matrix of text elements into the PDF coordinate system is: Where: y T is the vertical coordinate of the text element in the internal coordinate system; b T is the baseline scale factor; f T is the text size; The transformation matrix of image elements into PDF coordinate system is: Where: y is the vertical coordinate of the image element in the internal coordinate system; H picture is the image height.
7. A template-based multi-format layout file generation system, characterized in that: include: Parsing module, obtains template files and data files, and converts them into template objects and data objects through the parser; The paging module processes the template object and data object into a document object with fixed pages and fixed content through the page selection calculator and preset strategy class diagram; The output module constructs the document object page by page and outputs it in the specified format.
8. The template-based multi-format layout file generation system according to claim 7, characterized in that: In the parsing module, the template object includes: Parse the template file into a tree structure containing layout pages, flow partitions, and drawing elements. Fill the flow partitions with data objects using dynamic data keys. Grid modeling is performed for table layout, cells are defined as dynamic containers occupying continuous grid areas, and the number of grid rows is automatically expanded according to the number of data rows. When triggering a page span, the association between the header grid and the last row of the previous page is retained.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the method for generating a multi-format layout file based on a template as described in any one of claims 1 to 6 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method for generating a multi-format layout file based on a template as claimed in any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Document template design method and system for combining document control and data source based on graphical mode
CN117786784A
Cited By
Multi-format label generation method and system and storage medium
CN121636606A