Document streaming layout rendering method and device based on configuration driving

By using a configuration-driven document flow layout rendering method, the high maintenance cost and low iteration efficiency caused by the coupling of code and style in existing technologies are solved. This enables high-precision typesetting and low-barrier maintenance of PDF documents, and is suitable for document generation in fields such as finance and healthcare.

CN121809401APending Publication Date: 2026-04-07SILIDI SEMICON (SUZHOU) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-30
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

Existing PDF generation solutions suffer from deep coupling between code and style, high maintenance costs, uncontrolled cross-page layout, and high operating threshold for non-technical personnel, failing to meet the needs of high-precision typesetting and rapid iteration.

Method used

A configuration-driven document flow layout rendering method is adopted. By generating a key-value pair structure configuration file, using a pattern validator to validate the configuration file, parsing it into a document object model, dynamically populating it with business data, and using a flow layout algorithm and strategy pattern to build a component rendering factory to generate PDF documents.

Benefits of technology

It achieves decoupling of layout and style, supports hot updates, reduces maintenance costs, improves typesetting accuracy and scalability, and allows non-technical personnel to configure complex reports, meeting the needs of efficient iteration and accurate typesetting in fields such as finance and healthcare.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121809401A_ABST
    Figure CN121809401A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of document typesetting, in particular to a document streaming layout rendering method and device based on configuration driving. The method comprises the following steps: defining a four-dimensional generation key value pair configuration file according to document attributes, page layout, component geometry and styles, and verifying the key value pair configuration file; converting the configuration node into a document object model through an analysis engine; receiving external business data, positioning a dynamic slot position in the model, filling data, and generating a to-be-rendered instance tree; constructing a component rendering factory based on the strategy mode, and dynamically instantiating a corresponding rendering strategy class; and calculating the geometric position of the component by adopting a streaming typesetting algorithm, paging according to requirements, generating and executing a drawing instruction, and outputting a PDF (Portable Document Format) document. Aiming at the problems of code and style coupling, out-of-control typesetting and high operation threshold in the existing scheme, layout and code decoupling, high-precision typesetting and low-threshold configuration are realized, the method is adaptive to the requirements of multiple scenes such as finance and medical treatment, and the expansibility is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of document layout technology, and in particular to a configuration-driven document flow layout rendering method and apparatus. Background Technology

[0002] In fields such as finance, healthcare, and corporate offices, PDF documents are widely used in scenarios such as reports, test reports, and compliance documents due to their standardized and tamper-proof characteristics. These documents have stringent requirements for typesetting accuracy, dynamic data adaptability, and ease of maintenance. Currently, mainstream PDF generation solutions mainly include three categories: hard-coded development, HTML-to-PDF tools, and traditional reporting engines. Among them, the hard-coded mode suffers from drawbacks such as deep coupling between code and style, high maintenance costs, and poor reusability; HTML-to-PDF tools are prone to problems such as uncontrolled cross-page typesetting and style adaptation deviations, making it difficult to meet high-precision typesetting requirements; and traditional reporting engines have shortcomings such as cumbersome deployment architecture, weak scalability, and high operating threshold for non-technical personnel.

[0003] In addition, all three solutions lack a unified document description protocol and configuration verification mechanism, and have insufficient dynamic data adaptation capabilities. They cannot meet the core demands of business scenarios for efficient iteration of document generation, accurate typesetting, and low-threshold maintenance. There is an urgent need to propose a new technical solution to solve the above problems. Summary of the Invention

[0004] The purpose of this invention is to provide a configuration-driven document flow layout rendering method and apparatus to solve the technical problems in the prior art, such as low maintenance and iteration efficiency caused by deep coupling between code and style, insufficient high-precision typesetting adaptation capability, and high operating threshold for non-technical personnel.

[0005] The technical solution of this invention is: a configuration-driven document flow layout rendering method, comprising: A configuration file for generating a key-value pair structure of a PDF document is generated based on four dimensions: document attributes, page layout, component geometry, and style definition. The configuration file is then validated using a pattern validator. A parsing engine is used to traverse the configuration file and convert static configuration nodes into a document object model; Receive external business data, traverse the document object model and locate the dynamic slots, query the target business data corresponding to the key name of the dynamic slot from the external business data, populate the target business data into its data injection target item, and generate an instance tree to be rendered; the data injection target item includes text, table cell and icon data sources; A component rendering factory is built based on the strategy pattern, and a mapping table between component type identifiers and rendering strategy classes is constructed. The rendering engine dynamically instantiates the corresponding rendering strategy class according to the component type identifier of the rendering node. Employing a streaming layout algorithm, the rendering engine traverses the tree of instances to be rendered from top to bottom, calculates the geometric position of the components based on the constraint coordinates of the parent container, triggers pagination as needed, binds the geometric position and style attributes to the component instance, generates a standardized drawing instruction set, executes the drawing instructions through the underlying drawing interface, and generates a PDF document.

[0006] Preferably, the method for generating a configuration file with a key-value pair structure for a PDF document based on four dimensions—document attributes, page layout, component geometry, and style definition—is to generate a YAML-formatted configuration file according to a hierarchical document description protocol.

[0007] Preferably, the step of validating the configuration file using a pattern validator includes: Read the configuration file and check if the root node contains the necessary keywords. If any are missing, throw an exception. For each configuration item, check whether the type of its value conforms to the preset standard; if an exception is found, throw an exception. Iterate through the configuration items and check whether all resources referenced by the component nodes are defined. If the referenced resources are not defined, throw an exception.

