A method and system for cross-format document page replacement based on dynamic metadata mapping
By constructing a three-dimensional metadata model and applying a dual-channel replacement mechanism of convolutional neural networks and generative adversarial networks, the problems of format fidelity and dynamic element updates in Word to PDF page replacement are solved, achieving efficient, logically and visually consistent document replacement results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ADVANCED SYST DEV
- Filing Date
- 2025-08-28
- Publication Date
- 2026-05-05
AI Technical Summary
Existing technologies cannot simultaneously meet the requirements of format preservation, efficient processing, and dynamic element updates when handling specified page replacement after converting Word to PDF.
A three-dimensional metadata model is constructed, a dual-channel replacement mechanism and a multi-dimensional verification system are adopted, and style migration is performed by combining convolutional neural networks and generative adversarial networks. An incremental update strategy and cross-page element continuation technology are used to ensure the consistency of the replaced content with the original page style and the integrity of the document.
It enables efficient and accurate cross-format document page replacement, ensuring logical and visual consistency of the replaced document, improving processing efficiency and guaranteeing document quality.
Smart Images

Figure CN121092746B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer application technology, and in particular to a method and system for cross-format document page replacement based on dynamic metadata mapping. Background Technology
[0002] In document processing, it is often necessary to replace pages in documents that have been converted to PDF format. Currently, existing technologies for this purpose have several shortcomings:
[0003] Traditional PDF editing software, such as Adobe Acrobat, can perform simple page replacements in PDFs, but this replacement is merely a physical operation, directly overwriting the original page content. It cannot recognize and preserve the complex layout information of the original document, such as precise text formatting, paragraph styles, and the wrapping relationships between images and text, resulting in severe distortion of the formatting of the replaced document. When processing documents containing multiple elements, font, font size, line spacing, and other styles often become disordered, greatly affecting the document's aesthetics and professionalism.
[0004] Text extraction-based replacement methods: These methods first extract text information from the PDF using OCR technology, then edit the text, and finally regenerate the PDF document. However, this method performs poorly with complex document layouts, such as multi-column layouts and mixed text and chart layouts. It cannot accurately restore the original document's layout structure, and it cannot automatically update dynamic elements in the PDF, such as page numbers and table of contents, requiring manual adjustments, which is cumbersome and prone to errors.
[0005] General document conversion tools: Taking LibreOffice as an example, replacing pages in a PDF usually requires re-rendering the entire document. This full document reconstruction method is not only extremely inefficient and time-consuming when processing documents with a large number of pages, but also struggles to achieve accurate mapping of Word to PDF styles during cross-format conversion, failing to meet users' requirements for document format consistency.
[0006] Existing technology CN106294493B discloses a method for document format conversion, comprising: loading a Word document; converting the loaded Word document into a web page document; converting tags in the web page document into native tags, and converting style attributes in the tags into extended tags according to a pre-stored correspondence between style attributes and extended tags to obtain a Markdown document; wherein the Markdown document retains the style effects corresponding to the style attributes in the web page document; and parsing the Markdown document using a lexical parser according to the correspondence between extended tags and style attributes in a rule sequence to restore the Markdown document to a web page document. However, this method, on the one hand, does not introduce an algorithm, resulting in low processing efficiency and difficulty in achieving high-efficiency file format conversion; on the other hand, it lacks a checking mechanism, making it difficult to guarantee the quality of the converted file and achieve high-fidelity file conversion.
[0007] In conclusion, existing technologies cannot simultaneously address the needs of format preservation, efficient processing, and dynamic element updates when dealing with the issue of replacing specified pages after converting Word to PDF.
[0008] Therefore, there is an urgent need to provide a method and system for replacing cross-format document pages based on dynamic metadata mapping, which, compared with existing technologies, simultaneously meets the needs of format fidelity, efficient processing, and dynamic element updates. Summary of the Invention
[0009] This invention addresses the technical problems existing in the prior art and provides a method and system for replacing cross-format document pages based on dynamic metadata mapping.
[0010] To achieve the above objectives, the technical solution adopted by the present invention is as follows:
[0011] The method for replacing cross-format document pages based on dynamic metadata mapping includes the following steps:
[0012] S1. Construct a three-dimensional metadata model and use it to perform multi-dimensional document structure parsing. The three-dimensional metadata model includes a content topology layer, a dynamic element layer, and a style rule library.
[0013] S2. A dual-channel replacement mechanism is adopted, which uses physical channels and logical channels, combined with the results parsed in step S1, to collaboratively complete the page replacement operation and obtain the document with the page replacement completed.
[0014] S3. For documents where page replacement has been completed, use a page number update algorithm to track page number reference relationships and use cross-page element automatic continuation technology to achieve automatic continuation of cross-page elements.
[0015] S4. Establish a three-dimensional verification system to ensure the accuracy of page replacement and the quality of the replaced document from different levels.
[0016] Furthermore, the content topology layer in step S1 uses a Computer Logic Tree (CTL) to record the absolute coordinates, font attributes, and paragraph styles of text and images in the document.
[0017] Furthermore, the dynamic elements in step S1 used the DEL element in Python for tracking algorithms that locate header, footer, and table of contents items.
[0018] Furthermore, the style rule library in step S1 is used to store document-level style inheritance relationships, including style inheritance between different levels of Heading 1, Heading 2, and body text, as well as exception styles.
[0019] Furthermore, in step S2, the page replacement operation is completed through physical channels and logical channels, using a style migration algorithm. The physical channel performs underlying page replacement based on the PDFBox open-source library. The logical channel uses metadata reverse engineering, combined with the constructed three-dimensional metadata model, to reconstruct the layout constraints of the target page.
[0020] Furthermore, the style transfer algorithm in step S2 specifically includes the following steps:
[0021] S21. Using a CNN convolutional neural network, extract style features from the data obtained from the content topology layer of the target page, including font, color, and layout style.
[0022] S22. By generating a GAN adversarial network, the style of the newly replaced content is adjusted to match the style of the target page.
[0023] S23. Using the constraint satisfaction algorithm, the CSS_Optimizer module is called to perform rule verification and format fine-tuning on the generated content according to the CSS style rules defined in the style rule library. The style features are mapped to CSS style instructions that conform to the PDF typesetting specifications, ensuring that the final content is completely consistent with the original page in terms of font, paragraph, spacing, and alignment.
[0024] Furthermore, in step S3, the specific method for the page number update algorithm to track page number reference relationships is as follows: after the page replacement operation is completed, an incremental rearrangement strategy is adopted to determine the pages affected by the page replacement operation and update the page numbers of these pages.
[0025] Furthermore, in step S3, the specific method for automatic continuation of cross-page elements is as follows: for the detected cross-page elements, a breakpoint detection algorithm is applied to segment and process the replacement content to achieve automatic continuation.
[0026] Furthermore, the three-dimensional verification system in step S4 includes physical layer verification, logical layer verification, and visual layer verification.
[0027] Furthermore, the physical layer verification in step S4 uses the PDF / A standard for compliance checks, including physical structure and file format conformity to archiving standards.
[0028] Furthermore, the logical layer verification in step S4 verifies the integrity of the document content through metadata reconstruction, compares the metadata information before and after replacement, checks whether text and images are missing or damaged, and checks whether the logical relationships of paragraph structure and style are correct.
[0029] Furthermore, the visual layer verification in step S4 uses OpenCV's pixel-level difference analysis technology to compare the pages before and after the replacement pixel by pixel, setting an error range. When the pixel difference between the pages before and after the replacement is within the error range, the page replacement is considered to be visually consistent.
[0030] The cross-format document page replacement system based on dynamic metadata mapping includes a multi-dimensional document structure parsing module, a differential page replacement module, a dynamic element recalculation module, and a two-way verification module. The multi-dimensional document structure parsing module is used to perform step S1, the differential page replacement module is used to perform step S2, the dynamic element recalculation module is used to perform step S3, and the two-way verification module is used to perform step S4.
[0031] An electronic device, characterized by one or more processors; and a storage device for storing one or more programs, which, when executed by the one or more processors, cause the one or more processors to implement a cross-format document page replacement method based on dynamic metadata mapping.
[0032] A computer-readable program medium storing computer-readable instructions that, when executed by a processor, cause a computer to perform a cross-format document page replacement method based on dynamic metadata mapping.
[0033] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0034] (1) This invention constructs an innovative metadata model, which is a three-dimensional metadata model containing a content topology layer (CTL), a dynamic element layer (DEL), and a style rule base (SRB). It comprehensively records document information, provides a data foundation for subsequent accurate replacement and dynamic element processing, and breaks through the limitations of traditional document processing in terms of insufficient utilization of metadata.
[0035] (2) This invention applies cross-domain technology integration, applying convolutional neural networks (CNN) and generative adversarial networks (GAN) in the field of computer vision to document style migration, solving the problem of cross-document style compatibility and realizing automatic adaptation of replacement content to the original page style.
[0036] (3) This invention uses an efficient incremental update strategy and proposes a local update algorithm based on the page influence domain. By constructing a page dependency graph (PDG) and adopting an incremental reordering strategy, the time complexity of traditional full document reconstruction is reduced from O(n) to O(1) (single page replacement scenario), which significantly improves the processing efficiency.
[0037] (4) This invention establishes a multi-dimensional verification system, innovatively integrating digital document verification and image comparison technologies to establish a three-dimensional verification system of physical, logical and visual layers, ensuring the dual consistency of replacement operations at the logical and visual levels, and effectively guaranteeing document quality. Attached Figure Description
[0038] Figure 1 This is a flowchart of the method of the present invention.
[0039] Figure 2 This is a flowchart of the style migration algorithm in the method of this invention. Detailed Implementation
[0040] The technical solution of the present invention will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are not all embodiments of the present invention. All other embodiments obtained by those skilled in the art without creative effort are within the protection scope of the present invention.
[0041] Example 1
[0042] like Figure 1 As shown, this embodiment provides a method for replacing cross-format document pages based on dynamic metadata mapping, including the following steps:
[0043] S1. Construct a three-dimensional metadata model and use it for multi-dimensional document structure parsing. The three-dimensional metadata model includes a content topology layer (computer logic tree CTL), a dynamic element layer (DEL elements in Python), and a style rule library (SRB).
[0044] The content topology layer records the absolute coordinates of text and images in the document, down to their exact location on the page; it records detailed font attributes, including font name, size, color, bold, italics, and other styles; and paragraph styles, such as alignment (left, center, right, etc.), indentation, and line spacing. This information allows for precise location and description of the position and style characteristics of each content element on the page.
[0045] The dynamic element layer is used to track the positioning algorithms for headers, footers, and table of contents items. For example, it can accurately identify the differences between odd and even page header and footer settings and record the corresponding positioning rules; at the same time, it is also responsible for recording page number generation rules, including the starting page number, page number format, and the relationship between the page number and the document chapters.
[0046] The style rule library is used to store document-level style inheritance relationships, such as style inheritance between different levels like Heading 1, Heading 2, and Body Text, and how the font, font size, and other styles of Heading 1 affect the style settings of Heading 2 and Body Text. In addition, it will mark abnormal styles, that is, local style modifications that do not conform to the normal inheritance relationship, so that they can be accurately handled when the page is replaced later.
[0047] S2. A dual-channel replacement mechanism is adopted, which completes the page replacement operation through the collaboration of physical and logical channels.
[0048] Physical Channel: Low-level page replacement is performed using the open-source library PDFBox. PDFBox provides access to and manipulation capabilities of the underlying structure of PDF documents, allowing direct page replacement within a PDF file, ensuring that the new page is successfully embedded into the target PDF document at the physical level.
[0049] Logical Path: Using metadata reverse engineering, the layout constraints of the target page are reconstructed based on the previously constructed 3D metadata model. For example, based on the text and image coordinates and paragraph styles recorded in the CTL, as well as the style rules in the SRB, the logical layout information such as page margins, column layout, and element spacing is reconstructed to ensure that the replaced page maintains consistency with the original page in terms of logical layout.
[0050] Style migration algorithm:
[0051] Def style_transfer(new_content,target_page_metadata):
[0052] # Extracting target page style features based on convolutional neural networks
[0053] style_features=CNN_Extractor(target_page_metadata['CTL'])
[0054] #Using Generative Adversarial Networks for Content Style Adaptation
[0055] generated= GAN_Adapter(new_content,style_features)
[0056] # Apply constraint satisfaction algorithm to ensure format compliance
[0057] Retur nCSS_Optimizer(generated,target_page_metadata['SRB'])
[0058] The specific method for step S2 is as follows: Figure 2 As shown, specifically:
[0059] S21. Use a convolutional neural network (CNN) to extract unique style features from the content topology layer (CTL) data of the target page. These features cover font, color, typography style, etc.
[0060] S22. By using a generative adversarial network (GAN), the style of the newly replaced content is adjusted to match the style of the target page, so that the new content visually blends with the original page.
[0061] S23. Using the constraint satisfaction algorithm, the CSS_Optimizer module is called to perform rule verification and format fine-tuning on the generated content based on the CSS style rules defined in the Style Rules Library (SRB) (such as font inheritance, paragraph spacing, margin constraints, list indentation, etc.). The style features are mapped to CSS style instructions that conform to PDF typesetting specifications, ensuring that the final content is completely consistent with the original page in terms of font, paragraph, spacing, alignment, etc., achieving high-fidelity restoration.
[0062] S3. For documents where page replacement has been completed, use a page number update algorithm to track page number references and use cross-page element automatic continuation technology to identify cross-page situations of elements such as tables and icons, ensuring automatic continuation of cross-page elements and guaranteeing the integrity and coherence of the document.
[0063] Page number update algorithm: A page dependency graph (PDG) is constructed to track page number reference relationships, such as the correspondence between table of contents items and specific page numbers. After a page replacement operation, an incremental reordering strategy is adopted. The system intelligently determines which pages are affected by the replacement operation and only updates the page numbers of these affected page ranges, instead of recalculating the page numbers of the entire document as in traditional methods. This greatly improves the update efficiency, reducing the time complexity from the traditional O(n) to O(1) in single-page replacement scenarios.
[0064] Automatic continuation technology for cross-page elements: This technology utilizes data from the Content Topology Layer (CTL) to identify cross-page situations for elements such as tables and charts. Once a cross-page element is detected, a breakpoint detection algorithm is applied to intelligently segment and process the replacement content, ensuring that the cross-page element can automatically continue after the page is replaced, maintaining its integrity and continuity, and avoiding content breaks or display anomalies.
[0065] S4. Establish a three-dimensional verification system to ensure the accuracy of page replacement and document quality from different levels. The three-dimensional verification system includes physical layer verification, logical layer verification and visual layer verification.
[0066] Physical layer verification: Compliance checks are performed according to the PDF / A standard to ensure that the replaced PDF document conforms to archiving standards in terms of physical structure and file format, thus guaranteeing the long-term readability and compatibility of the document.
[0067] Logical layer verification: This verifies the integrity of the document content through metadata reconstruction. It compares the metadata information before and after replacement to check for missing or damaged text, images, and other content, and to verify the correctness of paragraph structure, styles, and other logical relationships.
[0068] Visual layer verification: Based on OpenCV's pixel-level difference analysis technology, the page before and after replacement is compared pixel by pixel to detect visual consistency. An acceptable error range is set (e.g., error <1%). If the difference is within this range, the page replacement is considered visually successful, ensuring that users will not perceive any obvious differences when viewing the document.
[0069] Example 2
[0070] This embodiment provides a cross-format document page replacement system based on dynamic metadata mapping, including a multi-dimensional document structure parsing module, a differential page replacement module, a dynamic element recalculation module, and a two-way verification module. The multi-dimensional document structure parsing module is used to execute step S1 in embodiment 1, the differential page replacement module is used to execute step S2 in embodiment 1, the dynamic element recalculation module is used to execute step S3 in embodiment 1, and the two-way verification module is used to execute step S4 in embodiment 1.
[0071] Example 3
[0072] An electronic device includes: one or more processors; and a storage device for storing one or more programs, which, when executed by the one or more processors, cause the one or more processors to implement the cross-format document page replacement method based on dynamic metadata mapping as described in Embodiment 1.
[0073] Example 4
[0074] A computer-readable program medium storing computer-readable instructions that, when executed by a processor, cause a computer to perform the cross-format document page replacement method based on dynamic metadata mapping as described in Embodiment 1.
[0075] Example 4
[0076] A 500-page technical document has been converted from Word to PDF format. Now, the content on page 100 needs to be replaced. The specific steps are as follows:
[0077] 1. Multi-dimensional document structure analysis: When converting Word to PDF, the system has already synchronously built a three-dimensional metadata model. Through the Content Topology Layer (CTL), information such as the precise position, font, and paragraph style of text and images on page 100 can be obtained; the Dynamic Elements Layer (DEL) records the page number generation rules of this page in the entire document and its association with headers, footers, and tables of contents; the Style Rules Base (SRB) stores the document's style inheritance relationships and any abnormal styles that may exist on this page.
[0078] 2. Differential Page Replacement Engine: In the physical channel, the PDFBox library is used to replace the physical data of the original page with the new content of page 100. In the logical channel, the layout constraints of page 100, such as margins and columns, are reconstructed based on the 3D metadata model. For style migration, the new content and target page metadata are input into the style migration algorithm. The target page style features are extracted by CNN, style is adapted by GAN, and then the CSS_Optimizer combined with SRB optimizes the format so that the new content is consistent with the original page in style.
[0079] 3. Dynamic Element Recalculation System: Utilizing a Page Dependency Graph (PDG), the system determines that replacing page 100 only affects a subset of pages starting from page 100 and related table of contents items. An incremental reflow strategy is employed, recalculating page numbers only for these affected pages. Furthermore, if page 100 contains tables or charts spanning multiple pages, the system identifies these spanning situations based on CTL data and processes the replacement content using a breakpoint detection algorithm to ensure automatic continuation of cross-page elements.
[0080] Two-way verification mechanism: At the physical layer, the document after replacement is checked for compliance according to the PDF / A standard; at the logical layer, the integrity of page 100 and related content is verified by reconstructing metadata; at the visual layer, OpenCV is used to perform pixel-level difference analysis on page 100 before and after replacement. If the error is within the allowable range (e.g., <1%), the entire replacement operation is successful and the final PDF document is output.
[0081] This invention constructs an innovative metadata model, which is a three-dimensional metadata model containing a Content Topology Layer (CTL), a Dynamic Element Layer (DEL), and a Style Rule Base (SRB). It comprehensively records document information, providing a data foundation for subsequent accurate replacement and dynamic element processing, and breaking through the limitations of traditional document processing in terms of insufficient utilization of metadata.
[0082] This invention applies cross-domain technology integration, combining convolutional neural networks (CNN) and generative adversarial networks (GAN) from the field of computer vision to document style migration, solving the problem of cross-document style compatibility and achieving automatic adaptation of replaced content to the original page style.
[0083] This invention employs an efficient incremental update strategy and proposes a local update algorithm based on the page influence domain. By constructing a page dependency graph (PDG) and adopting an incremental reordering strategy, the time complexity of traditional full document reconstruction is reduced from O(n) to O(1) (single-page replacement scenario), significantly improving processing efficiency.
[0084] This invention establishes a multi-dimensional verification system that innovatively integrates digital document verification and image comparison technologies to create a three-dimensional verification system encompassing the physical, logical, and visual layers. This ensures the dual consistency of replacement operations at both the logical and visual levels, effectively guaranteeing document quality.
[0085] Finally, it should be noted that the above content is only used to illustrate the technical solution of the present invention, and is not intended to limit the scope of protection of the present invention. Simple modifications or equivalent substitutions made by those skilled in the art to the technical solution of the present invention do not depart from the essence and scope of the technical solution of the present invention.
Claims
1. A method for replacing cross-format document pages based on dynamic metadata mapping, characterized in that, Includes the following steps: S1. Construct a three-dimensional metadata model and use it to perform multi-dimensional document structure parsing. The three-dimensional metadata model includes a content topology layer, a dynamic element layer, and a style rule library. S2. A dual-channel replacement mechanism is adopted, which uses physical channels and logical channels, combined with the results parsed in step S1, to complete the page replacement operation and obtain the document with the page replacement completed. Specifically, the page replacement operation is completed through physical channels and logical channels, and a style migration algorithm is used. The physical channel is based on the PDFBox open source library for underlying page replacement. The logical channel uses metadata reverse engineering and the constructed three-dimensional metadata model to reconstruct the layout constraints of the target page. The style migration algorithm specifically includes the following steps: S21. Using a CNN convolutional neural network, extract style features from the data obtained from the content topology layer of the target page, including font, color, and layout style. S22. By generating a GAN adversarial network, the style of the newly replaced content is adjusted to match the style of the target page. S23. Using the constraint satisfaction algorithm, the CSS_Optimizer module is called to perform rule verification and format fine-tuning on the generated content according to the CSS style rules defined in the style rule library. The style features are mapped to CSS style instructions that conform to the PDF typesetting specifications, ensuring that the final content is completely consistent with the original page in terms of font, paragraph, spacing, and alignment. S3. For documents where page replacement has been completed, use a page number update algorithm to track page number reference relationships and use cross-page element auto-continuation technology to achieve automatic continuation of cross-page elements. S4. Establish a three-dimensional verification system to ensure the accuracy of page replacement and the quality of the replaced document from different levels; the three-dimensional verification system includes physical layer verification, logical layer verification and visual layer verification.
2. The method for cross-format document page replacement based on dynamic metadata mapping according to claim 1, characterized in that, The content topology layer in step S1 uses a Computer Logic Tree (CTL) to record the absolute coordinates, font attributes, and paragraph styles of text and images in the document.
3. The method for cross-format document page replacement based on dynamic metadata mapping according to claim 1, characterized in that, The dynamic element layer in step S1 includes algorithms for locating headers, footers, and table of contents items.
4. The method for cross-format document page replacement based on dynamic metadata mapping according to claim 1, characterized in that, The style rule library in step S1 is used to store document-level style inheritance relationships, including style inheritance between different levels of Heading 1, Heading 2, and body text, as well as exception styles.
5. The method for cross-format document page replacement based on dynamic metadata mapping according to claim 1, characterized in that, In step S3, the specific method for the page number update algorithm to track page number reference relationships is as follows: after the page replacement operation is completed, an incremental rearrangement strategy is adopted to determine the pages affected by the page replacement operation and update the page numbers of these pages.
6. The method for cross-format document page replacement based on dynamic metadata mapping according to claim 1, characterized in that, In step S3, the specific method of automatic continuation technology for cross-page elements is as follows: for the detected cross-page elements, a breakpoint detection algorithm is applied to segment and process the replacement content to achieve automatic continuation.
7. The method for cross-format document page replacement based on dynamic metadata mapping according to claim 1, characterized in that, The physical layer verification in step S4 uses the PDF / A standard for compliance checks, including physical structure and file format conformity to archiving standards.
8. The method for cross-format document page replacement based on dynamic metadata mapping according to claim 1, characterized in that, The logical layer verification in step S4 verifies the integrity of the document content through metadata reconstruction. It compares the metadata information before and after replacement, checks whether text and images are missing or damaged, and checks whether the logical relationships of paragraph structure and style are correct.
9. The method for cross-format document page replacement based on dynamic metadata mapping according to claim 1, characterized in that, The visual layer verification in step S4 uses OpenCV's pixel-level difference analysis technology to compare the pages before and after the replacement pixel by pixel. An error range is set, and if the pixel difference between the pages before and after the replacement is within the error range, the page replacement is considered to be visually consistent.
10. A cross-format document page replacement system based on dynamic metadata mapping, characterized in that, The method for cross-format document page replacement based on dynamic metadata mapping, as described in any one of claims 1-9, includes a multi-dimensional document structure parsing module, a differential page replacement module, a dynamic element recalculation module, and a two-way verification module. The multi-dimensional document structure parsing module is used to perform step S1, the differential page replacement module is used to perform step S2, the dynamic element recalculation module is used to perform step S3, and the two-way verification module is used to perform step S4.
11. An electronic device, characterized in that, include: One or more processors; A storage device for storing one or more programs, which, when executed by one or more processors, cause the one or more processors to implement the cross-format document page replacement method based on dynamic metadata mapping as described in any one of claims 1-9.
12. A computer-readable program medium, characterized in that, It stores computer-readable instructions that, when executed by a processor, cause the computer to perform the cross-format document page replacement method based on dynamic metadata mapping as described in any one of claims 1-9.
Citation Information
Patent Citations
Methods and apparatus for document format conversion
CN106294493B
PDF (Portable Document Format) conversion multiplexing method and device, computer equipment and storage medium
CN120373260A
File conversion method, device, equipment and program product
CN120471022A