Template-based AI multi-format report rapid generation method

CN122549376APending Publication Date: 2026-08-11BEIJING HUAZHIXIN SOFTWARE 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
2026-05-18
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

[0003]这种做法在应对复杂版面时存在可见的工程局限性:当面临严格的页面尺寸约束时,为防止内容溢出,排版引擎通常会缩小字体或忽略原始宽高比去挤压图片,导致图表关键刻度或截图细节低于人眼分辨下限;或者采用按行截断的分页策略,使得语义强绑定的文本与视觉证据被分隔在不同页面,增加了用户的认知成本

Benefits of technology

[0007]本发明的有益效果在于:通过建立基于客观视觉分辨能力与版面空间约束的寻优与排布机制,解决了人工智能动态生成内容在固定页面呈现时易出现的图文割裂、图像变形、内容溢出及跨格式阅读顺序错位等问题。本发明将图文语义关联度、最小可辨识面积界限与跨页锚定距离等客观参量纳入统筹,引导引擎在限定的空间网格内合理分配输出字数与图像缩放比,保障了双格式输出时视觉展示与逻辑消费顺序的一致性;同时通过合规审计环节剔除了拉伸畸变与无事实支撑的虚构生成内容,兼顾了自动化生成报告的版面规范性、事实可靠性及跨模态输出的同源稳定性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122549376A_ABST
    Figure CN122549376A_ABST
Patent Text Reader

Abstract

This invention relates to the field of report text generation technology and discloses a method for rapid generation of multi-format reports based on template configuration using AI. The method includes: first, parsing the template to construct a constraint graph and slots, establishing spatial boundaries within the page; then, extracting facts from the output data and binding images to generate evidence units and relevance; calculating the minimum graph area and minimum character area, and combining anchor distance and order difference to obtain the critical relevance; subsequently, constructing fitness using this and the overflow area, and performing swarm intelligence optimization to determine the layout plan within the discrete grid; then, performing text and image layout according to the allocated maximum number of characters and image scaling ratio, and generating binding identifiers for constraint cross-layer homology; finally, synchronously rendering two layers based on the identifiers and extracting bounding boxes to calculate consistency loss, and outputting a multi-format report after passing compliance audits for deformation, detail, and support rate. This invention improves the layout adaptability and content reliability of text and image reports.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of report text generation technology, and more specifically, to an AI-based method for rapid generation of multi-format reports based on template configuration. Background Technology

[0002] In the development practice of automated document generation and intelligent typesetting, it is a common business requirement to directly output richly illustrated reports using artificial intelligence large language models. In actual engineering implementation, developers often face a conflict between the uncertainty of model text generation and the constraints of fixed pages. Conventional business implementations often adopt a decoupled logic of generating text first and then typesetting: prompting the model to output long text using prompts, and then using a front-end typesetting engine (such as a DOM-based web page rendering library or PDF conversion component) to insert images into the flowing text.

[0003] This approach has visible engineering limitations when dealing with complex layouts: when faced with strict page size constraints, in order to prevent content overflow, the layout engine usually reduces the font size or ignores the original aspect ratio to squeeze the image, resulting in key scales in charts or screenshot details being below the lower limit of human eye resolution; or it adopts a pagination strategy that truncates by line, which separates semantically strong text and visual evidence into different pages, increasing the cognitive cost for users.

[0004] Furthermore, when dealing with multi-format exports (such as simultaneously generating logical documents focused on data extraction and parsing, and visual layout documents focused on human review), existing conversion components tend to focus on hard-coded mapping of cascading styles or coordinates, with less consideration for the consistency of the underlying reading order. This can easily lead to a misalignment between the node order read by the machine and the actual visual scanning order. From the perspective of large model calls, simply relying on prompts to limit the number of words output by the model is ineffective because the generation engine lacks a closed-loop perception of actual rendered pixels, device viewing distance, and visual boundaries during the inference phase. Additionally, in order to respond to length instructions or fill layout blanks, the model sometimes deviates from the input evidence pool data, splicing unfounded statements. These development-level challenges mean that existing components and workflows have room for improvement in balancing image-text proximity, visual recognition lower limits, and the completeness of the content evidence chain. Summary of the Invention

[0005] This invention provides a method for rapid generation of AI multi-format reports based on template configuration, which solves the technical problems mentioned in the background.