[0008] Preferably, the step of traversing the document object model and locating the dynamic slots therein includes: The rendering engine loads the component tree and recursively accesses the properties of each component object; the component tree is a document object model, which is a tree structure with parent-child nesting relationships; For nodes whose attribute values ​​are strings, use regular expressions to extract the placeholders. Extract the corresponding key name from the capture group of the regular expression matching result to complete the location of the dynamic slot; the key name is the index identifier of the target business data query.

[0009] Preferably, the step of filling the target business data into its corresponding data injection target item includes: Establish a context data dictionary and load the received external business data into the context data dictionary; For the key names of the identified dynamic slots, parse the key names of the nested structure and recursively query the corresponding target business data in the context data dictionary; If the target business data is found, the placeholder in the dynamic slot will be replaced with the target business data to complete the data injection target item filling. If the business data with the corresponding key name is not found in the context data dictionary, it will be processed according to the preset strategy to avoid rendering errors.

[0010] Preferably, the preset strategy is a missing data fault tolerance handling rule predefined in the configuration file, including at least one of the following: Do not replace the placeholders for dynamic slots; retain the original placeholders. Replace the placeholder for the dynamic slot with an empty string; Replace the placeholder with the preset prompt text in the configuration file; the prompt text is "No data available" or "Data not configured".

[0011] Preferably, the method of calculating the geometric position of the component based on the parent container constraint coordinates and triggering pagination processing on demand includes: The rendering engine uses a Cartesian coordinate system for positioning, with the bottom left corner of the page as the origin, the x-axis extending horizontally to the right, and the y-axis extending vertically upward. Determine the initial coordinates and obtain the basic page specification parameters from the page_setup node in the configuration file; the page_setup node is a preset node in the configuration file used to define the page specifications, and the basic specification parameters include the page height, width and margins on all four sides. The initial x-coordinate of the cursor is equal to the left margin of the page, the initial y-coordinate is equal to the page height minus the top margin of the page, and the initial position of the cursor is the starting position of the effective drawing area of ​​the page. Based on the initial position of the cursor, and combined with the size constraints of the parent container and the size and margin parameters of the component itself, determine the geometric position of each component; The remaining height of the current page is calculated based on the current cursor position to determine whether pagination should be triggered; the remaining height of the current page is determined based on the current cursor y-coordinate and the bottom margin of the page.

[0012] Preferably, determining whether pagination processing is triggered includes: Compare the required height of the current component with the remaining height of the current page, and execute the branch decision logic: If the required height of the current component is less than or equal to the remaining height of the current page, then the drawing will start directly from the current cursor position, and the cursor position will be updated after the drawing is completed. If the required height of the current component is greater than the remaining height of the current page, then determine the component's splittable property: if the current component is not splittable, create a new page object, reset the cursor position to the initial position of the new page, and draw the current component on the new page; if the current component is splittable, draw the portion of the component that can be accommodated on the current page, create a new page and reset the cursor, and push the undrawn content as a new component instance to the head of the rendering queue.

[0013] On the other hand, this application also discloses a configuration-driven document flow layout rendering apparatus, including: The configuration generation and verification module is used to generate PDF document configuration files based on four dimensions: document attributes, page layout, component geometry, and style definition. The configuration file is then verified by a pattern validator, and corresponding exception information is thrown when the verification fails. The Document Object Model (DOM) building module is used to traverse configuration files through the parsing engine, identify container nodes and atomic nodes in the configuration, and convert static configuration nodes into a DOM with parent-child nesting relationships. The data injection module is used to receive external business data, traverse the document object model and locate the dynamic slots, query the target business data corresponding to the key name of the dynamic slot, populate the target business data into the corresponding data injection target item, and generate the instance tree to be rendered. The rendering strategy module is used to build a component rendering factory based on the strategy pattern, construct a mapping table between component type identifiers and rendering strategy classes, and dynamically instantiate the corresponding rendering strategy class according to the component type identifier of the rendering node. The rendering and generation module employs a streaming layout algorithm. The rendering engine traverses the tree of instances to be rendered from top to bottom, calculates the geometric position of the components based on the constraint coordinates of the parent container, triggers pagination as needed, binds the geometric position and style attributes to the component instances, generates a standardized set of drawing instructions, executes the drawing instructions through the underlying drawing interface, and generates a PDF document.

[0014] Compared with the prior art, the advantages of the present invention are: (1) This invention extracts the layout and style into the YAML configuration. The business code is only responsible for transmitting data. The layout adjustment only requires modifying the configuration file and does not require modifying the code. It supports hot updating of templates without restarting the service.

[0015] (2) Unlike the common problems of page breaks and blurry fonts when converting HTML to PDF, this invention builds native streaming computing logic based on the underlying drawing engine. It can automatically calculate the height according to the amount of content, accurately control the table header repetition and row break protection when the table spans pages, and meet the stringent printing standards of the financial, medical and other fields.

[0016] (3) By encapsulating the complex drawing instructions at the bottom layer, semantic configuration nodes are provided at the top layer, so that non-core developers, such as product managers or implementation engineers, can configure complex reports by mastering simple YAML syntax, which greatly shortens the development cycle. Attached Figure Description

[0017] The present invention will be further described below with reference to the accompanying drawings and embodiments: Figure 1 This is a flowchart of a configuration-driven document flow layout rendering method according to the present invention.

[0018] Figure 2 This is a schematic diagram of the structure of a configuration-driven document flow layout rendering device according to the present invention. Detailed Implementation

