A multi-format document cross-language parsing and automatic modification method for digital transformation

CN123013855APending Publication Date: 2026-10-30CHENGDU NIUDEDE NETWORK TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611122186.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-28
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

这种方式不仅效率低下,无法满足海量文档的批量处理需求,而且容易引入人为误差,导致转换后的文档与原始文档在视觉结构上产生较大偏差

Benefits of technology

1、本发明通过构建文档结构树和约束建模,实现对文档元素间空间拓扑关联的精准维护。在跨语言转换过程中,系统能够自动识别并锁定元素间的相对位置,确保翻译后的文档在视觉结构上与原始文档达到高度一致。特别是在处理包含复杂图文压盖关系和精密表格结构的文档时,本发明通过弹性容器模型和边界硬约束,彻底消除传统回填方式中频发的文本溢出容器、覆盖关键图元以及表格错位等排版故障,保证文档的高保真还原。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123013855A_ABST
    Figure CN123013855A_ABST
Patent Text Reader

Abstract

The application discloses a multi-format document cross-language parsing and automatic modification method for digital transformation, and belongs to the technical field of computer document parsing. By constructing a document structure tree and an elastic container model, combining neural machine translation and space occupation estimation, a cascading adjustment mechanism is started when the translation text exceeds the boundary, boundary reconstruction of interval compression, font scaling and topology moving is sequentially executed, and finally raster rendering is completed. The application can automatically adapt to cross-language text length changes, realize page self-repairing under the premise of maintaining the original document visual structure, and is suitable for high-fidelity cross-language conversion of massive multi-format documents. The application can automatically adapt to cross-language text length changes, realize page self-repairing under the premise of maintaining the original document visual topology structure, effectively solve the problems of text overflow, graphic element coverage and table misplacement, and is suitable for high-fidelity cross-language conversion of massive multi-format documents.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of computer document parsing technology, specifically involving a method for cross-language parsing and automated modification of multi-format documents for digital transformation. Background Technology

[0002] As global enterprises deepen their digital transformation, the demand for cross-language translation of various technical manuals, design documents, and contracts is growing. Existing document processing systems typically employ a simple parsing, translation, and backfilling logic for cross-language translation: extracting text content from the source document, translating it by machine, and then directly filling it into the original pre-defined layout container. However, significant length expansion or contraction characteristics exist between different languages. For example, German text with the same semantic meaning is usually significantly longer than Chinese text, causing the translation to often exceed the capacity of the original container. This leads to a series of layout errors, such as text overflowing boundaries, overlapping with surrounding graphic elements, and disordered table structures.

[0003] To address these issues, traditional methods rely on manual intervention, adjusting font size and line spacing page by page or manually reconstructing the layout. This approach is not only inefficient and unable to meet the demands of batch processing massive amounts of documents, but it is also prone to introducing human error, resulting in significant visual structural discrepancies between the converted and original documents. Furthermore, existing document parsing models struggle to accurately extract and maintain the spatial topological relationships between elements, such as the relative positions of text blocks and illustrations, and the proportional relationships between table cells. This lack of constraint on overall layout consistency during the layout correction process further exacerbates the resulting layout inconsistencies.

[0004] Therefore, there is an urgent need for a document processing method that can automatically adapt to changes in cross-language text length and achieve self-repair of the layout while maintaining the original document's visual topology, in order to support the need for efficient and high-fidelity cross-language document conversion during enterprise digital transformation. Summary of the Invention

[0005] The purpose of this invention is to provide a method for cross-language parsing and automated modification of multi-format documents for digital transformation, which can effectively solve the problems mentioned in the background art.

[0006] To achieve the above objectives, the technical solution adopted by the present invention is as follows: A method for cross-language parsing and automated modification of multi-format documents for digital transformation includes the following steps: Step S1: Obtain the document structure tree generated after the input document is parsed by multimodal analysis. Each node in the document structure tree corresponds to a document element and records the geometric position, topological association and font rendering attributes of the element. Step S2: Construct a flexible container model for each text element node in the document structure tree, and define a set of constraints for each flexible container model, including relative distance constraints, hard boundary constraints, and proportion preservation constraints. Step S3: Call the neural machine translation engine optimized with industry corpus to convert the source language text into the target language text, and calculate the estimated space occupancy of the target language text under the current typesetting parameters through the space occupancy prediction model. Step S4: When it is determined that the estimated space occupancy exceeds the boundary hard constraint of the elastic container model, a cascaded adjustment mechanism is activated. The cascaded adjustment mechanism executes three adjustment levels in sequence according to the order of the overall visual impact on the document from small to large: spacing compression, font size scaling, and boundary reconstruction based on topological shift, until the estimated space occupancy meets the boundary hard constraint or all levels are completed. After the cascading adjustment mechanism is executed, based on the final layout parameters determined after adjustment, the rasterization rendering of all elements on the page is completed in memory to generate the final document page.

[0007] Furthermore, obtaining the document structure tree in step S1 specifically includes: The geometric topology parsing engine is invoked to perform binary stream analysis on the input document, identifying and classifying text blocks, background images, vector graphics, and table cell elements within the document. The layout analysis model based on deep learning is used to extract multi-scale features from the document page image to identify and locate the header area, footer area, sidebar area, text flow area and floating primitives. The layout analysis model adopts a two-stage target detection architecture that combines convolutional neural network and feature pyramid network. For each identified element, its starting horizontal axis coordinate, starting vertical axis coordinate, width, and height are accurately recorded in a unified two-dimensional coordinate system. The element hierarchy topology construction module identifies and extracts the parent-child nesting relationship and sibling adjacency relationship between elements, and determines the overlapping relationship between elements based on the preset overlap area threshold and the distance to the center point, generating layer order markers.

[0008] Furthermore, the constraint set in step S2 specifically includes: The relative distance constraint is used to define the minimum gap threshold between two adjacent geometric entities to force the maintenance of this minimum gap during layout adjustments. The boundary hard constraint is used to define the absolute boundary that the elastic container cannot cross when it is stretched vertically or expanded horizontally. The absolute boundary is derived from the physical margin of the page, the preset column boundary, and the position of specific graphic elements marked as immovable. The proportional constraint is used to force the width of the current cell to remain constant in proportion to the width of adjacent columns in the same table when vertical stretching is triggered due to internal text overflow in a table cell.