[0006] This invention provides a template-based AI method for rapid generation of multi-format reports, applicable to report systems that include both logical and formatting layers, including: The template configuration is parsed to construct a constraint graph and slots representing the location topology, thus establishing the physical boundaries within the page; Facts are extracted from the output data and bound to images to generate evidence units bound to source features and the degree of relevance representing the semantic dependency relationship between images and text; The minimum image area that ensures visual recognition and the minimum character area that ensures character readability are calculated by the evidence unit. The anchor distance that eliminates page scale interference and the order difference that represents reading misalignment are combined to obtain the critical correlation degree used to evaluate the limit of spatial adaptation. A fitness factor is constructed to evaluate the feasibility of layout based on the critical correlation degree and the overflow area beyond the physical boundary, and swarm intelligence optimization is performed to determine the layout plan within the discrete grid. Based on the maximum number of characters allocated by the typesetting plan to eliminate character overflow and the image scaling ratio to maintain the original aspect ratio, the text and image layout is performed to generate binding identifiers that constrain cross-layer homology. Based on the binding identifier, the logic layer and the layout layer are rendered synchronously, and the bounding box is extracted to calculate the consistency loss of the spatial deviation between the layers. An anti-distortion audit is performed based on the deformation rate (characterizing the degree of deformation), the detail margin (characterizing the degree of resolution deviation), and the support rate (characterizing the level of objective support). A report is generated after the audit is passed.

[0007] The beneficial effects of this invention are as follows: By establishing an optimization and layout mechanism based on objective visual discrimination capabilities and page space constraints, it solves the problems of image-text separation, image distortion, content overflow, and misaligned reading order when AI-generated dynamic content is presented on a fixed page. This invention incorporates objective parameters such as semantic relevance between images and text, minimum identifiable area limits, and cross-page anchoring distances into a unified framework, guiding the engine to rationally allocate the number of output words and image scaling ratios within a limited spatial grid, ensuring consistency between visual display and logical consumption order when outputting in both formats; at the same time, through compliance auditing, it eliminates stretched distortions and fictitious generated content without factual support, taking into account the layout standardization, factual reliability, and source consistency stability of automatically generated reports. Attached Figure Description

[0008] Figure 1 This is a flowchart of the AI ​​multi-format report rapid generation method based on template configuration of the present invention. Detailed Implementation

[0009] The subject matter described herein will now be discussed with reference to exemplary embodiments. It should be understood that these embodiments are discussed only to enable those skilled in the art to better understand and implement the subject matter described herein, and changes may be made to the function and arrangement of the elements discussed without departing from the scope of this specification. Various processes or components may be omitted, substituted, or added as needed in the examples. Furthermore, features described in some examples may be combined in other examples.

[0010] like Figure 1 As shown, the template-based AI-powered method for rapid generation of multi-format reports is applied to a report system that includes both logical and formatting layers, including: The template configuration is parsed to construct a constraint graph and slots representing the location topology, thus establishing the physical boundaries within the page; Facts are extracted from the output data and bound to images to generate evidence units bound to source features and the degree of relevance representing the semantic dependency relationship between images and text; The minimum image area that ensures visual recognition and the minimum character area that ensures character readability are calculated by the evidence unit. The anchor distance that eliminates page scale interference and the order difference that represents reading misalignment are combined to obtain the critical correlation degree used to evaluate the limit of spatial adaptation. A fitness factor is constructed to evaluate the feasibility of layout based on the critical correlation degree and the overflow area beyond the physical boundary, and swarm intelligence optimization is performed to determine the layout plan within the discrete grid. Based on the maximum number of characters allocated by the typesetting plan to eliminate character overflow and the image scaling ratio to maintain the original aspect ratio, the text and image layout is performed to generate binding identifiers that constrain cross-layer homology. Based on the binding identifier, the logic layer and the layout layer are rendered synchronously, and the bounding box is extracted to calculate the consistency loss of the spatial deviation between the layers. An anti-distortion audit is performed based on the deformation rate (characterizing the degree of deformation), the detail margin (characterizing the degree of resolution deviation), and the support rate (characterizing the level of objective support). A report is generated after the audit is passed.

[0011] The template-based AI multi-format report rapid generation method provided in this embodiment is applied to a report system that includes a logic layer and a layout layer. The logic layer generates machine-readable structured content, while the layout layer generates human-readable visual page content.

[0012] S201: Extract the layout point value and Cascading Style Sheet pixels, and convert them into a dimensionless physical length to eliminate cross-device scale interference.

[0013] The template configuration is stored in JSON format. The root node contains a `pages` array, where each `page` node corresponds to a page and includes fields for `width`, `height`, `margin_top`, `margin_bottom`, `margin_left`, `margin_right`, and an array of `slots`. Each element in the `slots` array corresponds to a slot and includes fields for `x`, `y`, `width`, `height`, `role`, and `font_size`. The conversion process is achieved using the following formula: ; ; In the formula, 1 represents the converted physical length; pt represents the layout point value, extracted from the font_size field in the template configuration; csspx represents the Cascading Style Sheets pixels, extracted from the x, y, width, and height fields in the template configuration. The conversion factor is derived based on the standard definition that 1 inch equals 72 points, 96 pixels, and 1 inch equals 0.0254 meters.