[0019] The present invention will be further described in detail below with reference to specific embodiments: This application is applied to scenarios such as finance, healthcare, and enterprise office work that have stringent requirements for PDF document typesetting accuracy, dynamic adaptability, and ease of maintenance. It addresses the core problems of existing solutions, such as code and style coupling, typesetting loss, and high operational barriers. By configuring a driver architecture, streaming typesetting algorithm, and dynamic data injection mechanism, it achieves efficient document iteration, accurate typesetting, and low-barrier maintenance.

[0020] like Figure 1 As shown, a configuration-driven document flow layout rendering method includes: S1 generates a configuration file for the key-value pair structure of the PDF document based on four dimensions: document attributes, page layout, component geometry, and style definition. The configuration file is then validated using a pattern validator.

[0021] Specifically, document attributes are the basic metadata of a PDF document, used to identify the document's core attributes, including basic configurations such as document title, author, version number, page orientation, and document encryption permissions. These are the document's global identifying information. Page layout refers to the overall specifications of the PDF page, defining the page's physical boundaries and basic layout rules, including page size, margins, header and footer layouts, and determining the effective drawing area of ​​the page. Component geometry refers to the position and size parameters of various visual components in the PDF document. Components include renderable elements such as text blocks, tables, images, and charts, specifically covering the component's width, height, relative position, and spacing between components, clarifying the component's specific place within the effective page area. Style definition refers to the rules for the component's appearance, including font type, font size, font color, background color, border style, table cell margins, and text line spacing, unifying the visual presentation of the components.

[0022] Each dimension of configuration item is broken down into a mapping relationship between key name and value, the key-value pair hierarchy is organized, and the configuration file of key-value pair structure is exported. During the verification, the pattern validator checks in turn whether the necessary keywords of the root node of the configuration file are complete, whether the value type of each configuration item meets the preset standard, and whether the component references resources have been defined. If any link is abnormal, the corresponding exception is thrown.

[0023] In one implementation, based on the specific format requirements of the PDF document provided by the customer, a key-value pair configuration file is generated around four dimensions: document attributes, page layout, component geometry, and style definition. A schema validator is used to perform systematic validation on the configuration file to ensure that the configuration information is complete, compliant in type, and valid in reference.

[0024] S2. Use a parsing engine to traverse the configuration file and convert static configuration nodes into a document object model.

[0025] Specifically, the parsing engine is a dedicated parsing tool adapted to key-value pair configuration files. Its core function is to read the structured key-value pair data in the configuration file, identify the logical relationships of configurations in various dimensions, and parse unstructured text configurations into structured data that can be recognized by the program, providing data support for subsequent node transformations.

[0026] The process of converting static configuration nodes into a document object model is as follows: The parsing engine first recursively traverses the key-value pair hierarchy of the configuration file, mapping the root keys, child keys, and attribute items corresponding to document attributes, page layout, component geometry, and style definitions into independent configuration nodes. Then, it distinguishes between container nodes and atomic nodes by node identifiers. Container nodes correspond to the keys of component configurations that carry other child nodes, while atomic nodes correspond to the keys of text, images, etc., that directly carry renderable content. Finally, according to the hierarchical relationship of the configuration file, it establishes parent-child relationships between nodes, assembling the scattered configuration nodes into a tree structure with a clear logical hierarchy, i.e., the document object model, thus transforming the static key-value pair configuration into a structured data model that the program can operate on and traverse.

[0027] S3. Receive external business data, traverse the document object model and locate the dynamic slots, query the target business data corresponding to the key name of the dynamic slot from the external business data, fill the target business data into the data injection target item to which it belongs, and generate the instance tree to be rendered.

[0028] Specifically, external business data refers to the dynamic, actual data that needs to be populated into the PDF document, i.e., the core content source of the document, such as revenue figures from financial statements, test results from medical reports, and client information from corporate contracts. The format is typically structured data such as JSON, Excel, or database query results. The document object model is traversed recursively, starting from the root node and visiting all child nodes layer by layer, ensuring that no node containing dynamic slots is missed. Dynamic slots are placeholders preset in the configuration file to hold dynamic business data; essentially, they are dynamic data interfaces reserved in static configuration nodes, and their format is predefined using regular expressions for easy program recognition. Key names are the core identifiers in the dynamic slot placeholders, serving as index keywords that associate with external business data. They correspond one-to-one with field names in the external business data, used for precise querying of target business data. Target business data is the specific data content matched from the external business data using the key name. For example, if the external business data contains "A": 500, then the target business data corresponding to the key name "A" is "500".

[0029] The system receives structured business data from business systems. This data contains core dynamic content required for PDF documents, such as product names, transaction quantities, and sales amounts in enterprise sales reports. The data is organized in a field-based format, with each core piece of content corresponding to a clear identifier name, ensuring quick matching and querying via identifiers. Following the tree-like hierarchical structure of the document object model, all nodes in the model are accessed sequentially. The traversal process covers all nodes with potentially pre-defined dynamic slots, ensuring no location requiring dynamic data is missed, providing comprehensive coverage for subsequent slot location. Dynamic slots are identifiers pre-defined in the configuration file to hold dynamic business data, and they correspond one-to-one with the identifier names (keys) of external business data. During traversal, the position of each dynamic slot and its corresponding key name are determined by identifying the pre-defined slot identifiers in the nodes. The key name is the core basis for data matching, directly associating with the target field in the external business data. For example, the key name corresponding to the slot identifier "product name" is the identifier of the "product name" field in the external data.