[0009] Furthermore, the space occupancy estimation model in step S3 calculates the estimated space occupancy using the following formula:

[0010] in, Represents the estimated space occupancy. This represents the total number of characters in the target language text string. The first in the target language The theoretical character width of a character at a standard font size. Represents the font size scaling factor. The increment represents the character spacing adjustment. This represents the buffer space margin pre-set based on the length expansion characteristics of the target language; The method further includes: determining a maximum allowable size, the maximum allowable size being determined based on the boundary hard constraint; and calculating the maximum allowable size... The value is compared with the maximum allowable size. If If the value is greater than the maximum allowable size, it is determined that there is a risk of layout overflow, and the overflow direction and overflow amount are recorded.

[0011] Furthermore, the first stage of the cascaded adjustment mechanism is spacing compression, specifically including: Read the initial value of the row height multiple set in the current elastic container model, compress the row height multiple gradually towards the preset lower threshold according to the preset compression step size, and call the space occupancy estimation model again after each compression step to determine whether the overflow has been eliminated; If the overflow is not eliminated after the line is compressed to the lower limit threshold, the word spacing adjustment increment will be slightly compensated from the current value in the negative direction until the preset minimum allowable value is reached. During the spacing compression process, the real-time text overlap detection module analyzes the horizontal overlap ratio of adjacent character bounding boxes within the same line and the vertical overlap ratio of character bounding boxes between adjacent lines. When any overlap ratio exceeds the preset safety threshold, further compression in the current direction is immediately stopped.

[0012] Furthermore, the second level of adjustment in the cascaded adjustment mechanism is font size scaling, specifically including: Start the font size reduction program, starting from the initial preset font size and gradually reducing the font size scaling factor with a preset step size; During the font size scaling process, an integrated stroke clarity detection module is used. For each character glyph to be rendered, the stroke clarity detection module extracts its rasterized bitmap data at the target font size, extracts the outline of the character strokes through the Canny edge detection algorithm, and calculates the average pixel width of the main stroke area. When the average pixel width is lower than the preset minimum stroke width threshold, it is determined that continuing to reduce the font size will cause the strokes to break or become blurry. The scaling process is then immediately stopped and the current font size scaling factor is locked to the limit value of this adjustment.

[0013] Furthermore, the third level of regulation in the cascaded regulation mechanism is boundary reconstruction based on topological shift, specifically including: Identify the current text block affected by the overflow, and query all its vertically related sibling or parent-child elements from the document structure tree to form a set of nodes affected by the association. The problem of determining the displacement of the set of nodes affected by the association is modeled as a linear programming problem, with the objective function set as minimizing the increase in the total page height; The objective function of the linear programming problem is:

[0014] in, This represents the change in the total height of the page. Represents the set of nodes affected by association. Representing the Translation vector of each node, Representing the Constraint weights of the region where each node is located; The linear programming problem is solved using the simplex method to obtain the optimal translation amount for each node in the set. Based on this optimal translation amount, the geometric position of the affected nodes is updated. The document structure tree is recursively traversed, and the relative coordinates of the child nodes inside all affected elements are updated synchronously.

[0015] Furthermore, it also includes quality control steps: The generated final document page and the original document page are rendered as bitmap images of the same resolution; Perform a perceptual hashing algorithm on each bitmap image: scale the image to a fixed size and convert it into a grayscale single-channel image, perform a discrete cosine transform on the grayscale image, extract multiple low-frequency coefficients in the upper left corner region of the transformed matrix, traverse these coefficients, mark the bits with coefficient values ​​greater than the mean of the coefficients as 1, and mark the bits with values ​​less than or equal to the mean as 0, thereby generating a binary hash fingerprint. Calculate the Hamming distance between the original page fingerprint and the modified page fingerprint, and use this Hamming distance as a measure of visual similarity; If the calculated Hamming distance is greater than the preset threshold, the page layout change is determined to have failed quality monitoring. The page's processing status is marked as a manual intervention suggestion, and a difference report is generated, highlighting the image blocks with larger Hamming distances.

[0016] Furthermore, the multimodal parsing process in step S1 also includes the logic for extracting and replacing embedded fonts: When the target language does not support the original font encoding used in the source document, it automatically retrieves and matches the closest alternative font in visual style from the preset open-source font library. The matching dimensions include whether it is a serif or sans-serif font and the thickness of the font strokes. After the font replacement is completed, the font measurement parameters of the new font are read. The font measurement parameters include the ascending part value, the descending part value and the line spacing value. Based on these measurement parameters, the logical space occupied by each character in the current standard typesetting environment is recalculated.

[0017] Furthermore, the method performs batch parallel processing on massive documents, and the total time for parsing, translation estimation, and layout adjustment of a single page is strictly controlled within a preset time threshold of 500 milliseconds. The input document format includes portable document format and word processing document format, and the word processing document format includes DOCX format and RTF format; The neural machine translation engine uses the Transformer architecture as the basic sequence-to-sequence model. Its training process includes a general domain pre-training stage using a general bilingual corpus, and a domain-adaptive fine-tuning stage using a specific industry domain fine-tuning dataset.

[0018] In summary, this application includes at least one of the following beneficial technical effects: 1. This invention achieves precise maintenance of spatial topological relationships between document elements by constructing a document structure tree and constraint modeling. During cross-language conversion, the system can automatically identify and lock the relative positions between elements, ensuring that the translated document is highly consistent with the original document in terms of visual structure. Especially when dealing with documents containing complex text-image overlapping relationships and precise table structures, this invention completely eliminates the layout faults frequently occurring in traditional backfilling methods, such as text overflow containers, coverage of key graphic elements, and table misalignment, through flexible container models and hard boundary constraints, ensuring high-fidelity document restoration.

[0019] 2. This invention introduces a cascading layout adaptive adjustment mechanism. Through an orderly combination of spacing compression, font size scaling, and topology shifting, it completely eliminates the need for manual intervention in the layout correction process. Compared to the inefficient traditional method that relies on manual post-processing and page-by-page layout adjustments, this invention enables the rapid processing of massive amounts of multi-format digital documents. This method allows for controlling the layout correction time for a single page within an extremely short time threshold, significantly improving processing efficiency and greatly reducing the human and time costs of document processing for enterprises during digital transformation.