[0014] S202: Extract the slot coordinates, slot size, and semantic tags from the template configuration, multiply the slot size lengths to obtain the slot area representing the physical capacity limit, and construct the slot.

[0015] The slot coordinates are based on the top-left corner of the page, with the x-axis pointing horizontally to the right and the y-axis pointing vertically downwards. Slots are constructed using the following formula: ; ; In the formula, For the constructed slots, s is the slot number, which ranges from 1 to M, and M is the total number of slots; , The coordinates of the top-left corner of the slot on the page are obtained by converting the x and y fields configured in the template using S201. , The width and height of the slot are obtained by converting the width and height fields configured in the template using S201. The page number where the slot is located is extracted from the page node index configured in the template; The semantic tags for the slots include title, subtitle, body_text, figure_area, caption, header, and footer. The slot area represents the maximum physical space that the slot can accommodate.

[0016] S203: Analyze the adjacency, containment, reading order, or non-overlapping relationships between slots within the available page number and establish a constraint graph representing the anti-collision conditions between slots.

[0017] The constraint diagram is constructed using the following formula: ; In the formula, This is a constraint diagram; S is the set of all slots. This is the set of edges representing the relationships between slots; , For different slots; The relationship determination operator has the following specific logic: Adjacency is determined when the boundary distance between two slots is less than or equal to 0.001 meters; Containment is determined when all boundary coordinates of one slot are greater than or equal to the corresponding boundary coordinates of another slot; Reading order is determined based on the order of the slots array in the template configuration, with the slots listed earlier in the array having higher reading order. If the array order is not specified, it is determined based on the semantic tag priority, which is title>subtitle>body_text>figure_area>caption>header>footer; Non-overlapping is applied to all slots at the same level and is determined when the intersection area of ​​the bounding boxes of two slots is equal to 0.

[0018] S301: Combine facts and their corresponding images, captions, anchors and source sets to form an evidence unit with independent tracing attributes.

[0019] Output materials support PDF, Word, HTML, and Markdown formats. Fact extraction employs a BERT-based named entity recognition and relation extraction model. The input is the plain text content of the output materials, and the output is a list of fact texts, with each fact containing text content and its character offset in the original document. The binding of facts to images is achieved by calculating the cosine similarity between the fact text vector and the image description vector, with a similarity threshold of 0.7. A binding relationship is established if the similarity is greater than or equal to the threshold. The anchor format is document ID:page number:paragraph start offset - paragraph end offset. The source set is a JSON object containing the fields source_id, source_name, source_type, generate_time, and authority_level. The construction of evidence units is achieved using the following formula: ; In the formula, For each evidence unit, u is the unit number, ranging from 1 to U, where U is the total number of evidence units. For factual text extracted from the output data; The image binary data corresponding to this fact; Captions for images; This serves as the anchor point for facts in the original output data; A collection of sources of facts and images.

[0020] The output data parsing employs a format-specific processing logic: For PDF format, the PyMuPDF library is used to extract text and embedded images, with text split by page number and natural paragraphs, and images extracted as lossless PNG format; for Word format, the python-docx library is used to extract the main text and embedded images, preserving the paragraph hierarchy; for HTML format, the BeautifulSoup library is used to parse the DOM tree, extracting visible text and remote or local images corresponding to img tags; for Markdown format, the markdown-it-py library is used to parse the plain text content and image resources corresponding to image links.

[0021] Image description vectors are generated using a BLIP-base pre-trained model. The input is the original image data, and the output is a 768-dimensional image semantic description vector. The preprocessing procedure is the same as that of the ViT-base / 16 model.

[0022] Anchor point generation rules for different output formats: PDF format anchor point is a unique document identifier: actual page number: starting offset of character within the page - ending offset of character within the page; Word format anchor point is a unique document identifier: document page number: paragraph number: starting offset of character within the paragraph - ending offset of character within the paragraph; HTML format anchor point is a unique document identifier: element id: starting offset of character within the element - ending offset of character within the element; Markdown format anchor point is a unique document identifier: heading level number: paragraph number: starting offset of character within the paragraph - ending offset of character within the paragraph.

[0023] S302: Obtain the vector features of facts and images, and calculate cosine similarity to characterize the level of cross-modal alignment.