[0030] Based on the located dynamic slot key name, a matching query is performed in the received external business data to find the specific data content that completely corresponds to the key name, i.e., the target business data. If the slot key name is "transaction quantity", the specific value corresponding to the key name is extracted from the external business data, such as "150 units" or "320 items", to ensure the accuracy of the data query.

[0031] The retrieved target business data is then populated into the data injection target items belonging to the dynamic slots. Text-based target items need to be filled with specific descriptive data, such as "Statistical Period: August 2024" in the report header. Table cell-based target items need to be filled with numerical data in the corresponding columns, such as the specific values ​​in the "Transaction Quantity" column in a sales table. Chart data source-based target items need to be filled with the basic dataset required for chart generation, such as multiple sets of values ​​corresponding to "Monthly Sales" in a line chart. After all dynamic slots of all nodes have been populated with data, the tree hierarchy of the original document object model is maintained to form a rendering instance tree containing real business data. This instance tree already has a complete structure and data and can be directly used in subsequent rendering processes.

[0032] In one implementation, taking the generation of a company's monthly sales report as an example: the received external business data includes the fields "Product Name", "Quantity Sold", "Selling Price per Unit", and "Total Sales Amount" for three products; when traversing the document object model, the four dynamic slots corresponding to the "Product Name", "Quantity", "Unit Price", and "Sales Amount" columns in the sales table are located, and their key names are consistent with the four field identifiers of the external data; after querying the corresponding data for each product through key name matching, the data is filled into the corresponding cells of the table one by one, and the "Statistical Period" slot in the report header is filled with the data of the current month. Finally, a rendering instance tree containing complete sales data is generated to ensure the accuracy and completeness of the report data.

[0033] S4. Construct a component rendering factory based on the strategy pattern, build a mapping table between component type identifiers and rendering strategy classes, and dynamically instantiate the corresponding rendering strategy class according to the component type identifier of the rendering node.

[0034] Specifically, the core of this step is to decouple and flexibly adapt the rendering logic of different types of components through a combination of the strategy pattern and the factory pattern. This allows the rendering engine to call the corresponding rendering logic simply by knowing the component type, without needing to concern itself with the rendering details of specific components. The strategy pattern is a design pattern that decouples an algorithm from the entity that uses it. In this solution, the algorithm is the rendering logic of different components, such as how to render font styles for text, how to render row and column structures for tables, and how to render data visualization effects for charts. The entity that uses the algorithm is the rendering engine. By using the strategy pattern, the rendering logic of each component can be encapsulated into an independent rendering strategy class, avoiding a large number of conditional judgments in the rendering engine. For example, if it is text, execute logic A; if it is a table, execute logic B, thus improving code maintainability.

[0035] The component rendering factory is the core module responsible for managing all rendering strategy classes and providing strategy instantiation services. Its core responsibilities include: maintaining the correspondence between component types and strategy classes, receiving instantiation requests from the rendering engine, and matching and creating corresponding strategy class instances based on component types. This eliminates the need for the rendering engine to interact directly with specific strategy classes, reducing coupling between modules.

[0036] The component type identifier is a unique identifier preset for each renderable component, such as "text" for text components, "table" for table components, and "chart" for chart components. This identifier is bound to the component in the configuration file in step S1 and is synchronously stored in the component node of the document object model and the tree of instances to be rendered, serving as an index keyword for matching the rendering strategy class.

[0037] Rendering strategy classes are independent classes that encapsulate the rendering logic of a single component. Each component type corresponds to a dedicated strategy class, which contains the complete rendering logic for that component. For example, a text rendering strategy class encapsulates the rendering rules for font size, color, and line spacing, while a table rendering strategy class encapsulates the rendering rules for row and column layout, border styles, and cell alignment. All strategy classes follow a unified interface specification to ensure that the rendering engine can call them uniformly.

[0038] The mapping table is a structured data storage system that maps component type identifiers to rendering strategy classes. For example, {"text": text rendering strategy class, "table": table rendering strategy class, "chart": chart rendering strategy class}. The mapping table is maintained by the component rendering factory. When adding a new component type, only the mapping table needs to be updated with the new identifier and strategy class; there is no need to modify the rendering engine or the factory's core logic, demonstrating strong extensibility.

[0039] Dynamic instantiation means that the rendering engine does not create all strategy class instances in advance. Instead, it searches for the corresponding strategy class through the component rendering factory when it traverses the instance tree to be rendered and encounters a specific component node, and creates an instance of that class in real time. This avoids unnecessary memory consumption and ensures that a brand new strategy class instance can be obtained for each rendering, avoiding state interference when rendering multiple components.

[0040] In one implementation, the instance tree to be rendered in the enterprise's monthly sales report contains three types of core component nodes: "Report Title" (text component, type identifier "text"), "Sales Data Details" (table component, type identifier "table"), and "Monthly Sales Trend" (line chart component, type identifier "chart").

[0041] When the rendering engine iterates to the "Report Title" node, it extracts the identifier "text" and passes it to the component rendering factory. The factory matches the "Text Rendering Strategy Class" from the mapping table, dynamically instantiates it, and loads the font, color, and other configurations of the title, preparing to execute text rendering. When it iterates to the "Sales Data Details" node, it extracts the identifier "table," the factory matches the "Table Rendering Strategy Class" and instantiates it. The instance loads the table's border style, cell inner margins, sales data, and other information, preparing to execute table rendering. When it iterates to the "Monthly Sales Trend" node, it extracts the identifier "chart," the factory matches the "Chart Rendering Strategy Class" and instantiates it. The instance loads the line chart's axis range, legend position, sales dataset, and other information, preparing to execute chart rendering.