[0020] 3. For target languages ​​where the character length is significantly longer than the source language, this invention utilizes semantic translation and space occupancy prediction technologies to proactively detect layout conflict risks. A cascading adjustment mechanism provides multi-level tolerance; when simple spacing and font size adjustments fail to meet space requirements, the system can dynamically expand container capacity by reconstructing boundaries and topology, without compromising the document's logical aesthetics. This dynamic adaptive capability enables this invention to handle mutual translation and typesetting tasks between various mainstream languages ​​worldwide, resolving the technical challenges caused by inconsistent character lengths.

[0021] 4. This invention strictly adheres to geometric coordinate calculations during the processing and utilizes mathematical modeling methods to handle the constraints between elements, avoiding uncertainties introduced by evaluative intervention. Through fine-grained, step-by-step adjustments to text font size and line spacing, it ensures that the adjusted document maintains good readability. Simultaneously, the topology-based reconstruction algorithm enables cascading updates to affected areas of the page, ensuring logical consistency and accuracy when adjusting long documents across pages and paragraphs, significantly reducing the typesetting error rate introduced by human intervention. Attached Figure Description

[0022] Figure 1 A flowchart illustrating a method for cross-language parsing and automated modification of multi-format documents for digital transformation. Figure 2 A flowchart illustrating the logic of multimodal analysis and constraint modeling; Figure 3 A flowchart illustrating the logic of semantic translation and space occupancy estimation; Figure 4 The logic flowchart for the cascaded adjustment mechanism for adaptive layout adjustment. Detailed Implementation

[0023] To make the objectives, technical solutions, and advantages of this invention clearer, the following description is provided in conjunction with the appendix. Figure 1 To be continued Figure 4 The present invention will be further described in detail below with reference to specific embodiments.

[0024] In this embodiment of the method for cross-language parsing and automated modification of multi-format documents for digital transformation, the following steps are followed: The first step, S1, is the multimodal parsing process. This transforms input documents with varying formats and complex layouts into a structured document structure tree containing element geometric positions, topological relationships, and font rendering attributes. Driven by a geometric topology parsing engine, this process starts with underlying binary data flow analysis and combines it with a deep learning-based layout analysis model to accurately identify, classify, and lock spatial relationships of all visual elements within the document. Through this step, the originally disordered flow of page pixels or objects is abstracted into a digital information model that can be efficiently queried and constrained by computer programs. The specific implementation process of step S1 is described step by step below: Step S101 involves performing a full scan and low-level feature extraction on the input digitized document using a geometric topology parsing engine. The input digitized document types include portable document formats like PDF and various word processing document formats, such as DOCX and RTF. During this process, the parsing engine first performs low-level binary stream analysis on the document.

[0025] In step S102, for portable document formats like PDF, the system performs in-depth analysis of its internal cross-reference table XRefTable and object stream data structure to reconstruct the document's logical object graph. For word processing document formats, the system deconstructs its internal XML schema file to extract key information such as style definitions and content relationship files.

[0026] Based on the binary stream analysis, the system identifies and classifies all elements contained in the document, including at least text blocks, background images, vector graphics, table cells, and various annotation information.

[0027] In step S103, the geometric topology analysis engine invokes a deep learning-based page layout analysis model. This model employs a two-stage object detection architecture combining a convolutional neural network (CNN) and a feature pyramid network (FPN) to extract and fuse visual features of unstructured document page images at multiple scales.

[0028] The backbone network of the model is responsible for extracting basic visual features, while the feature pyramid network builds multi-level feature maps on this basis to ensure accurate recognition of both large page areas such as the main text area and small elements such as header and footer text. Specifically, the model is trained to recognize and locate header areas, footer areas, sidebar areas, main text flow areas, and floating primitives in a document.

[0029] Step S104, regarding the training method of the above layout analysis model, is explained in detail below. The process of constructing the training dataset includes: collecting multi-format document pages covering various layout styles such as technical manuals, academic papers, and commercial contracts, and uniformly rendering them into high-resolution images.

[0030] These images were manually annotated with detailed information, including category labels for each page element, headers, footers, body paragraphs, tables, illustrations, and the coordinates of their corresponding minimum bounding rectangles.

[0031] To further enhance the model's generalization ability and robustness, data augmentation strategies were implemented on the image data during the training phase. Specific operations included random cropping, geometric affine transformation, color space perturbation, and overlaying noise layers in blank areas of the page. The loss function used during training was a multi-task loss function, the mathematical expression of which is:

[0032] in, This represents the total loss value during model training. The loss value representing the classification task is calculated using the focus loss function to alleviate the problem of imbalance in the categories of elements on the page. The loss value representing the bounding box regression task is calculated using the smoothed L1 loss function and is used to optimize the coordinate deviation between the predicted bounding box and the ground truth bounding box. It is a balancing factor used to adjust the relative weights of classification loss and regression loss in the total loss, and is set to 1 in this embodiment.

[0033] The goal of training is to iteratively update the model parameters using the backpropagation algorithm and the gradient descent optimizer to minimize the total loss. Ultimately, this enables the model to accurately predict the spatial location and coverage of various layout elements for any input document image.

[0034] In step S105, for each element identified and located by the layout analysis model, the system accurately records its geometric attributes in a unified two-dimensional coordinate system. This coordinate system has its origin at the bottom left corner of the page. The geometric attributes recorded by the system specifically include the element's starting horizontal axis coordinate, starting vertical axis coordinate, width, and height. This coordinate recording process not only captures the element's independent physical boundaries but also provides fundamental data for subsequent topological relationship calculations.

[0035] In step S106, after obtaining the coordinate information of all independent elements, the system further identifies and extracts the spatial topological relationships between elements through an element-level topology construction module. These relationships specifically cover parent-child nesting relationships and sibling adjacency relationships between elements.

[0036] A typical example of parent-child nesting is the subordinate and boundary constraint relationship between a table cell and the text paragraph it contains; sibling adjacency describes the adjacent state of two paragraphs or text and illustrations at the same level on a two-dimensional plane.