[0024] The vector features of facts were generated using the BERT-base-chinese pre-trained model. Text preprocessing employed the corresponding tokenizer of this model, with a maximum sequence length of 512, truncation from back to front, and padding with zeros. The vector features of images were generated using the ViT-base / 16 pre-trained model. Image preprocessing resized the image to 224×224 pixels, normalized pixel values ​​to the [0,1] interval, and then standardized using the mean [0.485, 0.456, 0.406] and standard deviation [0.229, 0.224, 0.225]. The cosine similarity calculation formula is: ; In the formula, The vector features are facts, with a dimension of 768; The vector features of the image have a dimension of 768; This represents the vector dot product operation; This represents L2 norm operations.

[0025] S303: Count the number of proven facts and the number of unproven facts to obtain the total number of facts, and calculate the credibility of the support completeness based on this, and introduce a zero-bias term to correct the division-by-zero error.

[0026] Facts are those with a semantic similarity of 0.7 or higher to at least one image, and whose content directly supports the core factual statement. When multiple images correspond to a single fact, the number of proven facts is counted as 1; when a single image corresponds to multiple facts, each fact that meets the criteria is counted as proven. Unproven facts are those that do not meet the above conditions. The total number of facts is calculated using the following formula: ; In the formula, The total number of facts; The number of proven facts; This represents the number of unproven facts. The formula for calculating credibility is: ; In the formula, To prevent the zero deviation term from being used, the value is set to 1e-8.

[0027] S304: The correlation degree is calculated by integrating the basic association and credibility of the cosine similarity representation.

[0028] The correlation degree is calculated using the following formula: ; In the formula, The correlation score is calculated by first linearly mapping the cosine similarity from [-1,1] to the interval [0,1], and then multiplying it by the confidence score to obtain the correlation score.

[0029] S401: Calculate the minimum recognition length under physiological limits based on the tangent operation of viewing distance and resolution angle, and calculate the minimum image area based on the detailed features of the original image.

[0030] Sight distance Based on the application scenario, the recommended viewing distance is 0.4 meters for desktop reading, 3.0 meters for projection display, and 0.3 meters for mobile terminals. This distance can be entered through configuration parameters. (Minimum resolvable angle of the human eye) Take 1 point, that is Curve. Key details of the original image. The YOLOv8 object detection model was used for identification. The detection categories included tick marks, data points, and text annotations. The minimum value of the width in pixels of all detection boxes was taken as the result. If no key details are detected, take 1% of the original image width in pixels as the threshold. The minimum identification length and minimum map area are calculated using the following formulas: ; ; ; ; In the formula, Minimum recognition length; , The minimum display width and height of the image; This represents the width in pixels of the original image. The aspect ratio of the original image, i.e. , The height in pixels of the original image; This represents the minimum area of ​​the graph.

[0031] S402: Based on the character width ratio, derive the single-line capacity limit of the slot, and combine it with the total number of characters and the spacing ratio to calculate the minimum character area.

[0032] Character width ratio Based on character type settings, Chinese characters and full-width punctuation are assigned a value of 1, while English characters and half-width punctuation are assigned a value of 0.5. Total character count. This is the sum of the width proportions of each character in the factual text. Font height. The font_size field in the template configuration is converted using S201. The default value is 0.0035 meters, and the value range is from 0.0028 meters to 0.007 meters. (Row height magnification) Take 1.2, the multiplier after the segment Let's take 0.5. The minimum character area is calculated using the following formula: ; ; ; ; In the formula, Width of a single character; This represents the maximum number of characters that a single line in the slot can hold. This indicates the floor function; The number of rows required for typesetting; This indicates the rounding up operation; This represents the minimum character area.

[0033] S403: Calculate the cross-page equivalent distance between the fact and the image center to obtain the anchor distance, and calculate the deviation between the logical and visual rankings to obtain the order difference.

[0034] The center coordinates of the facts and images are the geometric center of the corresponding slots, i.e. Usable area per page This is calculated by multiplying the total page width by the total height, then subtracting the margin area. The margins are obtained from the `margin` field configured in the template using an S201 conversion. Logical ranking. The ranking is determined by the order in which facts appear in the output data; facts that appear earlier are ranked first. (Visual ranking) Slots are sorted by their y-coordinate from smallest to largest; if y-coordinates are the same, they are sorted by their x-coordinate from smallest to largest. When spanning multiple pages, slots with smaller page numbers are ranked higher. The anchor distance and order difference are calculated using the following formula: ; ; In the formula, For anchorage distance; , The center coordinates of the corresponding slot; , The coordinates of the center of the corresponding slot in the image; , The page number where the facts and images are located; denoted by , where is the order difference; N is the total number of all evidence units.

[0035] S404: Combine the ratio of the minimum graph area and the minimum character area to the slot area with the penalty terms of relevance, anchor distance, and order difference to obtain the critical relevance.

[0036] The critical correlation degree is calculated using the following formula: ; In the formula, This represents the critical correlation degree.