[0042] Through this process, the rendering logic of different components is completely encapsulated in independent strategy classes. The rendering engine only needs to instantiate the strategy through type identifier and factory scheduling. This solves the problems of high coupling between rendering logic and engine and difficulty in expansion in traditional solutions. It also ensures that when adding a new component type, only an image rendering strategy class needs to be added and the mapping table updated, without modifying the core code of the rendering engine, which greatly improves the scalability and maintainability of the system.

[0043] S5 employs a streaming layout algorithm. The rendering engine traverses the tree of instances to be rendered from top to bottom, calculates the geometric position of the component based on the constraint coordinates of the parent container, triggers pagination as needed, binds the geometric position and style attributes to the component instance, generates a standardized drawing instruction set, executes the drawing instructions through the underlying drawing interface, and generates a PDF document.

[0044] Specifically, the standardized drawing instruction set transforms the geometric position, style attributes, and content data of components into unified format execution instructions. These instructions are standardized and recognizable by the underlying drawing interface, ensuring consistent rendering logic. The underlying drawing interface is a universal interface that interacts with the PDF generation kernel. It receives standardized drawing instructions, calls underlying functions related to PDF rendering, and converts the instructions into underlying data recognizable by the PDF document. Users do not need to concern themselves with the internal implementation of the interface; they only need to pass in the instructions according to the specifications to complete the visual rendering.

[0045] In one implementation, in a scenario for rendering a monthly sales report for an enterprise, the instance tree to be rendered contains four core components: "Report Title," "Sales Data Table," "Monthly Sales Trend Chart," and "Summary Statistical Text." The rendering engine traverses the instance tree from top to bottom, first processing the "Report Title" component. Using the page as the parent container, it calculates the geometric position of the title component at the top center of the page, binds the style attribute "Microsoft YaHei No. 16, #333333 color", and generates text drawing instructions. Next, process the "Sales Data Table" component. Using the page as the parent container, calculate the starting coordinates of the table based on the end position of the title component. The table contains 100 rows of data, but the current page can only hold 60 rows, triggering pagination. Draw the first 60 rows of the table on the current page, and draw the remaining 40 rows of the table after creating a new page to ensure that the table content is complete. Next, process the "Monthly Sales Trend Chart" component, calculate the chart position below the table on the second page, bind the chart style, and generate chart drawing instructions; Finally, process the "Summary Statistics Text" component, calculate the text position below the chart, bind style attributes, and generate text instructions; The drawing instructions for all components are passed to the underlying drawing interface in sequence. The interface executes the instructions one by one, and finally generates a sales report PDF containing two pages of content. The first page contains the title and the first 60 rows of tables, and the second page contains the remaining tables, charts and summary text. The layout is neat and the content is continuous, which meets the business needs.

[0046] In summary, this solution achieves complete decoupling of document structure, style, and code through key-value pair configuration files. Layout and style adjustments only require modifying the configuration file, without altering the core code, significantly reducing maintenance costs and iteration cycles. Even non-technical personnel can participate in configuration. A precise matching mechanism between dynamic slots and key names enables flexible binding of static configurations and external business data, adapting to dynamic data filling needs across multiple scenarios. A structured transformation process involving configuration files, document object models, and the tree of instances to be rendered enhances the stability and operability of document generation. A component rendering factory built based on the strategy pattern decouples the rendering logic of different components, giving the system strong scalability. A streaming typesetting algorithm and parent container constraint coordinate calculation ensure reasonable component arrangement and trigger pagination as needed, avoiding cross-page content truncation and guaranteeing the typesetting accuracy and content integrity of PDF documents. This fully meets the core demands of finance, healthcare, and enterprise office sectors for efficient iteration, accurate typesetting, and low-barrier maintenance in document generation.

[0047] The method for generating a key-value pair configuration file for a PDF document based on four dimensions—document attributes, page layout, component geometry, and style definition—is to generate a YAML-formatted configuration file according to a hierarchical document description protocol.

[0048] Specifically, YAML configuration files are a lightweight, human-readable markup language that natively supports key-value mapping and hierarchical structure expression. They do not require complex syntax, making them suitable for program parsing and easy for non-technical personnel to edit. Compared to other formats, such as JSON files, they are more concise and intuitive.

[0049] The steps for validating the configuration file using a pattern validator include: Read the configuration file and check if the root node contains the necessary keywords. If any are missing, throw an exception. For each configuration item, check whether the type of its value conforms to the preset standard; if an exception is found, throw an exception. Iterate through the configuration items and check whether all resources referenced by the component nodes are defined. If the referenced resources are not defined, throw an exception.

[0050] Specifically, the essential keywords refer to the core identifiers that the root node of the configuration file must contain. They correspond to the root keys of the four configuration dimensions: document properties, page layout, component geometry, and style definition. They are the basis for the subsequent parsing engine to identify the configuration structure and traverse the configuration items. If they are missing, the configuration file cannot be parsed normally.

[0051] Preset standards refer to the predefined value type rules for each configuration item, which specify the allowed types based on the functional attributes of the configuration item, such as numeric, enumeration, string, and boolean types.