[0037] In step S107, to construct a robust document structure tree, the system iterates through and calculates a preset overlap area threshold and the distance between the center points of any two elements. If the overlap area between the bounding boxes of any two elements exceeds a predetermined proportion, such as the overlapping area occupying 30% of the area of ​​the smaller element, or the Euclidean distance between their center points is less than a specific pixel threshold, such as 5 pixels, the system will determine their overlapping relationship based on their layer attributes.

[0038] The system meticulously records the overlay logic between text elements and the background image, generating a layer order Z-Index accordingly. This mechanism ensures that in any subsequent layout adjustments, the text content always remains on top of the background layer, and the visual integrity of the background layer is not compromised.

[0039] Step S108, the multimodal parsing process also includes the logic for extracting and replacing embedded fonts in the document. When the target language does not support the original font encoding used in the source document, such as when converting from Chinese to Arabic or German, the system will automatically search and match from a preset open-source font library.

[0040] The matching process is based on finding the closest visual style alternative font. Comparison dimensions include whether it's a serif or sans-serif font, and the thickness of its strokes. After the font replacement is complete, the system reads the new font's font metrics, specifically the ascent, descent, and leading values. Based on these metrics, the system recalculates the logical space occupied by each character in the current standard typography environment.

[0041] In step S109, all the parsing results, extracted feature parameters, and their associated weights in subsequent calculations generated in the preceding steps are structurally stored in an in-memory database. This data is organized as a complete document structure tree. Within this structure tree, the reference relationships between nodes are indexed using a hash mapping method.

[0042] This design ensures that the system can complete attribute queries and real-time updates of node status with extremely high efficiency in processing large-scale, massive documents.

[0043] In summary, step S1 completes a comprehensive analysis of the input document, from the underlying byte stream to the high-level semantic structure. At this point, the originally complex and fixed-layout static document has been successfully mapped into a document structure tree containing precise element coordinates, hierarchical nesting relationships, overlay logic, and font rendering metrics. This structure tree not only faithfully reflects the visual topology of the original document, but more importantly, it makes the implicit typographic constraints explicit and digitized.

[0044] This information will be passed as direct input to the next processing stage, enabling the system to build a flexible container model for each text element for subsequent layout adaptive calculations, thus entering the constraint modeling process in step S2.

[0045] In the above method, step S2 is the constraint modeling process, following the document structure tree generated in step S1. Its core purpose is to abstract the spatial container of each text element in the document and its interaction with surrounding elements into a mathematical model that can be processed by a computer. By establishing a flexible container model for each text element and constructing a set of constraints around this model, including relative distance constraints, hard boundary constraints, and proportion-preserving constraints, the system provides clear constraint boundaries and calculation basis for the prediction of translation space occupancy in subsequent step S3 and the cascading layout adjustment in step S4. The specific implementation process of step S2 is described step by step below.

[0046] In step S201, the system traverses the document structure tree generated in step S1 and extracts each node marked as text. For each text element node, the system reads its starting horizontal axis coordinate, starting vertical axis coordinate, width, and height values ​​recorded in the document structure tree.

[0047] In step S202, based on the initial geometric bounding box described above, the system further abstracts it into a flexible container model. This flexible container model is defined as a geometric entity with highly dynamic scaling characteristics. Its basic properties not only include the original boundary parameters determined in step S201, namely the absolute coordinate values ​​in the four directions of the top, bottom, left, and right boundaries, but also additionally integrate the internal padding parameter Padding. The Padding parameter is used to define the flow boundary of the text content within the container, determining the size of the blank area reserved between the text and the container border.

[0048] In step S203, the flexible container model also records the text layout attributes. These attributes include the text flow direction, such as a horizontal writing direction from left to right or a writing direction from right to left, and the text alignment within the container, such as center alignment, left alignment, or justified alignment.

[0049] In step S204, after establishing a flexible container model for each text element, the system enters the stage of defining and binding constraint relationships. The system uses mathematical modeling to lock the logical positional relationship of each flexible container within the page and defines a set of constraints accordingly. This set of constraints consists of three types of constraints: relative distance constraints, hard boundary constraints, and proportion preservation constraints.

[0050] Step S205: The first type of constraint is a relative distance constraint. The process of establishing this constraint is as follows: The system identifies two elements in the document structure tree that have an adjacent relationship, such as two text paragraphs arranged vertically, or a text paragraph and an illustration arranged horizontally. The system calculates the shortest Euclidean distance between the geometric entities of these two elements and defines a preset minimum gap threshold for them.

[0051] During subsequent adaptive layout adjustments, this constraint will enforce that the spacing between these two elements must not be less than the minimum gap threshold, thus ensuring that elements do not visually overlap or overlap. For example, if a text paragraph extends downwards due to the length of the translation, the relative distance constraint will force the image below it to move downwards synchronously to maintain the preset minimum gap between them.

[0052] Step S206: The second type of constraint is a hard boundary constraint. This constraint defines the absolute boundary that the elastic container cannot cross when stretched vertically or expanded horizontally. Specific sources of these hard constraints include: the physical margins of the page, i.e., the boundary lines of the white space around the document page; preset column boundaries, such as the left and right dividing lines of each column in a column layout; and specific graphic element locations that are pre-marked by the user as immovable, such as the area containing a fixed company logo or page number on the page.

[0053] Step S207: The third type of constraint is the proportion preservation constraint, which is specifically invoked when processing documents containing table structures. When table nodes exist in the document's structure tree, the system identifies the set of cells belonging to the same table.

[0054] For these table cells, when the text inside them is stretched vertically in the height direction due to translation overflow, a proportion-preserving constraint will be activated. This constraint will force the current cell to maintain a constant aspect ratio with the width of adjacent columns in the same table, or to maintain a width-to-height ratio consistent with a preset value, even as the height changes.

[0055] In step S208, after the above three types of constraints are bound to each elastic container model instance, the system will update these constraints along with the container parameters to the document structure tree in the in-memory database.

[0056] In summary, through the flexible container model and multi-type constraint set constructed in step S2, this method successfully transforms the implicit, visual experience-based layout rules in the original document into a series of explicit and quantifiable mathematical constraints.

[0057] These constraints provide a basis for decision-making in subsequent processing stages: in step S3, the system will determine whether there is a risk of overflow in the translation based on the boundary hard constraints of these containers; and in step S4, each operation of the cascading adjustment mechanism—whether it is compressing the spacing, scaling the font size, or shifting the topology—must be solved and executed within the constraint framework defined here.