[0037] S501: Construct the layout parameters into a normalized position vector and extract the group dispersion as the optimization inertia weight.

[0038] Layout parameter dimensions Each evidence unit corresponds to three dimensions: slot number dimension, character number allocation ratio dimension, and image scaling ratio dimension. The slot number dimension maps slot numbers from 1 to M to the interval [0,1], and the mapping formula is as follows: , where i is the slot number; the character allocation ratio dimension ranges from [0,1], representing the proportion of characters allocated to this fact relative to its original character count; the image scaling ratio dimension ranges from [0,1], representing the maximum allowed image scaling ratio. Total number of particles The value ranges from 50 to 200, with a default value of 100. For every additional 10 evidence units, Increase by 10. The calculation of the normalized position vector and the optimization inertia weight is achieved through the following formula: ; ; ; In the formula, Let p be the normalized position vector of the p-th particle in the t-th generation; Let be the population dispersion of the particle swarm in generation t; Let be the mean of the position vectors of all particles in generation t; Represents L2 norm operations; To find the optimal inertia weight.

[0039] Each component of the initial position vector is randomly generated using a uniform distribution within the interval [0,1]. For high-priority evidence units with a correlation degree greater than or equal to 0.8, the initial slot number dimension component is preferentially mapped to slots with an area greater than or equal to the average slot area. The formula for calculating the average slot area is as follows: M represents the total number of slots. The initial character count allocation ratio dimension component is set to 1.0 by default, and the initial image scaling ratio dimension component is also set to 1.0 by default.

[0040] S502: In the objective function, the fitness is obtained by fusing the weighted critical correlation degree and the parameter representing the excess beyond the physical boundary.

[0041] Position vector The implementation logic for the evidence unit-slot mapping is as follows: multiply the slot number dimension component corresponding to each evidence unit by... The assigned slot number is obtained by rounding. The default weights for both terms of the fitness function are 1. For academic reports, the critical correlation weight can be set to 1.2 and the overflow area weight to 0.8; for internal reports, the critical correlation weight can be set to 0.8 and the overflow area weight to 1.2. Fitness is calculated using the following formula: ; In the formula, For fitness; Let x be the critical correlation degree of the evidence unit u corresponding to the position vector x in slot s; The minimum area required for the evidence unit u, i.e. ; The area assigned to the evidence unit u by the position vector x; To obtain the positive operator, when If the difference is true, take the difference; otherwise, take 0.

[0042] S503: Based on the fitness distributions corresponding to the individual optimal state and the global optimal state, calculate the individual factor and the global factor used to control the optimization pace.

[0043] The calculation of individual factors and global factors is achieved through the following formulas: ; ; In the formula, Individual factors; As a global factor; Let be the individual optimal state vector of the p-th particle in the t-th generation, that is, the position vector with the minimum fitness in the history of this particle; Let be the global optimal state vector of the t-th generation particle swarm, that is, the position vector with the minimum fitness in the history of all particles. To prevent the zero deviation term from being used, the value is set to 1e-8.

[0044] S504: Update the velocity and position vectors based on individual factors, global factors, and optimization inertia weights, and map them to the discrete grid through the projection operator to eliminate out-of-bounds positions.

[0045] The discrete mesh uses a single-page partitioning method, with each page divided into a 20×20 grid. The physical dimensions of each grid are... The grid numbers are from 1 to 400, from left to right and top to bottom. Projection operator. The implementation logic is as follows: Each component of the position vector is rounded to the normalized coordinate corresponding to the nearest grid center; components less than 0 are truncated to 0, and components greater than 1 are truncated to 1. Initial velocity vector. Each component is randomly generated using a uniform distribution, with values ​​ranging from [-0.1, 0.1]. The velocity and position vectors are updated using the following formulas: ; ; In the formula, Let be the velocity vector of the p-th particle in the (t+1)-th generation; , It is a uniformly distributed random vector with values ​​ranging from [0,1]. This represents element-wise multiplication. Let p be the position vector of the p-th particle in the (t+1)-th generation; This is the projection operator.

[0046] S505: When the global optimal state converges, output the corresponding grid as the layout plan.

[0047] Convergence conditions include: the number of iterations reaches the preset maximum of 300; the global optimal fitness value shows no improvement for 30 consecutive iterations; and the standard deviation of the particle swarm fitness is less than 1e-6. When any convergence condition is met, the iteration terminates, and the discrete grid corresponding to the global optimal state vector is output as the final layout plan.

[0048] S601: Based on the display size and line height / character height attributes allocated to the facts according to the typesetting plan, the maximum number of characters is calculated by truncating and rounding.