[0052] Verify all resources referenced by component nodes. Specifically, this refers to content that the component depends on and that needs to be predefined in other modules of the configuration file, including style names, external resource paths, component identifiers, etc. Such resources need to be defined in advance to ensure that the component renders correctly.

[0053] In one implementation, the pattern validator first reads the complete YAML configuration file, parses all first-level subkeys under the root node, and compares them with a preset list of necessary keywords. If the root node contains all the necessary keywords, the validation passes this step. If any keyword is missing, an exception is thrown immediately, and the subsequent validation process is terminated, prompting the user to add the corresponding keyword.

[0054] After passing the structure validation, the validator traverses all levels of configuration items in the configuration file and checks whether the value of each configuration item conforms to its corresponding preset standard; if the value type of a configuration item does not conform to the preset standard, an exception is thrown.

[0055] The validator continues to traverse the configuration items of all component nodes, extracts the content involving resource references, and checks whether the resource already exists in the corresponding definition module of the configuration file. If the referenced resource is explicitly defined in the configuration file, the validation passes; if the referenced resource cannot be found in the corresponding definition, an exception is thrown.

[0056] Traverse the document object model and locate its dynamic slots, including: The rendering engine loads the component tree and recursively accesses the properties of each component object; the component tree is a document object model, which is a tree structure with parent-child nesting relationships. For nodes whose attribute values ​​are strings, use regular expressions to extract the placeholders. Extract the corresponding key name from the capture group of the regular expression matching result to complete the location of the dynamic slot; the key name is the index identifier for the target business data query.

[0057] Specifically, nodes with string attribute values ​​are the sole carriers of dynamic slots. Dynamic slots are embedded in text as placeholders, such as the content attributes of table cells, the descriptive attributes of text components, and the legend text attributes of charts. Regular expressions are preset text matching rules used to accurately identify dynamic slot placeholders within strings. Placeholders are identifier text embedded in string nodes, used to carry dynamic data, with the format {{key name}}. They are the visual representation of dynamic slots and can be quickly identified using regular expressions. Capture groups are functional modules within regular expressions used to extract target content. In this solution, capture groups are used to accurately extract the core content between placeholder separators, i.e., the key name, eliminating separator interference.

[0058] Populate the target business data into its corresponding data injection target item, including: Establish a context data dictionary and load the received external business data into the context data dictionary; For the key names of the identified dynamic slots, parse the key names of the nested structure and recursively query the corresponding target business data in the context data dictionary; If the target business data is found, the placeholder in the dynamic slot will be replaced with the target business data to complete the data injection target item filling. If the business data with the corresponding key name is not found in the context data dictionary, it will be processed according to the preset strategy to avoid rendering errors.

[0059] Specifically, the context data dictionary is a structured data container for storing external business data. It organizes data using key-value pair mappings, supports single-level and multi-level nested structures, and can uniformly convert external business data in formats such as JSON and Excel into a format that programs can quickly query. The key names in the nested structure refer to the key names containing hierarchical relationships in the dynamic slots, corresponding to the nested field structure in the external business data. The target data can only be accurately located through hierarchical parsing.

[0060] The default strategy is a set of missing data fault handling rules predefined in the configuration file, including at least one of the following: Do not replace the placeholders for dynamic slots; retain the original placeholders. Replace the placeholder for the dynamic slot with an empty string; Replace the placeholder with the preset prompt text in the configuration file; the prompt text is "No data available" or "Data not configured".

[0061] Specifically, missing data refers to business data in the context data dictionary that does not have a corresponding dynamic slot key name, meaning that the external business data does not provide the content required for that slot.

[0062] In one implementation, the received external business data is a monthly sales report of the enterprise. Users specify fault tolerance rules in the configuration file according to component type. For table cells, the third rule is used, with the prompt text set to "No data available." For independent text blocks, the second rule is used, and for chart data sources, the first rule is used. In the external business data, device A lacks data in the "profit" dynamic slot, and device B lacks data in the "quantity" dynamic slot. According to the preset strategy and the fault tolerance rules set by the user, device B's "Transaction Quantity" is rendered as "Transaction Quantity: No data available," and device A's "Profit per Unit" is rendered as "Profit per Unit: No data available." The "Data Update Time" slot at the end of the report has no data and is rendered as "Data Update Time:" followed by a blank space. The quarterly sales slot in the sales trend chart has no data and retains the original key name {{quarter_sales}} for rendering, facilitating the identification of unmatched key names during debugging.

[0063] The methods for calculating the geometric position of a component based on the parent container's constraint coordinates and triggering pagination on demand include: The rendering engine uses a Cartesian coordinate system for positioning, with the bottom left corner of the page as the origin, the x-axis extending horizontally to the right, and the y-axis extending vertically upward. Determine the initial coordinates and obtain the basic page specification parameters from the page_setup node in the configuration file; the page_setup node is a preset node in the configuration file used to define the page specifications, and the basic specification parameters include the page height, width and margins on all four sides. The initial x-coordinate of the cursor is equal to the left margin of the page, the initial y-coordinate is equal to the page height minus the top margin of the page, and the initial position of the cursor is the starting position of the effective drawing area of ​​the page. Based on the initial position of the cursor, and combined with the size constraints of the parent container and the size and margin parameters of the component itself, determine the geometric position of each component; The remaining height of the current page is calculated based on the current cursor position to determine whether pagination should be triggered; the remaining height of the current page is determined based on the current cursor y-coordinate and the bottom margin of the page.