[0058] Therefore, step S2 forms a key bridge connecting static document parsing and dynamic adaptive adjustment, making automated layout repair possible.

[0059] In the above method, regarding step S3, the semantic translation and prediction process, there are two core tasks: first, to accurately convert the source language text into the target language text; second, to pre-calculate the space required under the current layout settings before filling the document container with the translated text. By calling a neural machine translation engine optimized with industry-specific corpora and combining it with a space occupancy prediction model based on character width accumulation, the system can accurately perceive potential overflow risks before the actual layout changes, providing a quantitative trigger basis for the cascading adaptive adjustment in step S4. The specific implementation process of step S3 is described step by step below.

[0060] In step S301, the system invokes a context-aware neural machine translation (NMT) engine. This engine is not a general-purpose translation tool, but rather specifically optimized for technical manuals and professional documents in particular industry sectors. The system receives the source language text fragment corresponding to the elastic container model from step S2 as input and initiates the translation process.

[0061] In step S302, during the translation process, the NMT engine first performs terminology recognition and alignment on the input text. The system has built-in multiple industry terminology databases, covering professional fields such as power systems, mechanical manufacturing, and legal contracts. When professional terms matching the terminology database appear in the source text, the engine will prioritize using the preset target language standard translation from the terminology database, rather than relying on general word-by-word translation, thereby ensuring the accuracy and consistency of the translation of key concepts in professional documents.

[0062] For example, in power industry documents, "busbar" will be consistently translated as "bus line" rather than the more common "bus railing" in the terminology database.

[0063] Step S303, regarding the specific training method of the aforementioned NMT engine, is further elaborated as follows. This engine uses the Transformer architecture as its basic sequence-to-sequence model. The training dataset is constructed as follows: a massive amount of bilingual parallel corpora are collected, with sources including publicly available technical document translation memories, multilingual patent literature databases, and internal bilingual technical manuals from enterprises.

[0064] For specific industries, sentence pairs belonging to the relevant technical fields are selected and labeled from the above corpus to form a domain-specific fine-tuning dataset. The training process consists of two stages: the first stage is general domain pre-training, which uses a large-scale general bilingual corpus to train the model, enabling it to master basic bilingual mapping capabilities and language model knowledge; the second stage is domain-adaptive fine-tuning, which uses the aforementioned domain-specific fine-tuning dataset to adjust the parameters of the pre-trained model, allowing the model to fully learn the terminology habits and sentence structures of the specific industry.

[0065] The loss function used for training is the cross-entropy loss function, whose mathematical expression is: ,in, This represents the loss value during the NMT engine training process. The total length of the target language sequence. For the first The true target vocabulary at any given moment Representing the The partial target language sequence generated before time 1. The input is a sequence of source language characters. This represents the probability that the model predicts the true word at the current moment.

[0066] The goal of training is to iteratively adjust the model parameters through an optimization algorithm to minimize the loss value. Ultimately, this enables the engine to generate high-quality translations that conform to the target language's syntax and industry terminology standards from the input source language text.

[0067] In step S304, after obtaining the target language text, the system does not immediately populate the text content back into the elastic container model established in step S2. Instead, the system first starts a space occupancy estimation program. The workflow of this program is as follows: iterates through and counts the target text string generated by translation to obtain its total number of characters, denoted as . .

[0068] In step S305, the space occupancy estimation program then performs a comprehensive calculation by combining parameters from multiple dimensions. These parameters include: the character set characteristics of the target language, such as the inherent differences in average width between Cyrillic and Latin alphabet characters; the font metrics extracted and stored in step S108 for the font currently applied to the container; and the system-preset typesetting density parameters.

[0069] Step S306: The system maintains a spatial prediction matrix, which stores the baseline width values ​​of various characters under different fonts and font sizes in the form of a lookup table.

[0070] The estimation program indexes the corresponding parameter values ​​from this matrix based on the currently effective font size, line height multiple, and character spacing expansion factor. Finally, the space required for the target text is calculated using the following formula:

[0071] in: This represents the estimated space required, and its unit is consistent with the coordinate system, usually in points (pt) or pixels (px). This value reflects the theoretical length that the target text needs to occupy along the text flow direction under the set layout parameters. : Represents the total number of characters in the target language text string, which is obtained by traversal and statistics in step S304. : Represents the first in the target language The theoretical character width of each character at standard font size. This value is obtained by querying the system's spatial prediction matrix. Different characters have different glyph designs. The values ​​are different; for example, the width of the character "W" is usually greater than that of the character "i".

[0072] : Represents the font size scaling factor. This factor is updated when the second-level adjustment mechanism in step S4 changes the text font size. In the initial estimation stage, this factor defaults to a value of 1.0, corresponding to the standard preset font size. : Represents the increment for character spacing adjustment. This value defines the extra gap width inserted between characters. During the initial estimation phase, this increment defaults to 0 or a preset standard character spacing value. This represents the buffer space added in advance based on the length expansion characteristics of the target language. This value is determined based on the statistical analysis results of a large number of bilingual parallel corpora.

[0073] For example, for the same semantic content, the character sequence length of German text is usually 30% to 50% longer than that of Chinese text. Therefore, when the target language is German, It will be assigned a positive offset to reserve any extra space that may be needed.

[0074] The calculation logic of the above formula is as follows: First, sum the actual width of each character under the scaling factor to obtain the total basic width of all characters; second, add the sum of all character spacing between characters; finally, add the buffer margin based on language characteristics.

[0075] By executing this formula, the system can estimate the theoretical width of the translated target text at standard font size and default line spacing. Simultaneously, by combining the line height multiple parameter, the system can also calculate the theoretical height of the text block.

[0076] Step S307: After the estimation program completes the calculation, the system will obtain the results. The value is compared with the boundary hard constraints of the elastic container model corresponding to the text element defined in step S2. The boundary hard constraints are specifically manifested as the maximum allowable width or maximum allowable height of the container in the text flow direction.

[0077] like If the value is less than or equal to the maximum allowable size, the system determines that the current layout space is sufficient and there is no risk of overflow, and the translated text can be directly filled into the container. Conversely, if... If the value exceeds the maximum allowable size, the system determines that there is a risk of layout overflow and records the determination result along with the specific overflow amount as a signal to trigger the next stage of action.