[0049] The maximum number of lines and the maximum number of characters are calculated using the following formulas: ; ; In the formula, Maximum number of rows; The display height allocated to the facts in the layout plan; The display width allocated to the facts in the layout plan; The maximum character count is set as input. If the original fact text exceeds the maximum character count, a BART-based Chinese summarization model is used for simplification. Input the original fact text and the maximum character count, and output the simplified text that retains the core semantics. If the simplification still exceeds the maximum character count, a back-to-foreign truncation method is used, with the truncation position retaining the complete sentence.

[0050] S602: Compare the ratio of the size allocated to the image to the ratio of the original image size, select the ratio that makes the image maintain its original aspect ratio and not exceed the lower limit of the boundary as the image scaling ratio, and calculate the image output size accordingly.

[0051] The page pixel density (DPI) is set to 300, and the physical length to pixel conversion is 1 meter = 1 pixel. Pixels. The image scaling ratio and output size are calculated using the following formula: ; ; ; ; ; In the formula, , Assign the display width and height to the image according to the layout plan; , Assign pixel values ​​corresponding to the size; Image scaling ratio; , This defines the output width and height of the image.

[0052] S603: Concatenate the source set, facts, images, and captions sequentially and perform secure hash calculation to generate a binding identifier.

[0053] The source set is converted to a UTF-8 encoded JSON string, facts and captions are converted to UTF-8 encoded byte streams, and images are converted to PNG format binary data. The concatenation order is: source set JSON byte stream, fact text byte stream, image PNG byte stream, and caption text byte stream. The binding identifier is generated using the following formula: ; In the formula, For binding identifier; SHA256 is a byte stream concatenation operator; it is a secure hash algorithm 256 that generates a 256-bit hash value.

[0054] S604: Apply the maximum number of characters and image scaling ratio to limit the content generated by the image and text, and perform image and text layout.

[0055] The text uses justified alignment, with character spacing adjustable from 0.8 to 1.2 times the standard character spacing, and line spacing fixed. The image is horizontally and vertically centered in its assigned image slot, with a minimum distance of 0.001 meters between the image and the slot boundary. The caption is located below the image, spaced 0.002 meters from it, and the caption font height is [missing information]. Multiple evidence units within the same slot are arranged from top to bottom according to their logical ranking, with a unit spacing of 0.003 meters.

[0056] S701: Simultaneously renders the logic layer, which focuses on the machine's reading order, and the layout layer, which focuses on the two-dimensional page display.

[0057] The logic layer uses XML format, with the root node being... <report>,Include <metadata>and <content>Child nodes. <metadata>The node includes the report title, generation time, and total page count field; <content>The node contains multiple<evidence_unit> Child nodes, each<evidence_unit> The node contains id, text, image_path, caption, and logical_rank fields, with the id field storing the binding identifier. The layout layer uses PDF format, generated using the WeasyPrint library, embedding all used fonts, and the image uses lossless PNG compression with a resolution of 300 DPI. Synchronous rendering means that both rendering layers use the same processed content data and binding identifier.

[0058] In the logical layer XML, the `image_path` field specifies the relative storage path of the image within the report package, generated as `images / evidence_{u}.png`, where `u` is the evidence unit number. All image files are stored uniformly in the `images` directory of the report package, maintaining a relative path relationship with the XML file.

[0059] S702: Extract the coordinates of cross-layer content based on the binding identifier, divide by the page's length and width to perform normalization, and obtain the bounding box.

[0060] The PyMuPDF library is used to extract text and image bounding boxes from PDFs. During extraction, `text_flags=3` and `image_flags=1` are set to ensure complete content boundaries are extracted. The coordinate system of the logical layer is consistent with that of the layout layer, with the origin at the top left corner of the page, the x-axis pointing to the right, and the y-axis pointing downwards. The bounding boxes are calculated using the following formula: ; In the formula, The bounding box is the normalized value; F is the rendering layer identifier, with a value of text indicating the logic layer and a value of visual indicating the layout layer; , Let u be the coordinates of the top-left corner of the evidence unit in the rendering layer F; , The width and height of the evidence unit u in the rendering layer F; , This refers to the page width and height of the rendering layer F.

[0061] S703: Calculates the spatial intersection-union ratio of the overlapping bounding boxes in the logic layer and the layout layer to quantitatively characterize the physical overlap of the same content in different rendering layers.

[0062] The spatial intersection-union ratio is calculated using the following formula: ; In the formula, For spatial intersection-union ratio; For area calculation operators; The intersection operation represents the bounding boxes; This represents the union operation of bounding boxes.

[0063] S704: The individual error is obtained based on the spatial deviation and the logical deviation of the order difference based on the spatial intersection-union ratio, and the consistency loss is calculated by weighted fusion of correlation degree.

