A method and system for lossless document format conversion and multi-format output
By combining the intermediate document object model and the target rendering engine, the problems of data loss and insufficient compatibility in document conversion are solved, and lossless conversion and stable adaptation to multiple format output are achieved.
Patent Information
- Application Number
- CN202611159802.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-02
- Publication Date
- 2026-11-06
AI Technical Summary
Existing document conversion technologies suffer from problems such as data loss, layout errors, and format distortion, making it impossible to achieve lossless conversion. Furthermore, they cannot adapt to various target output formats and lack compatibility.
The intermediate document object model is used for unified conversion and processing of document data. By recognizing the source document format, document data information is obtained and mapped to the preset intermediate document object model for updating. Combined with the target rendering engine, the target format output file is generated.
It achieves consistency between content and layout during document conversion, adapts to multiple target output formats, improves the adaptability and compatibility of multi-format output, and reduces problems such as layout errors and missing content.
Smart Images

Figure CN123050349A_ABST
Abstract
Description
Technical Field
[0001] This invention proposes a method and system for lossless document format conversion and multi-format output, belonging to the field of document conversion technology. Background Technology
[0002] Currently, there are numerous types of office and scenario-based document formats, with significant differences in structure, layout, and data storage logic. Cross-format document conversion is a core necessity in the field of office digitization. Most mainstream document conversion technologies currently employ direct format mapping conversion, lacking a unified document data transfer and processing architecture.
[0003] Existing conversion methods generally suffer from data loss, layout errors, and format distortion during multi-format adaptation, making it difficult to achieve lossless conversion. Furthermore, traditional technologies are fixed to a single rendering logic and cannot match the corresponding rendering engine to different target output formats, resulting in poor adaptability and insufficient compatibility for parallel multi-format output.
[0004] In addition, conventional conversion mechanisms cannot dynamically update and adapt to document data models. They are weak in adapting to the style and layout data of complex document formats, and the output files are prone to defects such as misalignment of images and text and missing formats. The conversion stability and universality are low, and they cannot meet the current needs for lossless conversion and diversified output of documents in multiple scenarios and of multiple specifications. Summary of the Invention
[0005] This invention provides a method and system for lossless document format conversion and multi-format output, to solve the aforementioned technical problems existing in the prior art. The technical solution adopted is as follows:
[0006] A method for lossless document format conversion and multi-format output includes:
[0007] Identify the original format type of the source document to be converted and obtain the document data information of the source document;
[0008] The document data information is mapped to a preset intermediate document object model, the intermediate document object model is updated, and the target rendering engine is determined.
[0009] Based on the target output format type of the source document to be converted, the target format output file is obtained using the target rendering engine and the updated intermediate document object model.
[0010] Preferably, identifying the original format type of the source document to be converted and obtaining the document data information of the source document includes:
[0011] Extract the source document to be converted and the target output format type specified by the user;
[0012] Identify the original format type of the source document to be converted, and retrieve the document parser corresponding to the original format type;
[0013] The document parser is used to perform structured parsing on the source document to be converted to obtain the document data information of the source document; wherein, the document data information includes the text content data, style attribute data, and hierarchical structure data of the source document to be converted.
[0014] Preferably, mapping the document data information to a preset intermediate document object model, updating the intermediate document object model, and determining the target rendering engine include:
[0015] Extract the document data information of the source document to be converted, and map the document data information to a preset intermediate document object model. The intermediate document object model is stored in a tree structure, and the node types of the tree structure include at least document root node, chapter node, paragraph node, text execution node, table node, graphic node and style attribute node. Each node contains a set of key-value pairs that represent its original attribute parameters in the source document.
[0016] Traverse the mapped intermediate document object model, extract the effective absolute style values of each document node in the mapped intermediate document object model, and update the effective absolute style values of each document node to the attribute set corresponding to each document node to generate the updated intermediate document object model.
[0017] Based on the target output format type specified by the user, the corresponding target rendering engine is selected from multiple preset format rendering engines.
[0018] Preferably, based on the target output format type of the source document to be converted, the target format output file is obtained using the target rendering engine and the updated intermediate document object model, including:
[0019] Determine the target output format type of the source document to be converted and obtain the determination result, wherein the target output format type includes a fluid layout format and a fixed layout format;
[0020] When the judgment result indicates that the target output format type of the source document to be converted belongs to the streaming layout format, the target rendering engine is controlled to read the updated intermediate document object model, traverse each document node in the updated intermediate document object model, and map each document node to the markup language elements and attributes corresponding to the streaming layout format according to the updated absolute style values in each document node in the traversal order of the tree structure, and serialize and generate the streaming layout format output file.
[0021] If the determination result indicates that the target output format type belongs to a fixed layout format, then the target rendering engine is controlled to read the updated intermediate document object model, traverse each document node in the updated intermediate document object model, use the updated absolute style values and hierarchical structure data in each document node to perform page layout calculation, obtain the absolute coordinate position and pagination information of each document node on the physical page, and use the absolute coordinate position and pagination information to draw the corresponding content of each document node into the page content stream of the fixed layout format, generating a fixed layout format output file.
[0022] A lossless document format conversion and multi-format output system includes:
[0023] The data information acquisition module is used to identify the original format type of the source document to be converted and to acquire the document data information of the source document;
[0024] The model update and engine determination module is used to map the document data information to a preset intermediate document object model, update the intermediate document object model, and determine the target rendering engine.
[0025] The conversion control module is used to obtain the target format output file based on the target output format type of the source document to be converted, using the target rendering engine and the updated intermediate document object model.
[0026] Preferably, the data information acquisition module is used to identify the original format type of the source document to be converted and to acquire the document data information of the source document, including:
[0027] Extract the source document to be converted and the target output format type specified by the user;
[0028] Identify the original format type of the source document to be converted, and retrieve the document parser corresponding to the original format type;
[0029] The document parser is used to perform structured parsing on the source document to be converted to obtain the document data information of the source document; wherein, the document data information includes the text content data, style attribute data, and hierarchical structure data of the source document to be converted.
[0030] Preferably, the model update and engine determination module is used to map the document data information to a preset intermediate document object model, update the intermediate document object model, and determine the target rendering engine, including:
[0031] Extract the document data information of the source document to be converted, and map the document data information to a preset intermediate document object model. The intermediate document object model is stored in a tree structure, and the node types of the tree structure include at least document root node, chapter node, paragraph node, text execution node, table node, graphic node and style attribute node. Each node contains a set of key-value pairs that represent its original attribute parameters in the source document.
[0032] Traverse the mapped intermediate document object model, extract the effective absolute style values of each document node in the mapped intermediate document object model, and update the effective absolute style values of each document node to the attribute set corresponding to each document node to generate the updated intermediate document object model.
[0033] Based on the target output format type specified by the user, the corresponding target rendering engine is selected from multiple preset format rendering engines.
[0034] Preferably, the conversion control module is used to obtain the target format output file based on the target output format type of the source document to be converted, using the target rendering engine and the updated intermediate document object model, including:
[0035] Determine the target output format type of the source document to be converted and obtain the determination result, wherein the target output format type includes a fluid layout format and a fixed layout format;
[0036] When the judgment result indicates that the target output format type of the source document to be converted belongs to the streaming layout format, the target rendering engine is controlled to read the updated intermediate document object model, traverse each document node in the updated intermediate document object model, and map each document node to the markup language elements and attributes corresponding to the streaming layout format according to the updated absolute style values in each document node in the traversal order of the tree structure, and serialize and generate the streaming layout format output file.
[0037] If the determination result indicates that the target output format type belongs to a fixed layout format, then the target rendering engine is controlled to read the updated intermediate document object model, traverse each document node in the updated intermediate document object model, use the updated absolute style values and hierarchical structure data in each document node to perform page layout calculation, obtain the absolute coordinate position and pagination information of each document node on the physical page, and use the absolute coordinate position and pagination information to draw the corresponding content of each document node into the page content stream of the fixed layout format, generating a fixed layout format output file.
[0038] Beneficial effects of this invention:
[0039] This invention proposes a lossless document format conversion and multi-format output method and system. It achieves unified conversion of multi-format document data through an intermediate document object model, avoiding data structure conflicts caused by direct conversion of different document formats and ensuring content and layout consistency during document conversion. The differentiated matching target rendering engine can adapt to the rendering rules of various target output formats, improving the adaptability and compatibility of multi-format output. The dynamic update mechanism of the intermediate document object model can adapt to the data characteristics of different types of source documents, optimize the reconstruction accuracy of the streaming layout, reduce layout errors and content loss during document conversion, and stably adapt to document format conversion and multi-type output requirements in various scenarios.
[0040] Other features and advantages of the invention will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures particularly pointed out in the written description and the accompanying drawings.
[0041] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0042] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings:
[0043] Figure 1 This is a flowchart of the method described in this invention;
[0044] Figure 2 This is a system block diagram of the system described in this invention. Detailed Implementation
[0045] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
[0046] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," "outer," "far," "near," "front," and "rear," etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the accompanying drawings and are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0047] In the description of this invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.
[0048] In this invention, the term "intermediate document object model" refers to an abstract data model that uses a tree structure to store document data. Its node types include at least a document root node, chapter nodes, paragraph nodes, text execution nodes, table nodes, graphic nodes, and style attribute nodes. Each node stores original attribute parameters through a set of key-value pairs, and each node contains a node type identifier, a unique identifier, a parent node reference, a list of child nodes, and the set of key-value pair attributes. The term "absolute style value" refers to the final style value determined after applying all style inheritance, cascading, and priority rules to a document node. For example, "1.5 line spacing" combined with the parent node's font size is calculated as a specific point value, or "2em" is converted into an absolute pixel value relative to the root node's font size. The term "fluid layout format" refers to a document format where content is arranged sequentially and the page size adjusts adaptively, including but not limited to HTML and EPUB. The term "fixed layout format" refers to a document format where content has a fixed page size and absolute position coordinates, including but not limited to PDF. The term "lossless conversion" means that the text content, style attributes, and hierarchical structure of the converted document remain consistent with the source document, without losing any original data.
[0049] This invention proposes a method for lossless document format conversion and multi-format output, such as... Figure 1 As shown, the document format lossless conversion and multi-format output method includes:
[0050] Identify the original format type of the source document to be converted and obtain the document data information of the source document;
[0051] The document data information is mapped to a preset intermediate document object model, the intermediate document object model is updated, and the target rendering engine is determined.
[0052] Based on the target output format type of the source document to be converted, the target format output file is obtained using the target rendering engine and the updated intermediate document object model.
[0053] In this embodiment, firstly, the original format type of the source document is identified, and all types of data information corresponding to the document are comprehensively collected to complete the complete aggregation of the original document content and layout data. By uniformly mapping the collected document data information to a preset intermediate document object model, the standardization and structured unified encapsulation of source document data of different formats are achieved, and the intermediate document object model is iteratively updated according to the document data status. At the same time, the corresponding target rendering engine is matched with the preset output requirements. Through a unified intermediate layer data structure, the matched rendering engine parses and reconstructs the updated intermediate document object model data in a streaming layout, and finally generates a target format output file that meets the target format requirements.
[0054] This embodiment achieves unified conversion of multi-format document data through an intermediate document object model, avoiding data structure conflicts caused by direct conversion of different document formats and ensuring consistency of content and layout during document conversion. The differentiated matching target rendering engine's processing method can adapt to the rendering rules of various target output formats, improving the adaptability and compatibility of multi-format output. The dynamic update mechanism of the intermediate document object model can adapt to the data characteristics of different types of source documents, optimize the reconstruction accuracy of the streaming layout, reduce layout errors and content loss during document conversion, and stably adapt to document format conversion and multi-type output requirements in various scenarios.
[0055] In one embodiment of the present invention, identifying the original format type of the source document to be converted and obtaining the document data information of the source document includes:
[0056] Extract the source document to be converted and the target output format type specified by the user;
[0057] Identify the original format type of the source document to be converted, and retrieve the document parser corresponding to the original format type;
[0058] The document parser is used to perform structured parsing on the source document to be converted to obtain the document data information of the source document; wherein, the document data information includes the text content data, style attribute data, and hierarchical structure data of the source document to be converted.
[0059] In this embodiment, the document parser provides a unified parsing interface. Its input is the source document file, and its output is a document data information structure. This structure contains text content, style attributes, and hierarchical structure data. Parsers of different formats internally adapt to their respective format specifications.
[0060] This embodiment first reads and extracts the source document to be converted and the target output format information set by the user, and determines the original format type of the source document through a format recognition mechanism. Based on the identified original format type, a matching dedicated document parser is invoked, and corresponding parsing rules are applied for different format documents to perform structured decomposition processing of the source document. The dedicated parser completes comprehensive document parsing, accurately extracting and collecting the text content data, style attribute data, and hierarchical structure data of the source document, and completely retaining all the core data and layout structure information of the source document, providing complete and accurate original data support for subsequent document format conversion processing.
[0061] In this embodiment, dedicated parsers are configured for different original document formats, overcoming the limitation of single-adaptability issues of general parsers and adapting to more types of source document parsing scenarios. The structured parsing approach accurately splits and completely preserves the document's text, style, and hierarchical structure data, avoiding data omissions and attribute loss during parsing. A unified data extraction dimension enables standardized aggregation of various source document data, providing a well-organized and complete data foundation for subsequent document model mapping and format rendering, ensuring the orderly conduct of subsequent format conversion work.
[0062] One embodiment of the present invention includes mapping the document data information to a preset intermediate document object model, updating the intermediate document object model, and determining the target rendering engine, comprising:
[0063] Extract the document data information of the source document to be converted, and map the document data information to a preset intermediate document object model. The intermediate document object model is stored in a tree structure, and the node types of the tree structure include at least document root node, chapter node, paragraph node, text execution node, table node, graphic node and style attribute node. Each node contains a set of key-value pairs that represent its original attribute parameters in the source document.
[0064] Traverse the mapped intermediate document object model, extract the effective absolute style values of each document node in the mapped intermediate document object model, and update the effective absolute style values of each document node to the attribute set corresponding to each document node to generate the updated intermediate document object model.
[0065] Based on the target output format type specified by the user, the corresponding target rendering engine is selected from multiple preset format rendering engines.
[0066] In this embodiment, each node in the tree structure contains a node type identifier, a unique identifier, a parent node reference, a list of child nodes, and a set of key-value pair attributes. The set of key-value pair attributes is used to store the original style attributes, such as {"font-size":"12pt", "bold":"true", "margin":"10px"}. The calculation of absolute style values follows the rules of style inheritance and cascading, that is, traversing downwards from the root node of the document, child nodes inherit the style attributes of the parent node, and if a child node defines the same attribute, it overrides the parent node's value. Relative units (such as em, percentage) are converted according to the base value of the parent node or the root node, and finally the absolute value of each style attribute of each node is obtained. For example, "1.5em" is converted to "18pt" (assuming the font size of the root node is 12pt).
[0067] In this embodiment, the various data information of the parsed document are mapped to a preset tree-structured intermediate document object model. This model covers the overall structure of the document and various element attributes through multiple types of nodes, and records the original attribute parameters of each node in a key-value pair set, realizing the structured loading of the full data and structure of the source document. By traversing the mapped intermediate document object model, the actual effective absolute style values of each node are extracted, and these style values are synchronously updated to the attribute set of the corresponding node, completing the calibration and iteration of the model data. Finally, according to the target output format type preset by the user, the corresponding engine is matched among the various format rendering engines pre-configured by the system to complete the selection of subsequent rendering processing units.
[0068] In this embodiment, the tree-structured intermediate document object model can fully cover the hierarchical structure and diverse element types of documents, adapting to document data input with different structures and content. The key-value pair storage structure associated with each node can completely retain the original document attribute parameters, ensuring that the source document data does not lose structure or attributes during the model mapping stage. By uniformly updating the absolute style values of nodes, the data standard within the model is unified, eliminating adaptation deviations caused by relative parameters of the original document styles. By matching the output format to the corresponding rendering engine, a correspondence between the model and multiple format output channels is established, providing architectural support for the unified conversion and output of multiple document formats.
[0069] In one embodiment of the present invention, according to the target output format type of the source document to be converted, a target format output file is obtained using the target rendering engine and the updated intermediate document object model, including:
[0070] Determine the target output format type of the source document to be converted and obtain the determination result, wherein the target output format type includes a fluid layout format and a fixed layout format;
[0071] When the judgment result indicates that the target output format type of the source document to be converted belongs to the streaming layout format, the target rendering engine is controlled to read the updated intermediate document object model, traverse each document node in the updated intermediate document object model, and map each document node to the markup language elements and attributes corresponding to the streaming layout format according to the updated absolute style values in each document node in the traversal order of the tree structure, and serialize and generate the streaming layout format output file.
[0072] If the determination result indicates that the target output format type belongs to a fixed layout format, then the target rendering engine is controlled to read the updated intermediate document object model, traverse each document node in the updated intermediate document object model, use the updated absolute style values and hierarchical structure data in each document node to perform page layout calculation, obtain the absolute coordinate position and pagination information of each document node on the physical page, and use the absolute coordinate position and pagination information to draw the corresponding content of each document node into the page content stream of the fixed layout format, generating a fixed layout format output file.
[0073] In this embodiment, each rendering engine implements a unified rendering interface, which includes at least the following functions: reading the intermediate document object model, traversing nodes, and generating output content. The streaming layout rendering engine maps document nodes to HTML or XML tags and their attributes, and outputs them in a depth-first tree traversal order, ultimately generating the target file through serialization. The fixed layout rendering engine calculates the x and y coordinates and page break positions of each node on a standard page such as A4 or Letter based on the absolute style values and hierarchical structure of the nodes, and then draws text, graphics, and other content into the page description stream to generate fixed layout files such as PDF.
[0074] In this embodiment, firstly, the target output format type set by the user is determined, distinguishing between two output scenarios: fluid layout format and fixed layout format, and executing differentiated rendering logic accordingly. For the fluid layout format, the target rendering engine reads the updated intermediate document object model, traverses all document nodes according to the tree structure, and, combined with the absolute style values stored in the nodes, converts each document node into elements and attributes of the corresponding markup language, generating a fluid layout output file through serialization. For the fixed layout format, the rendering engine reads the absolute style values and hierarchical structure data of the model nodes, completes page layout calculations, determines the absolute coordinates and pagination information of each document node in the physical page, and draws all node content to the page content stream based on this arrangement information, ultimately generating a fixed layout format output file.
[0075] This embodiment sets up independent rendering and generation logic for two mainstream document output formats, adapting to document output scenarios with different layout requirements. Differentiated rendering output is achieved based on a unified intermediate document object model, ensuring that output files of different formats can match the style and structure data after node calibration. The streaming output mode adapts to document usage scenarios requiring adaptive layout, while the fixed layout output mode restores the document's page arrangement and pagination structure. The entire output logic unifies the conversion and output process for different document formats, enriches the output types for document format conversion, and adapts to diverse document layout output needs.
[0076] In one embodiment, after identifying the original format type of the source document to be converted and obtaining the document data information, and before mapping the document data information to a preset intermediate document object model, the method may further include the following steps:
[0077] Step A1: Obtain the structure and style distribution parameters of the source document, including the total number of categories of different node types in the source document. (This parameter is obtained by deduplicating and counting the type identifiers of all nodes in the parsing result), the total number of all document element nodes in the source document. (This parameter is obtained by counting all nodes in the parsing result one by one), the maximum depth of the hierarchical structure tree of the source document. (This parameter is obtained by traversing the hierarchical structure tree in the parsing result, calculating the path length from the root node to the deepest leaf node, and taking the maximum value.) The standard deviation of the number of style attribute key-value pairs carried by each node in the source document. (This parameter is obtained by counting the total number of style attribute key-value pairs corresponding to each node and then calculating the standard deviation of this number for all nodes), and the arithmetic mean of the number of style attribute key-value pairs carried by each node in the source document. (This parameter is obtained by taking the arithmetic mean of the number of style attribute key-value pairs across all nodes); where, The value of ≥1, The value of ≥1, The value of ≥1, The value of ≥0, The value of is greater than 0;
[0078] Step A2, according to the above , , , , Determine the document structure heterogeneity index ;
[0079] Specifically, the following formula can be used for calculation:
[0080]
[0081] The preset minimum positive number to prevent division by zero, for example, is: ;
[0082] in, This indicates the breadth of type coverage per unit number of nodes; The logarithmic compressed value representing the complexity of nested levels; The discrete gain factor representing the pattern distribution;
[0083] Step A3: Before performing the step of mapping the document data information to the preset intermediate document object model, determine the mapping strategy used in the step of mapping the document data information to the preset intermediate document object model based on the document structure heterogeneity index (using the document structure heterogeneity index as the decision basis for selecting the mapping strategy).
[0084] The document data information remains unchanged during the mapping strategy determination process, and after the mapping strategy is determined, the step of mapping the document data information to a preset intermediate document object model continues. The DSHI calculation result is read only once before the mapping step begins and does not participate in any conditional branch judgments, loop control, or document node data modification operations within the step of mapping the document data information to the preset intermediate document object model. The mapping strategy is determined based on the document structure heterogeneity index, specifically using any of the following methods:
[0085] Method 1: Determine the structural complexity level of the source document based on the value of the document structure heterogeneity index: when When the complexity exceeds a preset first threshold, the document is classified as high-complexity. In the subsequent step of mapping the document data to a preset intermediate document object model, a refined mapping mode is adopted. Specifically, during the mapping process, a key-value pair attribute set cache space larger than the default capacity is pre-allocated to each document node in the constructed intermediate document object model. Furthermore, complete hierarchical structure data is additionally retained for subtrees with a depth exceeding the average level in the hierarchical structure data to prevent style propagation breaks due to missing hierarchical structure data in subsequent absolute style value calculations for deep document nodes. When the document data is less than or equal to the first threshold and greater than the preset second threshold, it is determined to be a document of medium complexity. In the subsequent step of mapping the document data to the preset intermediate document object model, a conventional mapping mode is used, i.e., mapping is performed according to the default node capacity and standard hierarchical structure depth. When the value is less than or equal to the second threshold, it is determined to be a low-complexity document. In the subsequent step of mapping the document data information to the preset intermediate document object model, a lightweight mapping mode is adopted, that is, during the mapping process, redundant intermediate attribute caches are reduced and a flat document node storage structure is adopted; the first threshold and the second threshold are pre-calibrated by the system based on historical conversion samples, and the first threshold is greater than the second threshold.
[0086] Method 2: Obtain the historical heterogeneity index baseline value corresponding to the document type to which the source document belongs. Calculate the deviation rate between the document structure heterogeneity index and the historical heterogeneity index benchmark value. ,in The value is a very small positive number, and the adjustment range of the mapping strategy is determined according to the value of the deviation rate: when the deviation rate is less than or equal to a preset first deviation threshold, a preset standard mapping strategy corresponding to the document type is adopted; when the deviation rate is greater than the first deviation threshold and less than or equal to a preset second deviation threshold, an enhanced mapping strategy is adopted, that is, based on the standard mapping strategy, additional attribute cache space is added for document nodes in the document data information where the number of style attribute key-value pairs exceeds the average value; when the deviation rate is greater than the second deviation threshold, an adaptive mapping strategy is adopted, that is, based on the enhanced mapping strategy, attribute cache space is independently configured for document nodes at each level depth in the hierarchical structure tree, and the cache space capacity at different level depths increases progressively with the level depth; the historical heterogeneity index benchmark value The system pre-calibrates the DSHI values of processed source documents of the same type by statistical averaging. The first deviation threshold and the second deviation threshold are pre-calibrated by the system based on historical conversion quality feedback, and the first deviation threshold is less than the second deviation threshold.
[0087] The above technical solution, after the source document is parsed and before it is mapped to the intermediate document object model, calculates a document structure heterogeneity index (DSHI) based on the parsing results, including the document's node type richness, total number of nodes, maximum hierarchical depth, and the standard deviation and mean of the number of style key-value pairs for each node. The system then uses this data to determine the document's structural complexity by comparing the DSHI value with historical benchmarks for similar documents. Based on this, the system differentiates the allocation of node cache space, adjusts the granularity of hierarchical information retention, or simplifies the node storage structure in subsequent mapping steps. The advantages of this technical solution are: it enables the mapping strategy to adaptively adjust according to the complexity of the source document structure, preventing high-complexity documents from causing subsequent style propagation breaks due to insufficient cache space or lost hierarchical information, while avoiding low-complexity documents consuming excessive cache and computational resources, thereby improving the overall processing efficiency of the mapping steps while ensuring conversion quality.
[0088] In one embodiment, after traversing the mapped intermediate document object model and extracting the effective absolute style values for each document node, and updating the absolute style values to the attribute set corresponding to each document node, before filtering the target rendering engine based on the target output format type, the method may further include:
[0089] Step B1: Obtain the style parsing and cascading propagation state parameters of each document node in the updated intermediate document object model, including: the total number of style attribute entries for which absolute style values have been successfully parsed and attribute updates have been completed. (This parameter is obtained by accumulating a count each time a style attribute value is successfully parsed and written into the attribute set of the corresponding document node during the traversal process.) The total number of style attribute entries that need to be parsed for all nodes in the entire document in the updated intermediate document object model. (This parameter is obtained by pre-counting the sum of all document node style attribute entries to be parsed before the traversal begins), the total number of attribute entries with definition conflicts during style inheritance and cascading propagation. (This parameter is obtained by accumulating counts each time a multi-source conflict is determined during the calculation of the absolute style value and cannot be uniquely determined.) The total number of operations for cascading rule adjudication. (This parameter is obtained by accumulating a count each time a cascading rule adjudication operation is performed during the calculation of absolute style values); and the average hierarchy depth of the document node to which the conflicting attribute belongs. (This parameter is calculated by summing the depth values of the document nodes belonging to the conflicting attributes in the hierarchical structure tree and then dividing by...) get);
[0090] in, The value of ≥0, The value of ≥1 and , The value of ≥0, The value of ≥0, if but Not included in the calculation, otherwise The value of is ≥1;
[0091] Step B2, according to the above , , , and Determine the style overlay fidelity coefficient;
[0092] Specifically, the following formula can be used for calculation:
[0093]
[0094] in, For the preset zero-prevention coefficient, take the smallest positive number, for example... ; This is the conflict depth attenuation factor, with a value ranging from 0.05 to 0.2. The dimension is the reciprocal of the number of layers;
[0095] in, This represents the absolute style value parsing completion rate of the updated intermediate document object model; Indicates the cascading collision rate, when When the ratio is 0, the physical meaning is that no decision-making operation has occurred, so there is no conflict. This represents the conflict depth attenuation factor. The deeper the conflict occurs in the document node, the smaller this factor becomes, indicating that the conflict has a lower negative impact on the overall document style fidelity.
[0096] Step B3: Before executing the step of selecting the corresponding target rendering engine from multiple preset format rendering engines according to the target output format type specified by the user, the rendering strategy to be used in subsequent rendering steps is determined according to the style overlay fidelity coefficient (the style overlay fidelity coefficient is used as the decision basis for the rendering strategy selection).
[0097] The updated intermediate document object model remains unchanged during the rendering strategy determination process. After the rendering strategy is determined, the step of selecting the corresponding target rendering engine from multiple preset format rendering engines based on the user-specified target output format type continues. The calculation result of the SCFC is only read once before the rendering step starts, does not participate in any conditional branch judgments within the rendering engine selection step, does not affect the determination result of the target rendering engine, and does not participate in the modification of specific rendering content in the output file generation step. The rendering strategy is determined based on the style overlay fidelity coefficient, specifically using any of the following methods:
[0098] Method 1: Determine the quality level of the absolute style value update process based on the value of the style overlay fidelity coefficient: when When the value exceeds the preset third threshold, it is determined to be a high-confidence update, and a direct rendering mode is adopted in subsequent rendering steps. That is, the target rendering engine directly reads the updated absolute style values of each document node in the updated intermediate document object model to generate the output file, without performing additional style data validation or completion operations; when When the value is less than or equal to the third threshold and greater than the preset fourth threshold, it is determined to be a medium-confidence update. In subsequent rendering steps, a verification-enhanced rendering mode is adopted. That is, after reading the absolute style values of each document node in the updated intermediate document object model and before generating the output file, an additional style integrity check is performed on nodes whose hierarchical depth in the style inheritance chain exceeds the average value. For style attributes found to be missing during the check, they are filled in with the corresponding style value of the nearest ancestor node in the subtree where the node is located. When the value is less than or equal to the fourth threshold, it is determined to be a low-confidence update. In subsequent rendering steps, a compensation rendering mode is adopted. That is, after reading the absolute style values of each document node in the updated intermediate document object model and before generating the output file, a full style baseline completion operation is performed on all document nodes. That is, based on the default style of the document root node, the style is passed down layer by layer and the missing or conflicting style entries in the attribute set of each node are forcibly overridden. The third threshold and the fourth threshold are pre-calibrated by the system based on historical rendering samples, and the third threshold is greater than the fourth threshold.
[0099] Method 2: Obtain the historical fidelity baseline value corresponding to the document type of the updated intermediate document object model. Calculate the deviation rate between the style overlay fidelity coefficient and the historical fidelity benchmark value. ,in The value is a very small positive number, and the adjustment range of the rendering strategy is determined according to the value of the deviation rate: when the deviation rate is less than or equal to a preset first deviation threshold, a standard rendering strategy corresponding to the document type is adopted, that is, the target rendering engine directly reads the updated absolute style values of each document node in the updated intermediate document object model to generate the output file; when the deviation rate is greater than the first deviation threshold and less than or equal to a preset second deviation threshold, an optimized rendering strategy is adopted, that is, based on the standard rendering strategy, after reading the absolute style values of each document node in the updated intermediate document object model and before executing the output file generation, the style attributes are adjusted. Document nodes with more than the average number of entries undergo an additional style integrity check. Missing style attributes are filled in using the corresponding style value of the nearest ancestor node in the subtree containing that node. When the deviation rate exceeds the second deviation threshold, an enhanced rendering strategy is adopted. This involves performing a full style baseline completion operation on all document nodes after reading the absolute style values of each document node in the updated intermediate document object model, but before generating the output file. This means using the default style of the root document node as a baseline, passing it down layer by layer, and forcibly overriding any missing or conflicting style entries in the attribute sets of each node. The historical fidelity baseline value... The system pre-calibrates the SCFC values of processed documents of the same type by statistical averaging. The first deviation threshold and the second deviation threshold are pre-calibrated by the system based on historical rendering quality feedback, and the first deviation threshold is less than the second deviation threshold.
[0100] The above technical solution, after updating the absolute style values of each node in the intermediate document object model and before selecting the target rendering engine, calculates a Style Cascading Fidelity Coefficient (SCFC) by statistically analyzing the number of successfully parsed style attribute entries, the total number of entries to be parsed, the number of cascading conflicts, the total number of adjudications, and the average depth of conflicting nodes during the update process. The system then uses the SCFC value or compares its deviation rate with historical benchmark values of similar documents to pre-assess the reliability of the current absolute style value update. Based on this, it determines in subsequent rendering steps whether additional style verification and completion are needed, and whether the completion should be local or global. The beneficial effects of this technical solution are: it enables the rendering strategy to adaptively adjust according to the quality of style updates; it allows direct rendering of high-confidence scenarios with complete parsing and few conflicts to avoid redundant operations; and it promptly corrects style data defects in scenarios with low parsing quality through verification and completion mechanisms, thereby reducing the risk of output format errors due to missing or conflicting style information while ensuring rendering efficiency.
[0101] This invention proposes a lossless document format conversion and multi-format output system, such as... Figure 2 As shown, the system includes:
[0102] The data information acquisition module is used to identify the original format type of the source document to be converted and to acquire the document data information of the source document;
[0103] The model update and engine determination module is used to map the document data information to a preset intermediate document object model, update the intermediate document object model, and determine the target rendering engine.
[0104] The conversion control module is used to obtain the target format output file based on the target output format type of the source document to be converted, using the target rendering engine and the updated intermediate document object model.
[0105] In this embodiment, firstly, the original format type of the source document is identified, and all types of data information corresponding to the document are comprehensively collected to complete the complete aggregation of the original document content and layout data. By uniformly mapping the collected document data information to a preset intermediate document object model, the standardization and structured unified encapsulation of source document data of different formats are achieved, and the intermediate document object model is iteratively updated according to the document data status. At the same time, the corresponding target rendering engine is matched with the preset output requirements. Through a unified intermediate layer data structure, the matched rendering engine parses and reconstructs the updated intermediate document object model data in a streaming layout, and finally generates a target format output file that meets the target format requirements.
[0106] This embodiment achieves unified conversion of multi-format document data through an intermediate document object model, avoiding data structure conflicts caused by direct conversion of different document formats and ensuring consistency of content and layout during document conversion. The differentiated matching target rendering engine's processing method can adapt to the rendering rules of various target output formats, improving the adaptability and compatibility of multi-format output. The dynamic update mechanism of the intermediate document object model can adapt to the data characteristics of different types of source documents, optimize the reconstruction accuracy of the streaming layout, reduce layout errors and content loss during document conversion, and stably adapt to document format conversion and multi-type output requirements in various scenarios.
[0107] In one embodiment of the present invention, a data information acquisition module is used to identify the original format type of the source document to be converted and to acquire the document data information of the source document, including:
[0108] Extract the source document to be converted and the target output format type specified by the user;
[0109] Identify the original format type of the source document to be converted, and retrieve the document parser corresponding to the original format type;
[0110] The document parser is used to perform structured parsing on the source document to be converted to obtain the document data information of the source document; wherein, the document data information includes the text content data, style attribute data, and hierarchical structure data of the source document to be converted.
[0111] Similarly, the document parser provides a unified parsing interface, and its input and output specifications are consistent with those described in the aforementioned method embodiments.
[0112] This embodiment first reads and extracts the source document to be converted and the target output format information set by the user, and determines the original format type of the source document through a format recognition mechanism. Based on the identified original format type, a matching dedicated document parser is invoked, and corresponding parsing rules are applied for different format documents to perform structured decomposition processing of the source document. The dedicated parser completes comprehensive document parsing, accurately extracting and collecting the text content data, style attribute data, and hierarchical structure data of the source document, and completely retaining all the core data and layout structure information of the source document, providing complete and accurate original data support for subsequent document format conversion processing.
[0113] In this embodiment, dedicated parsers are configured for different original document formats, overcoming the limitation of single-adaptability issues of general parsers and adapting to more types of source document parsing scenarios. The structured parsing approach accurately splits and completely preserves the document's text, style, and hierarchical structure data, avoiding data omissions and attribute loss during parsing. A unified data extraction dimension enables standardized aggregation of various source document data, providing a well-organized and complete data foundation for subsequent document model mapping and format rendering, ensuring the orderly conduct of subsequent format conversion work.
[0114] In one embodiment of the present invention, a model update and engine determination module is used to map the document data information to a preset intermediate document object model, update the intermediate document object model, and determine the target rendering engine, including:
[0115] Extract the document data information of the source document to be converted, and map the document data information to a preset intermediate document object model. The intermediate document object model is stored in a tree structure, and the node types of the tree structure include at least document root node, chapter node, paragraph node, text execution node, table node, graphic node and style attribute node. Each node contains a set of key-value pairs that represent its original attribute parameters in the source document.
[0116] Traverse the mapped intermediate document object model, extract the effective absolute style values of each document node in the mapped intermediate document object model, and update the effective absolute style values of each document node to the attribute set corresponding to each document node to generate the updated intermediate document object model.
[0117] Based on the target output format type specified by the user, the corresponding target rendering engine is selected from multiple preset format rendering engines.
[0118] The specific implementation details, such as node data structure and absolute style value calculation rules, are completely consistent with the corresponding descriptions in the aforementioned method embodiments, and will not be repeated here.
[0119] In this embodiment, the various data information of the parsed document are mapped to a preset tree-structured intermediate document object model. This model covers the overall structure of the document and various element attributes through multiple types of nodes, and records the original attribute parameters of each node in a key-value pair set, realizing the structured loading of the full data and structure of the source document. By traversing the mapped intermediate document object model, the actual effective absolute style values of each node are extracted, and these style values are synchronously updated to the attribute set of the corresponding node, completing the calibration and iteration of the model data. Finally, according to the target output format type preset by the user, the corresponding engine is matched among the various format rendering engines pre-configured by the system to complete the selection of subsequent rendering processing units.
[0120] In this embodiment, the tree-structured intermediate document object model can fully cover the hierarchical structure and diverse element types of documents, adapting to document data input with different structures and content. The key-value pair storage structure associated with each node can completely retain the original document attribute parameters, ensuring that the source document data does not lose structure or attributes during the model mapping stage. By uniformly updating the absolute style values of nodes, the data standard within the model is unified, eliminating adaptation deviations caused by relative parameters of the original document styles. By matching the output format to the corresponding rendering engine, a correspondence between the model and multiple format output channels is established, providing architectural support for the unified conversion and output of multiple document formats.
[0121] An embodiment of the present invention is used to obtain a target format output file based on the target output format type of the source document to be converted, using the target rendering engine and the updated intermediate document object model, including:
[0122] Determine the target output format type of the source document to be converted and obtain the determination result, wherein the target output format type includes a fluid layout format and a fixed layout format;
[0123] When the judgment result indicates that the target output format type of the source document to be converted belongs to the streaming layout format, the target rendering engine is controlled to read the updated intermediate document object model, traverse each document node in the updated intermediate document object model, and map each document node to the markup language elements and attributes corresponding to the streaming layout format according to the updated absolute style values in each document node in the traversal order of the tree structure, and serialize and generate the streaming layout format output file.
[0124] If the determination result indicates that the target output format type belongs to a fixed layout format, then the target rendering engine is controlled to read the updated intermediate document object model, traverse each document node in the updated intermediate document object model, use the updated absolute style values and hierarchical structure data in each document node to perform page layout calculation, obtain the absolute coordinate position and pagination information of each document node on the physical page, and use the absolute coordinate position and pagination information to draw the corresponding content of each document node into the page content stream of the fixed layout format, generating a fixed layout format output file.
[0125] The unified interface of the rendering engine and its specific functional implementation are consistent with the description in the aforementioned method embodiments.
[0126] In this embodiment, firstly, the target output format type set by the user is determined, distinguishing between two output scenarios: fluid layout format and fixed layout format, and executing differentiated rendering logic accordingly. For the fluid layout format, the target rendering engine reads the updated intermediate document object model, traverses all document nodes according to the tree structure, and, combined with the absolute style values stored in the nodes, converts each document node into elements and attributes of the corresponding markup language, generating a fluid layout output file through serialization. For the fixed layout format, the rendering engine reads the absolute style values and hierarchical structure data of the model nodes, completes page layout calculations, determines the absolute coordinates and pagination information of each document node in the physical page, and draws all node content to the page content stream based on this arrangement information, ultimately generating a fixed layout format output file.
[0127] This embodiment sets up independent rendering and generation logic for two mainstream document output formats, adapting to document output scenarios with different layout requirements. Differentiated rendering output is achieved based on a unified intermediate document object model, ensuring that output files of different formats can match the style and structure data after node calibration. The streaming output mode adapts to document usage scenarios requiring adaptive layout, while the fixed layout output mode restores the document's page arrangement and pagination structure. The entire output logic unifies the conversion and output process for different document formats, enriches the output types for document format conversion, and adapts to diverse document layout output needs.
[0128] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. This disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A method for lossless document format conversion and multi-format output, characterized in that, include: Identify the original format type of the source document to be converted and obtain the document data information of the source document; The document data information is mapped to a preset intermediate document object model, the intermediate document object model is updated, and the target rendering engine is determined. Based on the target output format type of the source document to be converted, the target format output file is obtained using the target rendering engine and the updated intermediate document object model.
2. The document format lossless conversion and multi-format output method according to claim 1, characterized in that, Identify the original format type of the source document to be converted and obtain the document data information of the source document, including: Extract the source document to be converted and the target output format type specified by the user; Identify the original format type of the source document to be converted, and retrieve the document parser corresponding to the original format type; The document parser is used to perform structured parsing on the source document to be converted to obtain the document data information of the source document; wherein, the document data information includes the text content data, style attribute data, and hierarchical structure data of the source document to be converted.
3. The document format lossless conversion and multi-format output method according to claim 1, characterized in that, Mapping the document data information to a preset intermediate document object model, updating the intermediate document object model, and determining the target rendering engine include: Extract the document data information of the source document to be converted, and map the document data information to a preset intermediate document object model. The intermediate document object model is stored in a tree structure, and the node types of the tree structure include at least document root node, chapter node, paragraph node, text execution node, table node, graphic node and style attribute node. Each node contains a set of key-value pairs that represent its original attribute parameters in the source document. Traverse the mapped intermediate document object model, extract the effective absolute style values of each document node in the mapped intermediate document object model, and update the effective absolute style values of each document node to the attribute set corresponding to each document node to generate the updated intermediate document object model. Based on the target output format type specified by the user, the corresponding target rendering engine is selected from multiple preset format rendering engines.
4. The document format lossless conversion and multi-format output method according to claim 1, characterized in that, Based on the target output format type of the source document to be converted, the target format output file is obtained using the target rendering engine and the updated intermediate document object model, including: Determine the target output format type of the source document to be converted and obtain the determination result, wherein the target output format type includes a fluid layout format and a fixed layout format; When the judgment result indicates that the target output format type of the source document to be converted belongs to the streaming layout format, the target rendering engine is controlled to read the updated intermediate document object model, traverse each document node in the updated intermediate document object model, and map each document node to the markup language elements and attributes corresponding to the streaming layout format according to the updated absolute style values in each document node in the traversal order of the tree structure, and serialize and generate the streaming layout format output file. If the determination result indicates that the target output format type belongs to a fixed layout format, then the target rendering engine is controlled to read the updated intermediate document object model, traverse each document node in the updated intermediate document object model, use the updated absolute style values and hierarchical structure data in each document node to perform page layout calculation, obtain the absolute coordinate position and pagination information of each document node on the physical page, and use the absolute coordinate position and pagination information to draw the corresponding content of each document node into the page content stream of the fixed layout format, generating a fixed layout format output file.
5. A lossless document format conversion and multi-format output system, characterized in that, include: The data information acquisition module is used to identify the original format type of the source document to be converted and to acquire the document data information of the source document; The model update and engine determination module is used to map the document data information to a preset intermediate document object model, update the intermediate document object model, and determine the target rendering engine. The conversion control module is used to obtain the target format output file based on the target output format type of the source document to be converted, using the target rendering engine and the updated intermediate document object model.
6. The document format lossless conversion and multi-format output system according to claim 5, characterized in that, The data information acquisition module is used to identify the original format type of the source document to be converted and to acquire the document data information of the source document, including: Extract the source document to be converted and the target output format type specified by the user; Identify the original format type of the source document to be converted, and retrieve the document parser corresponding to the original format type; The document parser is used to perform structured parsing on the source document to be converted to obtain the document data information of the source document; wherein, the document data information includes the text content data, style attribute data, and hierarchical structure data of the source document to be converted.
7. The document format lossless conversion and multi-format output system according to claim 5, characterized in that, The model update and engine determination module is used to map the document data information to a preset intermediate document object model, update the intermediate document object model, and determine the target rendering engine, including: Extract the document data information of the source document to be converted, and map the document data information to a preset intermediate document object model. The intermediate document object model is stored in a tree structure, and the node types of the tree structure include at least document root node, chapter node, paragraph node, text execution node, table node, graphic node and style attribute node. Each node contains a set of key-value pairs that represent its original attribute parameters in the source document. Traverse the mapped intermediate document object model, extract the effective absolute style values of each document node in the mapped intermediate document object model, and update the effective absolute style values of each document node to the attribute set corresponding to each document node to generate the updated intermediate document object model. Based on the target output format type specified by the user, the corresponding target rendering engine is selected from multiple preset format rendering engines.
8. The document format lossless conversion and multi-format output system according to claim 5, characterized in that, The conversion control module is used to obtain the target format output file based on the target output format type of the source document to be converted, using the target rendering engine and the updated intermediate document object model, including: Determine the target output format type of the source document to be converted and obtain the determination result, wherein the target output format type includes a fluid layout format and a fixed layout format; When the judgment result indicates that the target output format type of the source document to be converted belongs to the streaming layout format, the target rendering engine is controlled to read the updated intermediate document object model, traverse each document node in the updated intermediate document object model, and map each document node to the markup language elements and attributes corresponding to the streaming layout format according to the updated absolute style values in each document node in the traversal order of the tree structure, and serialize and generate the streaming layout format output file. If the determination result indicates that the target output format type belongs to a fixed layout format, then the target rendering engine is controlled to read the updated intermediate document object model, traverse each document node in the updated intermediate document object model, use the updated absolute style values and hierarchical structure data in each document node to perform page layout calculation, obtain the absolute coordinate position and pagination information of each document node on the physical page, and use the absolute coordinate position and pagination information to draw the corresponding content of each document node into the page content stream of the fixed layout format, generating a fixed layout format output file.