[0078] In summary, through the execution of step S3, this method achieves a precise quantitative assessment of the space requirements of the translated text before it truly impacts the document layout. This step organically connects semantic-level cross-language transformation with geometric-level spatial constraint calculation: the NMT engine ensures the professionalism of the translated content, while the space estimation formula quantifies the potential pressure that the expansion of the translated text will place on the page layout.

[0079] The resulting spillover risk assessment directly determines whether the cascading adjustment mechanism in step S4 needs to be activated, and which level of adjustment strategy needs to be initiated. At this point, the system has completed all the necessary information preparation for subsequent adaptive layout adjustments, and the process then proceeds to the execution phase of step S4.

[0080] In the above method, the final step, S4, is the layout adaptive adjustment process. This step is the core execution stage of this method, and its task is to automatically and dynamically correct the document layout based on the overflow risk assessment result transmitted in step S3. The system compares the estimated space occupancy with the available size of the flexible container model in real time. Once the overflow condition is confirmed, a cascading adjustment mechanism is initiated.

[0081] This mechanism follows the principle of starting with the smallest impact on the overall visual appearance of the document, and successively attempts three levels of adjustment: spacing compression, font size scaling, and boundary reconstruction based on topological shifts, until the overflow risk is completely eliminated. The specific implementation process of step S4 is described step by step below.

[0082] In step S401, the system receives the overflow risk assessment result output in step S307. If the assessment result indicates no overflow risk, the system directly fills the target language text generated in step S303 back into the corresponding elastic container model according to the layout attributes recorded in step S203, and jumps to step S409 to perform rendering output. If the assessment result indicates overflow risk, the system reads the overflow direction and overflow amount recorded in the assessment result and proceeds to step S402 to start the first-level adjustment.

[0083] Step S402, the first level of adjustment is spacing compression. The system first attempts to adjust the micro-typesetting parameters inside the flexible container without changing the text font size. This adjustment involves three types of compressible spacing objects: the first is line spacing, the second is character spacing, and the third is the spacing value of the blank areas before and after paragraphs.

[0084] Step S403, the line spacing compression process specifically involves: the system reading the line height multiple set for the current container. The initial value is typically 1.5 times. The system gradually compresses the data according to a preset compression step size, for example, decreasing the line height factor by 0.1 times each time. Compression is applied to a preset lower threshold. This lower threshold is typically set to 1.1 times. After each compression step, the system re-invokes the spatial estimation formula from step S306, based on the updated... The value is recalculated for the target text. The value is determined, and it is then checked whether the overflow has been eliminated.

[0085] Step S404, the character spacing compression process specifically involves the system adjusting the character spacing increment. Starting from the current value, make minor compensations in the negative direction. The constraints for the compression operation are: The minimum allowed value is limited to -0.5 points to prevent visual clumping between characters. Similarly, the compression of spacing before and after paragraphs works by gradually tightening the vertical gaps between paragraphs according to a preset ratio, such as reducing the current paragraph spacing by 10% each time.

[0086] In step S405, throughout the first-level adjustment process, the system uses a real-time text overlap detection module to ensure that the compression operation does not impair the readability of the document. This module works by analyzing the horizontal overlap ratio of adjacent character bounding boxes within the same line and the vertical overlap ratio of character bounding boxes between adjacent lines after completing the typesetting rasterization in memory.

[0087] If any overlap ratio exceeds a preset safety threshold, such as 5%, the system determines that the current compression level has reached the readability limit and immediately stops further compression in that direction. After each round of fine-tuning, the system re-observes the space surplus. If the overflow condition is eliminated, the cascading adjustment process stops, and the process proceeds to step S409 to perform final rendering.

[0088] Step S406: If the spatial estimation model still indicates overflow after the first-level adjustment, the system automatically switches to the second-level adjustment, i.e., font size scaling. In this stage, the system initiates a font size reduction program. Specifically, starting from an initial preset font size, such as 12 points, the font size scaling factor is gradually reduced in a preset step size, such as 0.5 points. The value of .

[0089] In step S407, during the font size scaling process, the system integrates a stroke clarity detection module to monitor the rendering quality of the scaled characters in real time. The module is implemented as follows: for each character glyph to be rendered, the system extracts its rasterized bitmap data at the target font size. The module uses the Canny edge detection algorithm to extract the outline of the character strokes and calculates the average pixel width of the main stroke region.

[0090] This module internally stores a minimum stroke width threshold, for example, 1.2 physical pixels. If the average width of the main stroke area of ​​any character is detected to be lower than this threshold, it is determined that further reducing the font size will cause stroke breakage or blurring, severely affecting the reading experience. At this point, the scaling process immediately stops and the current font size is adjusted. The value is locked as the limit for this adjustment.

[0091] In addition, the system sets an absolute lower limit threshold for font size, such as 9 points. When the font size drops below this threshold, the scaling process will be forcibly terminated regardless of the stroke detection results.

[0092] If the font size decreases during the update process The value makes the recalculated value and If all boundary hard constraints of the elastic container model are met, the system determines that the overflow has been eliminated, stops the cascade adjustment process, and proceeds to step S409. If the font size has been reduced to the limit value but the overflow problem still exists, the system determines that the first and second level adjustments are insufficient to resolve the current conflict, and then initiates the highest level, the third level adjustment.

[0093] Step S408, the third-level adjustment is a boundary reconstruction based on topological shift. This adjustment mechanism is no longer limited to parameter adjustments within the current text container, but creates additional space for the translation by changing the geometric position of the container itself and its associated elements below it. The system identifies the current text block affected by the overflow and queries all its vertically related sibling or parent-child elements from the document structure tree. These elements constitute the set of nodes affected by the association. .

[0094] The system models this translation problem as a linear programming problem. Its objective function is set to minimize the increase in the total page height, in order to maintain the original document's layout as compact as possible. The standard form of this linear programming model is as follows: Objective function:

[0095] The constraint is: for the current overflowing text block Its new height must be at least For any pair of adjacent elements whose relative distance constraint is defined in step S205 and The spacing after translation must not be less than its preset minimum gap threshold; for any element, the new position after translation must not exceed the boundary hard constraint range defined in step S206; for table cells, their width ratio must meet the ratio maintenance constraint defined in step S207.