[0064] Specifically, the Cartesian coordinate system is the pre-defined unified position calculation benchmark system in this solution. With the bottom left corner of the page as the origin, the x-axis extends horizontally to the right (larger values ​​indicate a more rightward position), and the y-axis extends vertically upwards (larger values ​​indicate a higher position). The (x, y) coordinate combination uniquely determines the component's position on the page, avoiding positional deviations caused by a chaotic coordinate system. The cursor is a dynamic pointer that identifies the starting position of the next component within the currently valid drawing area of ​​the page. Its coordinates are updated in real-time as the component is drawn, making it the core tool for achieving fluid layout and ensuring that components are arranged sequentially from top to bottom.

[0065] Determining whether pagination is triggered includes: Compare the required height of the current component with the remaining height of the current page, and execute the branch decision logic: If the required height of the current component is less than or equal to the remaining height of the current page, then the drawing will start directly from the current cursor position, and the cursor position will be updated after the drawing is completed. If the required height of the current component is greater than the remaining height of the current page, then determine the component's splittable property: if the current component is not splittable, create a new page object, reset the cursor position to the initial position of the new page, and draw the current component on the new page; if the current component is splittable, draw the portion of the component that can be accommodated on the current page, create a new page and reset the cursor, and push the undrawn content as a new component instance to the head of the rendering queue.

[0066] In one implementation, taking the layout of a company's monthly sales report as an example, the page_setup node is configured as follows: size A4, width 210mm, height 297mm, top margin 20mm, bottom margin 20mm, left margin 15mm, and right margin 15mm; the rendering engine uses a Cartesian coordinate system, extracts the page_setup parameters, and calculates the initial cursor position as (15mm, 277mm); first, the position of the report title component is calculated, the component is preset to width 18mm, height 20mm, with no extra margins, and the geometric position is calculated as (15mm, 277mm, 180mm, 20mm), after drawing, the cursor y-coordinate is updated to 277mm-20mm=257mm. The remaining height is 257mm - 20mm = 237mm. The position of the sales table component is calculated. The component has a preset width of 180mm and a height of 240mm, containing 100 rows of data. The required height of 240mm is greater than the remaining height of 237mm, triggering pagination. The pagination process executes branch decision logic. After pagination, a new page object is created. The initial cursor position on the new page remains (15mm, 277mm). The position of the sales table on the new page is calculated as (15mm, 277mm, 180mm, 240mm). After drawing, the cursor y-coordinate is updated to 277mm - 240mm = 37mm, and the remaining height is 37mm - 20mm = 17mm, which can be used to draw subsequent small components.

[0067] This application also provides a configuration-driven document flow layout rendering apparatus for implementing a configuration-driven document flow layout rendering method, such as... Figure 2 As shown, it includes: The configuration generation and verification module is used to generate PDF document configuration files based on four dimensions: document attributes, page layout, component geometry, and style definition. The configuration file is then verified by a pattern validator, and corresponding exception information is thrown when the verification fails. The Document Object Model (DOM) building module is used to traverse configuration files through the parsing engine, identify container nodes and atomic nodes in the configuration, and convert static configuration nodes into a DOM with parent-child nesting relationships. The data injection module is used to receive external business data, traverse the document object model and locate the dynamic slots, query the target business data corresponding to the key name of the dynamic slot, populate the target business data into the corresponding data injection target item, and generate the instance tree to be rendered. The rendering strategy module is used to build a component rendering factory based on the strategy pattern, construct a mapping table between component type identifiers and rendering strategy classes, and dynamically instantiate the corresponding rendering strategy class according to the component type identifier of the rendering node. The rendering and generation module employs a streaming layout algorithm. The rendering engine traverses the tree of instances to be rendered from top to bottom, calculates the geometric position of the components based on the constraint coordinates of the parent container, triggers pagination as needed, binds the geometric position and style attributes to the component instances, generates a standardized set of drawing instructions, executes the drawing instructions through the underlying drawing interface, and generates a PDF document.

[0068] The above embodiments are merely illustrative of the technical concept and features of the present invention, intended to enable those skilled in the art to understand the content of the present invention and implement it accordingly, and should not be construed as limiting the scope of protection of the present invention. It will be apparent to those skilled in the art that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention. Therefore, the embodiments should be considered exemplary and non-limiting in all respects. The scope of the present invention is defined by the appended claims rather than the foregoing description, and thus all changes falling within the meaning and scope of the equivalents of the claims are intended to be included within the present invention.

Claims

1. A configuration-driven document flow layout rendering method, characterized in that, include: A configuration file for generating a key-value pair structure of a PDF document is generated based on four dimensions: document attributes, page layout, component geometry, and style definition. The configuration file is then validated using a pattern validator. A parsing engine is used to traverse the configuration file and convert static configuration nodes into a document object model; Receive external business data, traverse the document object model and locate the dynamic slots, query the target business data corresponding to the key name of the dynamic slot from the external business data, fill the target business data into its data injection target item, and generate the instance tree to be rendered. The data injection targets include text, table cells, and icon data sources; A component rendering factory is built based on the strategy pattern, and a mapping table between component type identifiers and rendering strategy classes is constructed. The rendering engine dynamically instantiates the corresponding rendering strategy class according to the component type identifier of the rendering node. Employing a streaming layout algorithm, the rendering engine traverses the tree of instances to be rendered from top to bottom, calculates the geometric position of the components based on the constraint coordinates of the parent container, triggers pagination as needed, binds the geometric position and style attributes to the component instance, generates a standardized drawing instruction set, executes the drawing instructions through the underlying drawing interface, and generates a PDF document.