[0064] The consistency loss is calculated using the following formula: ; In the formula, This represents the consistency loss. When the consistency loss is less than 0.1, the consistency between the two layers is considered to meet the requirements.

[0065] S801: Calculate the deformation rate by comparing the absolute difference between the aspect ratio of the output image and the original aspect ratio to eliminate stretching distortion.

[0066] The rate of deformation is calculated using the following formula: ; In the formula, denoted as the deformation rate.

[0067] S802: Calculate the detail margin by comparing the positive deviation between the output detail size and the physiological resolution limit, in order to eliminate arrangements that are below the visually recognizable threshold.

[0068] The physical length of the output detail size is calculated by dividing the number of output detail pixels by the number of pixels per meter, where the number of pixels per meter is... The margin of detail is calculated using the following formula: ; In the formula, For detail margin.

[0069] S803: The approval rating is calculated by summing the number of proven facts within the president's plan out of the total number of facts.

[0070] Support rate is calculated using the following formula: ; In the formula, For support rate.

[0071] S804: When the deformation rate is zero, the detail margin meets the lower limit requirement, and the support rate after cleaning up the content corresponding to the unproven facts meets the anti-fictitiousness standard, the audit is deemed to have passed and the report is packaged and output.

[0072] The audit passes under the following conditions: all images have a distortion rate of 0; all images have a detail margin greater than or equal to 1; and the support rate after cleaning up unproven facts is greater than or equal to 0.9. The unproven fact cleaning method involves traversing all evidence units, deleting the text and images corresponding to unproven facts, and retaining proven facts. After cleaning, the minimum character area and minimum image area of ​​the remaining content are recalculated, triggering swarm optimization to regenerate the layout plan. If the audit fails, the process returns to the swarm optimization step, increasing the total number of particles by 20 and the maximum number of iterations by 100, with a maximum of 3 retries. If it still fails after 3 retries, a log file containing the error type and corresponding parameters is output. After the audit passes, the formatted content is packaged into reports in PDF, Word, and HTML formats and output to a specified path.

[0073] The multi-format report packaging is implemented using separate tools: PDF format is generated using the WeasyPrint library, preserving all layout styles and image resolutions; Word format is generated using the python-docx library, converting the formatted text and images into native Word elements; HTML format is rendered using the Jinja2 template engine, generating responsive HTML pages, with images embedded or referenced from local files using base64 encoding. The report package is in ZIP compressed format and contains the main report file, an images directory, and metadata files.

[0074] The embodiments of this example have been described above. However, this example is not limited to the specific implementation methods described above. The specific implementation methods described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms based on the guidance of this example, and all of them are within the protection scope of this example.< / content> < / metadata> < / content> < / metadata> < / report>

Claims

1. A method for fast generation of AI multi-format report based on template configuration, applied to a report system comprising a logic layer and a layout layer, characterized in that, include: The template configuration is parsed to construct a constraint graph and slots representing the location topology, thus establishing the physical boundaries within the page; Facts are extracted from the output data and bound to images to generate evidence units bound to source features and the degree of relevance representing the semantic dependency relationship between images and text; The minimum image area that ensures visual recognition and the minimum character area that ensures character readability are calculated by the evidence unit. The anchor distance that eliminates page scale interference and the order difference that represents reading misalignment are combined to obtain the critical correlation degree used to evaluate the limit of spatial adaptation. A fitness factor is constructed to evaluate the feasibility of layout based on the critical correlation degree and the overflow area beyond the physical boundary, and swarm intelligence optimization is performed to determine the layout plan within the discrete grid. Based on the maximum number of characters allocated by the typesetting plan to eliminate character overflow and the image scaling ratio to maintain the original aspect ratio, the text and image layout is performed to generate binding identifiers that constrain cross-layer homology. Based on the binding identifier, the logic layer and the layout layer are rendered synchronously, and the bounding box is extracted to calculate the consistency loss of the spatial deviation between the layers. An anti-distortion audit is performed based on the deformation rate (characterizing the degree of deformation), the detail margin (characterizing the degree of resolution deviation), and the support rate (characterizing the level of objective support). A report is generated after the audit is passed.

2. The template-based configuration AI multi-format report quick generation method according to claim 1, characterized in that, The parsing template is configured to construct a constraint graph and slots representing the location topology, including: Extract the layout point value and Cascading Style Sheet pixels, and convert them into a uniform physical length to eliminate cross-device scale interference; Extract the slot coordinates, slot size, and semantic tags configured in the template; multiply the length and width of the slot size to obtain the slot area representing the physical capacity limit; and construct the slot. The adjacency, inclusion, reading order, or non-overlapping relationships between the slots within the available page number are analyzed to establish the constraint diagram characterizing the anti-collision conditions between slots.