[0096] in, : Represents the change in the total page height, which is the weighted sum of the vertical displacements of all affected nodes, in pixels. : Represents the set of affected nodes. This set is automatically determined by the system by traversing the document structure tree, specifically including the overflow text block itself, all its sibling nodes vertically below it, and the child nodes within those nodes.

[0097] : Represents the first The translation vector of each node. In practical solutions, since this problem mainly deals with vertical overflow, this vector degenerates into a scalar, that is, the displacement only in the vertical axis direction. , in pixels. : Represents the constraint weight of the region where the i-th node is located. This weight value is preset in the document structure tree and is used to reflect the difference in sensitivity of different regions to positional changes.

[0098] For example, the weight of the body text area can be set to 1.0, and the weight of the footer area can be set to 2.0, indicating that changes to the position of the footer area have a greater impact on the overall page height or that it is less desirable to move it. : Represents the magnitude of the vector, which in this scenario is the absolute value of the displacement.

[0099] For this linear programming problem, the system employs the simplex method for solution. Since the number of nodes on a document page is typically within the hundreds, the simplex method can converge to the optimal solution within milliseconds. After solving, the system obtains the set... Each node Optimal translation amount .

[0100] The system then performs the following geometric update operations: stretches the height of the overflowing text block to the required new height; and updates the set... The remaining nodes are treated as a whole, and their original vertical axis coordinates are increased by the corresponding translation amount. After the update is complete, the system recursively traverses the document structure tree, synchronously refreshing the relative coordinates of all child nodes within the affected elements to ensure topological consistency across the entire page. This reconstruction process involves a global write-back operation of the document structure tree, ensuring that the topological position of each associated node is recalculated and stored.

[0101] Step S409: After any of the above-mentioned level adjustments successfully eliminates the risk of overflow, or for text elements that originally did not have the risk of overflow, the system will determine the final target language text, along with all the typesetting parameters determined during the adjustment process—including the final font size scaling factor. , row height multiple Incremental adjustment of character spacing —Based on the final determined container geometry boundaries, the rasterization rendering of all page elements is completed in memory to generate the final document page that can be output or printed.

[0102] Through the cascading layout adaptive adjustment mechanism described in step S4, this method achieves fully automated layout repair capabilities, from micro-level fine-tuning of typesetting parameters to macro-level page structure reconstruction. This mechanism completely eliminates manual intervention in the typesetting correction process. Through a three-level orderly adjustment strategy, it gradually releases the container's space capacity while prioritizing document readability and visual appeal, ultimately addressing complex layout conflicts caused by cross-language text expansion. At this point, the core processing flow for a single document page is complete.

[0103] To ensure the final generated document meets high-fidelity requirements in engineering practice, this method also includes a quality monitoring step. After automated modification, the system calculates the visual similarity metric between the modified page and the original page using computer vision algorithms. Specifically, the system renders both the original and modified pages as bitmap images with the same resolution of 150 pixels per inch.

[0104] For each image, the system performs a perceptual hash algorithm: First, the image is scaled to a fixed size of 32 pixels × 32 pixels and converted into a grayscale single-channel image; second, a discrete cosine transform is performed on the grayscale image to extract 64 low-frequency coefficients in the 8×8 region in the upper left corner of the transformed matrix; then, these 64 coefficients are traversed, and bits with coefficient values ​​greater than the mean value are marked as 1, and bits with values ​​less than or equal to the mean value are marked as 0, thereby generating a 64-bit binary hash fingerprint.

[0105] The system calculates the Hamming distance between the original page fingerprint and the modified page fingerprint, using this Hamming distance as a measure of visual similarity. The system has a preset threshold of 5. If the calculated Hamming distance is greater than 5, the page layout is deemed to have changed too much and fails quality control.

[0106] For pages that fail quality monitoring, the system automatically marks their processing status as "human intervention suggestion" and generates a discrepancy report in the output directory. The report highlights image blocks with large Hamming distances for reviewers to perform final visual verification and targeted corrections. The entire process supports batch parallel processing of massive amounts of documents, and the total time for parsing, translating, estimating, and adjusting the layout of a single page is strictly controlled within a preset 500 millisecond time threshold.

[0107] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, 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 regarded as exemplary and non-limiting in all respects.

[0108] Furthermore, it should be understood that although this specification describes embodiments, not every embodiment contains only one independent technical solution. This narrative style is merely for clarity. Those skilled in the art should consider the specification as a whole, and the technical solutions in each embodiment can also be appropriately combined to form other embodiments that can be understood by those skilled in the art.

Claims

1. A method for cross-language parsing and automated modification of multi-format documents for digital transformation, characterized in that, Includes the following steps: Step S1: Obtain the document structure tree generated after the input document is parsed by multimodal analysis. Each node in the document structure tree corresponds to a document element and records the geometric position, topological association and font rendering attributes of the element. Step S2: Construct a flexible container model for each text element node in the document structure tree, and define a set of constraints for each flexible container model, including relative distance constraints, hard boundary constraints, and proportion preservation constraints. Step S3: Call the neural machine translation engine optimized with industry corpus to convert the source language text into the target language text, and calculate the estimated space occupancy of the target language text under the current typesetting parameters through the space occupancy prediction model. Step S4: When it is determined that the estimated space occupancy exceeds the boundary hard constraint of the elastic container model, a cascaded adjustment mechanism is activated. The cascaded adjustment mechanism executes three adjustment levels in sequence according to the order of the overall visual impact on the document from small to large: spacing compression, font size scaling, and boundary reconstruction based on topological shift, until the estimated space occupancy meets the boundary hard constraint or all levels are completed. After the cascading adjustment mechanism is executed, based on the final layout parameters determined after adjustment, the rasterization rendering of all elements on the page is completed in memory to generate the final document page.