2. The document flow layout rendering method based on configuration-driven approach according to claim 1, characterized in that, The method for generating a key-value pair configuration file for a PDF document based on four dimensions—document attributes, page layout, component geometry, and style definition—is to generate a YAML-formatted configuration file according to a hierarchical document description protocol.

3. The document flow layout rendering method based on configuration-driven approach according to claim 1, characterized in that, The step of validating the configuration file using a pattern validator includes: Read the configuration file and check if the root node contains the necessary keywords. If any are missing, throw an exception. For each configuration item, check whether the type of its value conforms to the preset standard; if an exception is found, throw an exception. Iterate through the configuration items and check whether all resources referenced by the component nodes are defined. If the referenced resources are not defined, throw an exception.

4. The document flow layout rendering method based on configuration-driven approach according to claim 1, characterized in that, The process of traversing the document object model and locating its dynamic slots includes: The rendering engine loads the component tree and recursively accesses the properties of each component object; the component tree is a document object model, which is a tree structure with parent-child nesting relationships; For nodes whose attribute values ​​are strings, use regular expressions to extract the placeholders. Extract the corresponding key name from the capture group of the regular expression matching result to complete the location of the dynamic slot; the key name is the index identifier of the target business data query.

5. The document flow layout rendering method based on configuration-driven approach according to claim 1, characterized in that, The step of filling the target business data into its corresponding data injection target item includes: Establish a context data dictionary and load the received external business data into the context data dictionary; For the key names of the identified dynamic slots, parse the key names of the nested structure and recursively query the corresponding target business data in the context data dictionary; If the target business data is found, the placeholder in the dynamic slot will be replaced with the target business data to complete the data injection target item filling. If the business data with the corresponding key name is not found in the context data dictionary, it will be processed according to the preset strategy to avoid rendering errors.

6. The document flow layout rendering method based on configuration-driven approach according to claim 5, characterized in that, The preset strategy is a missing data fault tolerance handling rule predefined in the configuration file, including at least one of the following: Do not replace the placeholders for dynamic slots; retain the original placeholders. Replace the placeholder for the dynamic slot with an empty string; Replace the placeholder with the preset prompt text in the configuration file; the prompt text is "No data available" or "Data not configured".

7. The document flow layout rendering method based on configuration-driven approach according to claim 1, characterized in that, The method for calculating the geometric position of a component based on the parent container's constraint coordinates and triggering pagination on demand includes: The rendering engine uses a Cartesian coordinate system for positioning, with the bottom left corner of the page as the origin, the x-axis extending horizontally to the right, and the y-axis extending vertically upward. Determine the initial coordinates and obtain the basic page specification parameters from the page_setup node in the configuration file; the page_setup node is a preset node in the configuration file used to define the page specifications, and the basic specification parameters include the page height, width and margins on all four sides. The initial x-coordinate of the cursor is equal to the left margin of the page, the initial y-coordinate is equal to the page height minus the top margin of the page, and the initial position of the cursor is the starting position of the effective drawing area of ​​the page. Based on the initial position of the cursor, and combined with the size constraints of the parent container and the size and margin parameters of the component itself, determine the geometric position of each component; The remaining height of the current page is calculated based on the current cursor position to determine whether pagination should be triggered; the remaining height of the current page is determined based on the current cursor y-coordinate and the bottom margin of the page.

8. The document flow layout rendering method based on configuration-driven approach according to claim 7, characterized in that, The determination of whether pagination processing is triggered includes: Compare the required height of the current component with the remaining height of the current page, and execute the branch decision logic: If the required height of the current component is less than or equal to the remaining height of the current page, then the drawing will start directly from the current cursor position, and the cursor position will be updated after the drawing is completed. If the required height of the current component is greater than the remaining height of the current page, then determine the component's splittable property: if the current component is not splittable, create a new page object, reset the cursor position to the initial position of the new page, and draw the current component on the new page; if the current component is splittable, draw the portion of the component that can be accommodated on the current page, create a new page and reset the cursor, and push the undrawn content as a new component instance to the head of the rendering queue.

9. A configuration-driven document flow layout rendering apparatus, used to implement the configuration-driven document flow layout rendering method as described in any one of claims 1-8, characterized in that, include: The configuration generation and verification module is used to generate PDF document configuration files based on four dimensions: document attributes, page layout, component geometry, and style definition. The configuration file is then verified by a pattern validator, and corresponding exception information is thrown when the verification fails. The Document Object Model (DOM) building module is used to traverse configuration files through the parsing engine, identify container nodes and atomic nodes in the configuration, and convert static configuration nodes into a DOM with parent-child nesting relationships. The data injection module is used to receive external business data, traverse the document object model and locate the dynamic slots, query the target business data corresponding to the key name of the dynamic slot, populate the target business data into the corresponding data injection target item, and generate the instance tree to be rendered. The rendering strategy module is used to build a component rendering factory based on the strategy pattern, construct a mapping table between component type identifiers and rendering strategy classes, and dynamically instantiate the corresponding rendering strategy class according to the component type identifier of the rendering node. The rendering and generation module employs a streaming layout algorithm. The rendering engine traverses the tree of instances to be rendered from top to bottom, calculates the geometric position of the components based on the constraint coordinates of the parent container, triggers pagination as needed, binds the geometric position and style attributes to the component instances, generates a standardized set of drawing instructions, executes the drawing instructions through the underlying drawing interface, and generates a PDF document.