3. The template-based configuration AI multi-format report quick generation method according to claim 2, characterized in that, The generated evidence units bound to source tracing features and the degree of correlation representing the semantic dependency relationship between text and images include: The facts and their corresponding images, captions, anchors, and source sets are combined to form the evidence unit with independent tracing attributes; Obtain the vector features of the facts and the image, and calculate the cosine similarity to characterize the cross-modal alignment level; The total number of facts is obtained by counting the number of proven facts and the number of unproven facts. Based on this, the credibility reflecting the completeness of the support is calculated, and a zero-bias term is introduced to correct the division-by-zero error. The correlation degree is calculated by integrating the basic association represented by the cosine similarity with the credibility.

4. The template-based configuration AI multi-format report quick generation method according to claim 3, characterized in that, The determination of the critical correlation degree used to evaluate the spatial fit limit includes: The minimum recognition length under physiological limits is obtained by calculating the tangent of viewing distance and resolution angle, and the minimum image area is obtained by converting the original image details. The single-line capacity limit of the slot is derived based on the character width ratio, and the minimum character area is obtained by combining the total number of characters and the spacing ratio. The anchoring distance is obtained by calculating the cross-page equivalent distance between the fact and the center of the image, and the order difference is obtained by calculating the deviation between the logical and visual rankings. The critical correlation degree is obtained by combining the ratio of the minimum image area and the minimum character area to the slot area with the correlation degree, the anchor distance, and the penalty term of the order difference.

5. The method for rapid generation of AI multi-format reports based on template configuration according to claim 4, characterized in that, The process of performing swarm intelligence optimization to determine the layout plan within the discrete grid includes: The layout parameters are constructed as normalized position vectors, and the group dispersion is extracted as the optimization inertia weight. In the objective function, the fitness is obtained by fusing the weighted critical correlation degree and the excess parameter that represents the physical boundary. Based on the fitness distributions corresponding to the individual optimal state and the global optimal state, the individual factor and the global factor used to control the optimization pace are calculated respectively. The velocity and position vectors are updated based on the individual factors, the global factors, and the optimization inertia weights, and then mapped to the discrete grid using a projection operator to eliminate out-of-bounds positions. When the global optimal state converges, the corresponding grid is output as the layout plan.

6. The method for rapid generation of AI multi-format reports based on template configuration according to claim 5, characterized in that, The process of generating binding identifiers for cross-layer homology constraints and performing graphic layout includes: Based on the display size and line height / character height attributes allocated to the fact in the layout plan, the maximum number of characters is obtained by truncating and rounding. By comparing the size allocated to the image with the ratio limit of the original image size, the ratio that makes the image maintain its original aspect ratio and does not exceed the lower limit of the boundary is selected as the image scaling ratio, and the image output size is calculated accordingly. The source set, the facts, the image, and the caption are sequentially concatenated and a secure hash calculation is performed to generate the binding identifier; The maximum number of characters and the image scaling ratio are used to limit the content of the generated text and images, and the text and images layout is executed.

7. The method for rapid generation of AI multi-format reports based on template configuration according to claim 6, characterized in that, The process of extracting bounding boxes and calculating the consistency loss of quantized inter-layer spatial deviation includes: The logic layer, which focuses on the machine's reading order, and the layout layer, which focuses on the two-dimensional page display, are rendered synchronously. Based on the binding identifier, extract the cross-layer content coordinates, divide them by the length and width dimensions of the page to perform normalization, and obtain the bounding box; Calculate the spatial intersection-union ratio of the bounding boxes that overlap in the logical layer and the layout layer to quantitatively characterize the physical overlap of the same content in different rendering layers; The individual error is obtained based on the spatial deviation of the spatial intersection-union ratio and the logical deviation of the order difference, and the consistency loss is calculated by weighted fusion of the correlation degree.

8. The method for rapid generation of AI multi-format reports based on template configuration according to claim 7, characterized in that, The distortion prevention audit is performed based on the deformation rate (characterizing the degree of deformation), the detail margin (characterizing the degree of resolution deviation), and the support rate (characterizing the level of objective support). This includes: The deformation rate is calculated by comparing the absolute difference between the ratio of the output image size and the original aspect ratio to eliminate stretching distortion. The detail margin is calculated by comparing the positive deviation between the output size of the detail and the physiological resolution limit, so as to eliminate the arrangement below the visually recognizable threshold. The approval rating is calculated by the proportion of the number of proven facts described in the president's plan to the total number of said facts. When the deformation rate is zero, the detail margin meets the lower limit requirement, and the support rate after cleaning up the content corresponding to the number of unproven facts meets the anti-fiction generation standard, the audit is deemed to have passed and the report is packaged and output.