2. The method according to claim 1, characterized in that, The specific steps in step S1 of obtaining the document structure tree include: The geometric topology parsing engine is invoked to perform binary stream analysis on the input document, identifying and classifying text blocks, background images, vector graphics, and table cell elements within the document. The layout analysis model based on deep learning is used to extract multi-scale features from the document page image to identify and locate the header area, footer area, sidebar area, text flow area and floating primitives. The layout analysis model adopts a two-stage target detection architecture that combines convolutional neural network and feature pyramid network. For each identified element, its starting horizontal axis coordinate, starting vertical axis coordinate, width, and height are accurately recorded in a unified two-dimensional coordinate system. The element hierarchy topology construction module identifies and extracts the parent-child nesting relationship and sibling adjacency relationship between elements, and determines the overlapping relationship between elements based on the preset overlap area threshold and the distance to the center point, generating layer order markers.

3. The method according to claim 1, characterized in that, The constraint set in step S2 is specifically as follows: The relative distance constraint is used to define the minimum gap threshold between two adjacent geometric entities to force the maintenance of this minimum gap during layout adjustments. The boundary hard constraint is used to define the absolute boundary that the elastic container cannot cross when it is stretched vertically or expanded horizontally. The absolute boundary is derived from the physical margin of the page, the preset column boundary, and the position of specific graphic elements marked as immovable. The proportional constraint is used to force the width of the current cell to remain constant in proportion to the width of adjacent columns in the same table when vertical stretching is triggered due to internal text overflow in a table cell.

4. The method according to claim 1, characterized in that, The space occupancy estimation model in step S3 calculates the estimated space occupancy using the following formula: in, Represents the estimated space occupancy. This represents the total number of characters in the target language text string. The first in the target language The theoretical character width of a character at a standard font size. Represents the font size scaling factor. The increment represents the character spacing adjustment. This represents the buffer space margin pre-set based on the length expansion characteristics of the target language; The method further includes: determining a maximum allowable size, the maximum allowable size being determined based on the boundary hard constraint; and calculating the maximum allowable size... The value is compared with the maximum allowable size. If If the value is greater than the maximum allowable size, it is determined that there is a risk of layout overflow, and the overflow direction and overflow amount are recorded.

5. The method according to claim 1, characterized in that, The first stage of the cascaded adjustment mechanism is spacing compression, which specifically includes: Read the initial value of the row height multiple set in the current elastic container model, compress the row height multiple gradually towards the preset lower threshold according to the preset compression step size, and call the space occupancy estimation model again after each compression step to determine whether the overflow has been eliminated; If the overflow is not eliminated after the line is compressed to the lower limit threshold, the word spacing adjustment increment will be slightly compensated from the current value in the negative direction until the preset minimum allowable value is reached. During the spacing compression process, the real-time text overlap detection module analyzes the horizontal overlap ratio of adjacent character bounding boxes within the same line and the vertical overlap ratio of character bounding boxes between adjacent lines. When any overlap ratio exceeds the preset safety threshold, further compression in the current direction is immediately stopped.

6. The method according to claim 1, characterized in that, The second level of adjustment in the cascaded adjustment mechanism is font size scaling, which specifically includes: Start the font size reduction program, starting from the initial preset font size and gradually reducing the font size scaling factor with a preset step size; During the font size scaling process, an integrated stroke clarity detection module is used. For each character glyph to be rendered, the stroke clarity detection module extracts its rasterized bitmap data at the target font size, extracts the outline of the character strokes through the Canny edge detection algorithm, and calculates the average pixel width of the main stroke area. When the average pixel width is lower than the preset minimum stroke width threshold, it is determined that continuing to reduce the font size will cause the strokes to break or become blurry. The scaling process is then immediately stopped and the current font size scaling factor is locked to the limit value of this adjustment.

7. The method according to claim 1, characterized in that, The third level of regulation in the cascaded regulation mechanism is boundary reconstruction based on topological shift, specifically including: Identify the current text block affected by the overflow, and query all its vertically related sibling or parent-child elements from the document structure tree to form a set of nodes affected by the association. The problem of determining the displacement of the set of nodes affected by the association is modeled as a linear programming problem, with the objective function set as minimizing the increase in the total page height; The objective function of the linear programming problem is: in, This represents the change in the total height of the page. Represents the set of nodes affected by association. Representing the Translation vector of each node, Representing the Constraint weights of the region where each node is located; The linear programming problem is solved using the simplex method to obtain the optimal translation amount for each node in the set. Based on this optimal translation amount, the geometric position of the affected nodes is updated. The document structure tree is recursively traversed, and the relative coordinates of the child nodes inside all affected elements are updated synchronously.

8. The method according to claim 1, characterized in that, It also includes quality control steps: The generated final document page and the original document page are rendered as bitmap images of the same resolution; Perform a perceptual hashing algorithm on each bitmap image: scale the image to a fixed size and convert it into a grayscale single-channel image, perform a discrete cosine transform on the grayscale image, extract multiple low-frequency coefficients in the upper left corner region of the transformed matrix, traverse these coefficients, mark the bits with coefficient values ​​greater than the mean of the coefficients as 1, and mark the bits with values ​​less than or equal to the mean as 0, thereby generating a binary hash fingerprint. Calculate the Hamming distance between the original page fingerprint and the modified page fingerprint, and use this Hamming distance as a measure of visual similarity; If the calculated Hamming distance is greater than the preset threshold, the page layout change is determined to have failed quality monitoring. The page's processing status is marked as a manual intervention suggestion, and a difference report is generated, highlighting the image blocks with larger Hamming distances.

9. The method according to claim 1, characterized in that, The multimodal parsing process in step S1 also includes the logic for extracting and replacing embedded fonts: When the target language does not support the original font encoding used in the source document, it automatically retrieves and matches the closest alternative font in visual style from the preset open-source font library. The matching dimensions include whether it is a serif or sans-serif font and the thickness of the font strokes. After the font replacement is completed, the font measurement parameters of the new font are read. The font measurement parameters include the ascending part value, the descending part value and the line spacing value. Based on these measurement parameters, the logical space occupied by each character in the current standard typesetting environment is recalculated.

10. The method according to claim 1, characterized in that, The method performs batch parallel processing on massive documents, and the total time for parsing, translation estimation and layout adjustment of a single page is strictly controlled within a preset time threshold of 500 milliseconds. The input document format includes portable document format and word processing document format, and the word processing document format includes DOCX format and RTF format; The neural machine translation engine uses the Transformer architecture as the basic sequence-to-sequence model. Its training process includes a general domain pre-training stage using a general bilingual corpus, and a domain-adaptive fine-tuning stage using a specific industry domain fine-tuning dataset.