Multi-dimensional comparison method, device and electronic equipment for PDF document

By employing a multi-dimensional comparison method and utilizing a deep learning model to segment and parse the object regions of PDF documents, this approach addresses the problem of neglecting multi-dimensional differences in existing technologies, enabling efficient and accurate comparison and difference annotation of PDF documents.

CN119514518BActive Publication Date: 2026-04-07BEIJING RENHE HUIZHI INFORMATION TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-21
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

Existing PDF document comparison technologies mainly focus on text content, ignoring differences in multiple dimensions such as images, tables, mathematical formulas, paragraph layout, fonts, and page structure. This results in low efficiency and insufficient accuracy when processing complex documents, failing to meet high standards.

Method used

A multi-dimensional comparison method is adopted, which uses a deep learning model to divide the PDF document into multiple object regions, including text, images, tables and mathematical formula regions, and performs parsing and comparison to determine the difference information, and simultaneously marks the difference type and index information.

Benefits of technology

It enables comprehensive, accurate, and automated comparison of PDF documents, improving the precision and efficiency of document processing and meeting the needs of complex application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119514518B_ABST
    Figure CN119514518B_ABST
Patent Text Reader

Abstract

The application provides a multi-dimension comparison method and device of a PDF document and an electronic device. The method comprises: dividing a first PDF document and a second PDF document to be compared into a plurality of object regions; analyzing the plurality of object regions to obtain object content to be compared; determining, for each first object content in the first PDF document, that the first object content corresponds to second object content to be compared in the second PDF document; comparing the first object content and the second object content to determine difference information; and synchronously marking the difference type and index information of the difference information in the first PDF document and the second PDF document. The application can comprehensively, accurately and automatically compare and mark the differences in the text, image, table and formula multi-dimension content of two PDF documents, improve the accuracy and efficiency of document processing, and meet the needs of complex application scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of document processing technology, and in particular to a method, apparatus and electronic device for multi-dimensional comparison of PDF documents. Background Technology

[0002] With PDF (Portable Document Format) becoming the mainstream document format and widely used in academic, legal, and business fields, the importance of document version management and difference detection is increasingly prominent. However, existing PDF document comparison technologies mainly focus on text content, neglecting differences in multiple dimensions such as images, tables, mathematical formulas, paragraph layout, fonts, and page structure. This limitation often leads to the omission of key changes when processing complex documents, especially in high-requirement scenarios such as legal document review, academic paper version control, and contract review, which can potentially have serious consequences.

[0003] Existing technologies suffer from inefficiency and insufficient accuracy when faced with large-scale document comparison tasks, failing to meet the high standards required for modern document processing. Manual document review is not only time-consuming and labor-intensive but also prone to errors and lacks precision. Summary of the Invention

[0004] The purpose of this application is to provide a method, apparatus, and electronic device for multi-dimensional comparison of PDF documents, which can comprehensively, accurately, and automatically compare and annotate the differences in multiple dimensions of text, images, tables, and formulas in two PDF documents, thereby improving the accuracy and efficiency of document processing and meeting the needs of complex application scenarios.

[0005] Firstly, this application provides a multi-dimensional comparison method for PDF documents. The method includes: dividing both a first PDF document and a second PDF document to be compared into multiple object regions; the multiple object regions include at least one of the following: text region, image region, table region, and mathematical formula region; parsing the multiple object regions to obtain the object content to be compared; determining that each first object content in the first PDF document corresponds to a second object content to be compared in the second PDF document; comparing the first object content and the second object content to determine the difference information; and simultaneously marking the difference type and index information of the difference information in the first PDF document and the second PDF document.

[0006] Furthermore, the steps described above for parsing multiple object regions to obtain the object content to be compared include: extracting the text content from the text region; merging adjacent text content distributed in different columns or spanning multiple pages when they are determined to be the same paragraph to obtain the text content to be compared.

[0007] Furthermore, the step of determining that the first object content corresponds to the second object content to be compared in the second PDF document includes: determining the target object content in the second PDF document at the position corresponding to the first position information according to the first position information of the first object content in the first PDF document; expanding the content of a specified number of regions of the same object type forward and backward based on the target object content; calculating the similarity between the first object content and the multiple regions, and taking the region content corresponding to the highest similarity as the second object content to be compared in the second PDF document corresponding to the first object content.

[0008] Furthermore, the steps described above for comparing the content of the first object and the content of the second object to determine the difference information include: for the two text contents to be compared, performing the following text content difference analysis steps: dividing the two text contents into character units; comparing the character units of the two text contents one by one, and calculating the minimum edit distance between the two text contents; the minimum edit distance is characterized by the minimum number of editing operations required to convert one text into another text; the operations include inserting characters, deleting characters, and replacing characters; after comparing all character units, obtaining the editing operation sequence from one text content to another text content; and determining the difference information between the two text contents based on the editing operation sequence.

[0009] Furthermore, the steps described above for determining the difference information of two text contents based on the editing operation sequence include: if the editing operation type of the target comparison segment is inserting a character, determining the difference type of the target comparison segment as inserting a segment; merging multiple consecutive comparison segments of the inserting segment type to determine a first difference region; if the editing operation type of the target comparison segment is deleting a character, determining the difference type of the target comparison segment as deleting a segment; merging multiple consecutive comparison segments of the deleting segment type to determine a second difference region; if the difference type of the target comparison segment is the same segment type, comparing the font, font size, and font style of the text in the target comparison segment, and marking the target comparison segment as having the same segment type.

[0010] Furthermore, the steps described above for comparing the content of the first object and the content of the second object to determine the difference information include: for the two images to be compared, normalizing the size and resolution of the two images respectively; traversing each pixel at the same position in the two images; for each pixel, comparing the values ​​of the four channels of red, green, blue and transparency respectively; if the value of any channel is different, then the pixel is marked as different; after traversing all pixels, counting the number of different pixels between the two images; determining the similarity between the two images based on the number of different pixels; merging consecutive different pixels to determine the difference region.

[0011] Furthermore, the steps described above for comparing the content of the first object and the content of the second object to determine the difference information include: for the two formulas to be compared, obtaining the formula character information corresponding to the two formulas; aligning the formula character information according to the Y coordinate to make the vertical order of the two formula character information consistent; sorting the two formula character information according to the X coordinate and combining the formula characters into the corresponding formula text string; and performing a text content difference analysis step on the formula text string to determine the difference area and difference type.

[0012] Furthermore, the steps described above for comparing the content of the first object and the content of the second object to determine the difference information include: for the two tables to be compared, obtaining the text content in the two tables; concatenating the text content in the order of rows and / or columns to obtain the concatenated text string; and performing a text content difference analysis step on the text string to determine the difference area and difference type.

[0013] Secondly, this application also provides a multi-dimensional comparison device for PDF documents. The device includes: a document segmentation module, used to divide both the first PDF document and the second PDF document to be compared into multiple object regions; the multiple object regions include at least one of the following: text region, image region, table region, and mathematical formula region; a region parsing module, used to parse the multiple object regions to obtain the object content to be compared; a comparison content determination module, used to determine that each first object content in the first PDF document corresponds to a second object content to be compared in the second PDF document; a difference determination module, used to compare the first object content and the second object content to determine the difference information; and a difference marking module, used to simultaneously mark the difference type and index information of the difference information in the first PDF document and the second PDF document.

[0014] Thirdly, this application also provides an electronic device, including a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the method described in the first aspect above.

[0015] The multi-dimensional comparison method, apparatus, and electronic device for PDF documents provided in this application divides both the first and second PDF documents to be compared into multiple object regions. These multiple object regions include at least one of the following: text region, image region, table region, and mathematical formula region. The multiple object regions are parsed to obtain the object content to be compared. For each first object content in the first PDF document, it is determined that the first object content corresponds to the second object content to be compared in the second PDF document. The first and second object content are compared to determine the difference information. The difference type and index information of the difference information are simultaneously marked in both the first and second PDF documents. This application can comprehensively, accurately, and automatically compare and annotate the differences in text, images, tables, and formulas across multiple dimensions in two PDF documents, improving the accuracy and efficiency of document processing and meeting the needs of complex application scenarios. Attached Figure Description

[0016] To more clearly illustrate the technical solutions in the specific embodiments of this application or the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0017] Figure 1 A flowchart illustrating a multi-dimensional comparison method for PDF documents provided in this application embodiment;

[0018] Figure 2 This application provides a schematic diagram of PDF document region division as an embodiment.

[0019] Figure 3 A structural block diagram of a multi-dimensional comparison device for PDF documents provided in this application embodiment;

[0020] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0021] The technical solutions of this application will be clearly and completely described below with reference to the embodiments. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0022] To address the issues of low efficiency and insufficient accuracy in existing technologies when facing large-scale document comparison tasks, as well as the problems that manual document review is not only time-consuming and laborious but also prone to errors and lacks accuracy, this application provides a multi-dimensional PDF content comparison method that covers comprehensive analysis of text, images, tables, mathematical formulas, paragraph layout, fonts, and page structure. It is suitable for document version management, difference detection, and content review, such as legal documents, academic papers, contracts, and other scenarios that require accurate identification of alterations.

[0023] To facilitate understanding of this embodiment, a multi-dimensional PDF content comparison method disclosed in this application embodiment will first be described in detail.

[0024] Figure 1 A flowchart of a multi-dimensional comparison method for PDF documents provided in this application embodiment is shown. The method specifically includes the following steps:

[0025] Step S102: For both the first PDF document and the second PDF document to be compared, they are divided into multiple object regions; the multiple object regions include at least one of the following: text region, image region, table region, and mathematical formula region;

[0026] A finely tuned layout language model, LayoutLM, is used to perform preliminary layout analysis and segmentation of PDF documents. LayoutLM is a large language model based on deep learning, specifically designed to understand the layout and content structure of documents. Using the LayoutLM model, the PDF document is divided into multiple coarse-grained regions, including text regions, image regions, table regions, and mathematical formula regions. Each region retains its position coordinates on the page, ensuring the accuracy of subsequent processing.

[0027] Step S104: parse multiple object regions to obtain the content of the objects to be compared;

[0028] For each defined object region, the specific content within that region is extracted based on its coordinates on the page. Text regions are extracted and merged to obtain the text content to be compared; table regions are parsed to extract the tables to be compared; image regions are parsed to extract the images to be compared; and formula regions are parsed to extract the formulas to be compared.

[0029] Step S106: For each first object content in the first PDF document, determine that the first object content corresponds to the second object content to be compared in the second PDF document;

[0030] This step involves matching the objects to be compared. For each object in the first document, the corresponding object to be compared must be found in the second document. Here, a comparison range and a similarity threshold can be set. For example, the object with the highest similarity among a specified number of adjacent objects of the same type can be used as the second object to be compared with the first object.

[0031] Step S108: Compare the content of the first object and the content of the second object to determine the differences;

[0032] This step actually involves comparing elements within the specific content of the objects to accurately determine the differences between the two documents.

[0033] Step S110: In the first PDF document and the second PDF document, the difference type and index information of the difference information are marked synchronously.

[0034] By synchronizing and marking the differences, a comprehensive difference report can be generated, detailing all changes in the document.

[0035] The multi-dimensional comparison method for PDF documents provided in this application divides both the first and second PDF documents to be compared into multiple object regions. These multiple object regions include at least one of the following: text region, image region, table region, and mathematical formula region. The multiple object regions are parsed to obtain the object content to be compared. For each first object content in the first PDF document, the corresponding second object content to be compared in the second PDF document is determined. The first and second object contents are compared to determine the difference information. The difference type and index information of the difference information are simultaneously marked in both the first and second PDF documents. This application can comprehensively, accurately, and automatically compare and annotate the differences in text, images, tables, and formulas across multiple dimensions in two PDF documents, improving the accuracy and efficiency of document processing and meeting the needs of complex application scenarios.

[0036] This application also provides another method for multi-dimensional comparison of PDF documents, which is implemented based on the above embodiments; this embodiment focuses on describing the region parsing process, the comparison object matching process, and the difference analysis process of each dimension.

[0037] (1) Region resolution process:

[0038] like Figure 2 As shown, after dividing the PDF document into multiple object regions, the next step is to parse these object regions:

[0039] For a text area, extract the text content within the text area; for adjacent text content distributed in different columns or spanning multiple pages, merge the text content if it is determined to be the same paragraph to obtain the text content to be compared.

[0040] In practice, for text areas, content extraction includes obtaining character information, font type, font size, and other relevant text attributes. Based on the font size of the extracted characters and their vertical displacement relative to the baseline, it is determined whether the characters are superscripts or subscripts. Characters with smaller font sizes and significant vertical displacement are typically identified as superscripts or subscripts. The thickness and slant angle of the text are analyzed to determine whether the text is bold or italic. Specifically, by detecting the thickness and slant of the character outlines, bold and italic characters are identified and marked. This step ensures that the content information extracted from the PDF document not only accurately reflects the characters and basic attributes of the text but also includes more detailed style information, such as superscripts, subscripts, bold, and italics, laying the foundation for accurate document comparison and analysis.

[0041] Then, region correction and merging are performed: For adjacent text regions distributed across different columns, based on preset rules and natural language processing techniques, it is determined whether these regions belong to the same paragraph. If so, these text region blocks are corrected and merged. For adjacent text region blocks spanning multiple pages, the same rules and natural language processing techniques are used to analyze them, determine whether they belong to the same paragraph or sentence, and then merge them. This step ensures that the integrity of paragraphs is maintained even when the document content is split across multiple pages or columns.

[0042] The system generates a structured content representation from the merged and corrected region blocks, and outputs comprehensive information data including content text, style, location coordinates, and region type. This data will serve as the basis for subsequent content comparison and analysis.

[0043] (2) Comparison and matching process:

[0044] That is, the steps described above for determining that the content of the first object corresponds to the content of the second object to be compared in the second PDF document include:

[0045] Based on the first position information of the first object content in the first PDF document, determine the target object content in the second PDF document at the position corresponding to the first position information; based on the target object content, extend the content of a specified number of regions of the same object type forward and backward respectively; calculate the similarity between the first object content and the multiple regions, and take the region content corresponding to the highest similarity as the second object content to be compared in the second PDF document corresponding to the first object content.

[0046] In this embodiment, based on the results of the aforementioned layout analysis and content parsing, object regions in the PDF document are categorized into corresponding comparison object types for one-by-one matching. These objects include text paragraphs, tables, images, etc. The specific process is as follows:

[0047] (2.1) Text Paragraph Comparison and Matching: Before comparing text paragraphs, the text is first normalized. This includes unifying half-width and full-width punctuation marks and removing unnecessary whitespace characters. The purpose of this step is to ensure the consistency of the text content in form, thereby improving the accuracy of similarity calculation. After normalization, the text content is matched for similarity. The similarity is evaluated by calculating the cosine similarity between each pair of text paragraphs. Cosine similarity measures the degree of similarity between two paragraphs by representing the text as vectors and calculating the cosine value of the angle between the vectors. The higher the score, the more similar the content of the two paragraphs.

[0048] (2.2) Table Comparison and Matching: The table area blocks are parsed in a structured manner to extract information such as the rows, columns, cell content, and their positions. The text content of each cell is extracted row by row, and these text contents are then concatenated in row order to form a concatenated text string representing the entire table. This concatenation process preserves the content order and structural features of the table, ensuring that the overall consistency of the table content is reflected during comparison. Similarity is calculated for the concatenated text content. A cosine similarity calculation method, similar to that used in text paragraph comparison, is employed to evaluate the similarity of the text content between the two tables. By comparing the similarity of the concatenated text strings, the similarity and differences between the table content can be effectively determined.

[0049] (2.3) Image Comparison and Matching: First, the two images to be compared are normalized in size and resolution. This may include scaling or cropping the images to ensure they have the same size; it may also include adjusting the image resolution to ensure they are compared under the same standard. Then, each pixel of the image is traversed, and the pixel values ​​at the same location in both images are compared one by one. For each pixel, the values ​​of its four channels—red, green, blue, and transparency—are compared. If the value of any channel differs, the pixel is marked as different. After comparing all pixels, the difference information between the two images is counted, and the similarity percentage of the images is calculated based on the number of pixels marked as different. The higher the similarity percentage, the closer the content of the two images is.

[0050] (2.4) Matching Strategy and Threshold Settings: To avoid bias or omissions in the matching results, a threshold for the span before and after matching is set, with a default value of 20 regions. That is, during the comparison process, each match allows searching for the most similar matching object within 20 adjacent regions. When performing object matching, if the similarity is less than 60%, the content is considered newly added. In practical applications, the threshold can be adjusted according to the complexity of the document and user needs to optimize the matching effect.

[0051] (3) The process of difference analysis for each dimension:

[0052] (3.1) Text content comparison:

[0053] For the two text contents to be compared, the following text content difference analysis steps are performed: the two text contents are segmented into character units; the character units of the two text contents are compared one by one, and the minimum edit distance between the two text contents is calculated; the minimum edit distance is characterized by the minimum number of editing operations required to convert one text into another text; the operations include inserting characters, deleting characters, and replacing characters; after comparing all character units, the editing operation sequence from one text content to another text content is obtained; the difference information between the two text contents is determined based on the editing operation sequence.

[0054] Furthermore, the steps described above for determining the difference information of two text contents based on the editing operation sequence include: if the editing operation type of the target comparison segment is inserting a character, determining the difference type of the target comparison segment as inserting a segment; merging multiple consecutive comparison segments of the inserting segment type to determine a first difference region; if the editing operation type of the target comparison segment is deleting a character, determining the difference type of the target comparison segment as deleting a segment; merging multiple consecutive comparison segments of the deleting segment type to determine a second difference region; if the difference type of the target comparison segment is the same segment type, comparing the font, font size, and font style of the text in the target comparison segment, and marking the target comparison segment as having the same segment type.

[0055] In practice, the input text is first segmented into character units. Each character unit can be a letter, number, symbol, or other special character. Then, an optimized dynamic programming method is used to calculate the minimum edit distance between two texts by comparing their character units one by one. This represents the minimum number of operations required to transform one text into another. These operations include inserting characters, deleting characters, and replacing characters. Each step in the dynamic programming process records the minimum number of edit operations required to reach the current character position. By backtracking these steps, the specific sequence of edit operations from one text to another can be determined.

[0056] The comparison results can be categorized into three types: "insertion," "deletion," and "identical." For "identical" fragments, further comparison of font, size, and style is needed to ensure consistency in text style. For "insertion" and "deletion" fragments, they are merged and split based on their position in the document. Adjacent text blocks with the same type of difference are merged and pieced together to form complete difference regions, and the type of difference in these regions (insertion, deletion, or identical text content but different styles) is recorded in detail. This method accurately identifies and records the difference regions between texts, providing accurate and detailed difference information for subsequent document processing and analysis.

[0057] (3.2) Image comparison:

[0058] For the two images to be compared, normalize the size and resolution of each image; traverse each pixel at the same position in both images; for each pixel, compare the values ​​of the four channels: red, green, blue, and transparency; if the value of any channel is different, mark the pixel as different; after traversing all pixels, count the number of different pixels between the two images; determine the similarity between the two images based on the number of different pixels; merge consecutive different pixels to determine the difference region.

[0059] Differences in image resolution or size can affect the comparison results, so it is necessary to standardize the size and resolution of images.

[0060] Uniform resolution: If two images have different resolutions, select the smaller resolution as the baseline resolution and adjust the other image to that baseline resolution. This preserves all original image information and avoids blurring and distortion caused by interpolation and enlargement of the smaller image. At the same time, a smaller resolution means less computation and higher image comparison efficiency.

[0061] Standardize the size: First, compare the aspect ratios of the two images. If the aspect ratios are the same, use the smaller image as the baseline and scale the other image proportionally. If the aspect ratios are different, crop the larger image to match the smaller image's aspect ratio.

[0062] Image difference comparison uses a pixel-by-pixel comparison method to identify the differences between two images in detail. First, it iterates through each pixel position in the image, comparing the values ​​of the corresponding pixel in the four channels: red, green, blue, and transparency. For any pixel whose channel value is inconsistent, its position information is recorded to capture the difference points in the image.

[0063] Then, these differences are processed, merging consecutive differing pixels into complete difference regions. Simultaneously, these difference regions can be marked on the image, making the differences between images visually apparent. This method can accurately locate and display subtle differences in images, making it suitable for applications requiring high-precision image comparison.

[0064] (3.3) Formula comparison:

[0065] For the two formulas to be compared, obtain the corresponding formula character information; align the formula character information according to the Y coordinate to ensure that the vertical order of the two formula character information is consistent; sort the two formula character information according to the X coordinate and combine the formula characters into the corresponding formula text string; perform text content difference analysis on the formula text string to determine the difference area and difference type.

[0066] When processing character information in mathematical formulas, the characters are first sorted according to their Y-coordinates to ensure consistent vertical order. If the Y-coordinates are the same, they are further sorted by X-coordinate, combining these characters into corresponding formula text strings. Then, the aforementioned text content difference comparison algorithm is used to compare these formula text strings, thereby accurately identifying differences between formulas.

[0067] (3.4) Table comparison:

[0068] For the two tables to be compared, obtain the text content from the two tables; concatenate the text content according to the order of rows and / or columns to obtain the concatenated text string; perform text content difference analysis on the text string to determine the difference area and difference type.

[0069] When performing table difference comparison, the table is first sorted according to its structure, with rows as the primary sorting rule and columns as the secondary sorting rule. The text content of each cell is then concatenated. The concatenated text content is then compared using the aforementioned text difference comparison algorithm to identify and record the differences between the table content. This method ensures accuracy in table comparison, enabling comprehensive and accurate difference analysis of text, formulas, and table content.

[0070] (4) Distinction markers:

[0071] During the recording of text difference information, the index position of each difference segment in the corresponding comparison text can be recorded simultaneously. These index positions allow for precise location of specific difference areas within text blocks or images in the original PDF document, and the corresponding difference areas can be found in the comparison PDF document. For each identified difference area, bidirectional mapping clearly displays the differences at the same location in the two documents or images. Furthermore, the difference areas are simultaneously located and marked in both documents or images. When a user views a difference area in one document or image, the corresponding area in the other document or image is automatically located and highlighted. This bidirectional localization method ensures that users can quickly and accurately identify and analyze differences in documents or images, thus gaining a more intuitive understanding of the differences between them.

[0072] The multi-dimensional comparison method for PDF documents provided in this application first parses the PDF documents to be compared and extracts content information in each dimension; then, different algorithms are used to accurately compare elements such as text, images, tables, and mathematical formulas, while analyzing differences in paragraph layout, font changes, and page structure; finally, a comprehensive difference report is generated, which details all changes in the document.

[0073] Based on the above method embodiments, this application also provides a multi-dimensional comparison device for PDF documents, see [link to relevant documentation]. Figure 3 As shown, the device includes: a document segmentation module 302, used to divide both the first PDF document and the second PDF document to be compared into multiple object regions; the multiple object regions include at least one of the following: text region, image region, table region, and mathematical formula region; a region parsing module 304, used to parse the multiple object regions to obtain the object content to be compared; a comparison content determination module 306, used to determine that each first object content in the first PDF document corresponds to the second object content to be compared in the second PDF document; a difference determination module 308, used to compare the first object content and the second object content to determine the difference information; and a difference marking module 310, used to simultaneously mark the difference type and index information of the difference information in the first PDF document and the second PDF document.

[0074] Furthermore, the aforementioned region parsing module 304 is used to extract the text content in the text region; for adjacent text content distributed in different columns or spanning multiple pages, when it is determined to be the same paragraph, the text content is merged to obtain the text content to be compared.

[0075] Furthermore, the aforementioned comparison content determination module 306 is used to determine the target object content in the second PDF document corresponding to the first position information in the first PDF document according to the first position information of the first object content; based on the target object content, extend the content of a specified number of regions of the same object type forward and backward respectively; calculate the similarity between the first object content and the multiple regions, and take the region content corresponding to the highest similarity as the second object content to be compared in the second PDF document corresponding to the first object content.

[0076] Furthermore, the aforementioned difference determination module 308 is used to perform the following text content difference analysis steps for the two text contents to be compared: segmenting the two text contents according to character units; comparing the character units of the two text contents one by one, and calculating the minimum edit distance between the two text contents; the minimum edit distance is characterized by the minimum number of editing operations required to convert one text into another text; the operations include inserting characters, deleting characters, and replacing characters; after comparing all character units, obtaining the editing operation sequence from one text content to another text content; and determining the difference information of the two text contents based on the editing operation sequence.

[0077] Furthermore, the aforementioned difference determination module 308 is used to determine the difference type of the target comparison segment as an insertion segment type if the editing operation type of the target comparison segment is an insertion character; and to merge multiple consecutive comparison segments of the insertion segment type to determine a first difference region; if the editing operation type of the target comparison segment is a deletion character, to determine the difference type of the target comparison segment as a deletion segment type; and to merge multiple consecutive comparison segments of the deletion segment type to determine a second difference region; if the difference type of the target comparison segment is the same segment type, to compare the font, font size, and font style of the text of the target comparison segment, and to mark the target comparison segment as having the same segment type.

[0078] Furthermore, the aforementioned difference determination module 308 is used to perform size and resolution normalization processing on the two images to be compared; traverse each pixel at the same position in the two images; for each pixel, compare the values ​​of the four channels: red, green, blue, and transparency; if the value of any channel is different, then mark the pixel as different; after traversing all pixels, count the number of difference pixels between the two images; determine the similarity between the two images based on the number of difference pixels; and merge consecutive difference pixels to determine the difference region.

[0079] Furthermore, the aforementioned difference determination module 308 is used to obtain the formula character information corresponding to the two formulas to be compared; align the formula character information according to the Y coordinate to make the vertical order of the two formula character information consistent; sort the two formula character information according to the X coordinate and combine the formula characters into the corresponding formula text string; and perform a text content difference analysis step on the formula text string to determine the difference area and difference type.

[0080] Furthermore, the aforementioned difference determination module 308 is used to obtain the text content of the two tables to be compared; to concatenate the text content in the order of rows and / or columns to obtain the concatenated text string; and to perform a text content difference analysis step on the text string to determine the difference area and difference type.

[0081] The device provided in this application embodiment has the same implementation principle and technical effect as the aforementioned method embodiment. For the sake of brevity, any parts of the device embodiment not mentioned can be referred to the corresponding content in the aforementioned method embodiment.

[0082] This application also provides an electronic device, such as... Figure 4 The diagram shows the structure of the electronic device, which includes a processor 41 and a memory 40. The memory 40 stores computer-executable instructions that can be executed by the processor 41, and the processor 41 executes the computer-executable instructions to implement the above-described method.

[0083] exist Figure 4 In the illustrated embodiment, the electronic device further includes a bus 42 and a communication interface 43, wherein the processor 41, the communication interface 43, and the memory 40 are connected via the bus 42.

[0084] The memory 40 may include high-speed random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 43 (which can be wired or wireless), such as the Internet, wide area network, local area network, metropolitan area network, etc. The bus 42 may be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. The bus 42 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.

[0085] Processor 41 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 41 or by instructions in software form. Processor 41 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this application can be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in the memory, and the processor 41 reads the information in the memory and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiment.

[0086] This application also provides a computer-readable storage medium storing computer-executable instructions. When the computer-executable instructions are called and executed by a processor, the computer-executable instructions cause the processor to implement the above-described method. For specific implementation details, please refer to the foregoing method embodiments, which will not be repeated here.

[0087] The computer program products of the methods, apparatus, and electronic devices provided in the embodiments of this application include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementations, please refer to the method embodiments, which will not be repeated here.

[0088] Unless otherwise specifically stated, the relative steps, numerical expressions, and values ​​of the components and steps described in these embodiments do not limit the scope of this application.

[0089] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0090] In the description of this application, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing this application 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. Therefore, they should not be construed as limitations on this application. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0091] Finally, it should be noted that the above-described embodiments are merely specific implementations of this application, used to illustrate the technical solutions of this application, and not to limit them. The protection scope of this application is not limited thereto. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the technical scope disclosed in this application. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be covered within the protection scope of this application. Therefore, the protection scope of this application should be determined by the protection scope of the claims.

Claims

1. A multi-dimensional comparison method for PDF documents, characterized in that, The method includes: For both the first and second PDF documents to be compared, they are divided into multiple object regions; the multiple object regions include at least one of the following: text region, image region, table region, and mathematical formula region; Multiple object regions are parsed to obtain the object content to be compared, including: for each divided object region, the specific content within the object region is extracted based on the coordinate information of the object region on the page; the text region is parsed and merged to obtain the text content to be compared; the table region is parsed to obtain the table to be compared; the image region is parsed to obtain the image to be compared; and the formula region is parsed to obtain the formula to be compared. The LayoutLM layout language model, which has been fine-tuned, is used to perform preliminary layout analysis and segmentation of PDF documents. Based on the font size of the extracted characters and their vertical displacement relative to the baseline, determine whether the characters are subscripts or superscripts; determine whether the text is bold or italic by analyzing the thickness and slant angle of the text. For adjacent text areas distributed across different columns, based on preset rules and natural language processing technology, it is determined whether these areas belong to the same paragraph; if so, these text area blocks are corrected and merged; for adjacent text area blocks spanning multiple pages, the same rules and natural language processing technology are used to analyze whether they belong to the same paragraph or sentence, and then they are merged. For each first object content in the first PDF document, determining the corresponding second object content to be compared in the second PDF document includes: determining the target object content in the second PDF document at the position corresponding to the first position information in the first PDF document according to the first position information of the first object content; expanding the content of the same object type forward and backward by a specified number of regions based on the target object content; calculating the similarity between the first object content and the multiple regions, and taking the region content corresponding to the highest similarity as the second object content to be compared in the second PDF document corresponding to the first object content; The contents of the first object and the contents of the second object are compared to determine the differences. In both the first and second PDF documents, the difference types and index information of the difference information are simultaneously marked; the index position of each difference fragment in the corresponding comparison text is recorded; through these index positions, the specific difference region in the text block or image in the original PDF document can be accurately located, and the corresponding difference region can be found in the comparison PDF document; for each identified difference region, through bidirectional mapping, the difference at the same position in the two documents or images can be clearly displayed; in addition, the difference region is simultaneously located and marked in the two documents or images; when a user views a certain difference region in one document or image, the corresponding region in the other document or image will be automatically located and highlighted; The step of comparing the content of the first object and the content of the second object to determine the differences includes: For two text contents to be compared, the following text content difference analysis steps are performed: The two text contents are segmented into character units; the character units of the two text contents are compared one by one to calculate the minimum edit distance between the two text contents; the minimum edit distance is characterized by the minimum number of editing operations required to convert one text into another; the operations include inserting characters, deleting characters, and replacing characters; after comparing all character units, an editing operation sequence from one text content to another is obtained; the difference information of the two text contents is determined based on the editing operation sequence, including: if the editing operation type of the target comparison segment is inserting characters, the difference type of the target comparison segment is determined to be an insert segment type; multiple consecutive insertion segment type comparison segments are merged to determine a first difference region; if the editing operation type of the target comparison segment is deleting characters, the difference type of the target comparison segment is determined to be a deletion segment type; multiple consecutive deletion segment type comparison segments are merged to determine a second difference region; if the difference type of the target comparison segments is the same segment type, the font, font size, and font shape of the text in the target comparison segment are compared, and the target comparison segment is marked as having the same segment type. For the two images to be compared, the size and resolution of each image are normalized. Each pixel at the same location in both images is traversed. For each pixel, the values ​​of the four channels (red, green, blue, and transparency) are compared. If any channel value differs, the pixel is marked as different. After traversing all pixels, the number of differing pixels between the two images is counted. Based on the number of differing pixels, the similarity between the two images is determined. Consecutive differing pixels are merged to determine the difference region. For the two formulas to be compared, obtain the formula character information corresponding to the two formulas; align the formula character information according to the Y coordinate to make the vertical order of the two formula character information consistent; sort the two formula character information according to the X coordinate and combine the formula characters into the corresponding formula text string; perform the text content difference analysis step on the formula text string to determine the difference area and difference type; For the two tables to be compared, obtain the text content from the two tables; concatenate the text content according to the order of rows and / or columns to obtain the concatenated text string; perform the text content difference analysis step on the text string to determine the difference area and difference type.

2. A multi-dimensional comparison device for PDF documents, characterized in that, The device includes: The document segmentation module is used to divide both the first and second PDF documents to be compared into multiple object regions. These multiple object regions include at least one of the following: text region, image region, table region, and mathematical formula region. The region parsing module is used to parse the multiple object regions to obtain the object content to be compared, including: for each segmented object region, extracting the specific content within the object region based on its coordinate information on the page; for the text region, text extraction and merging are used to obtain the text content to be compared; for the table region, the parsed table is the table to be compared; for the image region, the parsed image is the image to be compared; and for the formula region, the parsed formula is the formula to be compared. The LayoutLM layout language model, which has been fine-tuned, is used to perform preliminary layout analysis and segmentation of PDF documents. Based on the font size of the extracted characters and their vertical displacement relative to the baseline, determine whether the characters are subscripts or superscripts; determine whether the text is bold or italic by analyzing the thickness and slant angle of the text. For adjacent text areas distributed across different columns, based on preset rules and natural language processing technology, it is determined whether these areas belong to the same paragraph; if so, these text area blocks are corrected and merged; for adjacent text area blocks spanning multiple pages, the same rules and natural language processing technology are used to analyze whether they belong to the same paragraph or sentence, and then they are merged. The comparison content determination module is used to determine, for each first object content in a first PDF document, the corresponding second object content to be compared in a second PDF document, including: determining the target object content in the second PDF document at the position corresponding to the first position information according to the first position information of the first object content in the first PDF document; expanding the content of the same object type forward and backward by a specified number of regions based on the target object content; calculating the similarity between the first object content and the multiple regions, and taking the region content corresponding to the highest similarity as the second object content to be compared in the second PDF document corresponding to the first object content; The difference determination module compares the content of the first object and the content of the second object to determine the difference information. The difference marking module synchronously marks the difference type and index information of the difference information in the first PDF document and the second PDF document; records the index position of each difference fragment in the corresponding comparison text; through these index positions, the specific difference area in the text block or image in the original PDF document can be accurately located, and the corresponding difference area can be found in the comparison PDF document; for each identified difference area, through bidirectional mapping, the difference at the same position in the two documents or images can be clearly displayed; in addition, the difference area is synchronously located and marked in the two documents or images; when a user views a certain difference area in one document or image, the corresponding area in the other document or image will be automatically located and highlighted. The difference determination module is also used for: For two text contents to be compared, the following text content difference analysis steps are performed: The two text contents are segmented into character units; each character unit of the two text contents is compared one by one, and the minimum edit distance between the two text contents is calculated; the minimum edit distance is characterized by the minimum number of editing operations required to convert one text into another; the operations include inserting characters, deleting characters, and replacing characters; after comparing all character units, the editing operation sequence from one text content to another is obtained; the difference information between the two text contents is determined based on the editing operation sequence, including: If the editing operation type of the target comparison segment is "insert character", the difference type of the target comparison segment is determined to be "insert segment"; and multiple consecutive comparison segments of the "insert segment" type are merged to determine the first difference region; if the editing operation type of the target comparison segment is "delete character", the difference type of the target comparison segment is determined to be "delete segment"; and multiple consecutive comparison segments of the "delete segment" type are merged to determine the second difference region; if the difference type of the target comparison segment is the same segment type, the font, font size, and font style of the text of the target comparison segment are compared, and the target comparison segment is marked as the same segment type. For the two images to be compared, the size and resolution of each image are normalized. Each pixel at the same location in both images is traversed. For each pixel, the values ​​of the four channels (red, green, blue, and transparency) are compared. If any channel value differs, the pixel is marked as different. After traversing all pixels, the number of differing pixels between the two images is counted. Based on the number of differing pixels, the similarity between the two images is determined. Consecutive differing pixels are merged to determine the difference region. For the two formulas to be compared, obtain the formula character information corresponding to the two formulas; align the formula character information according to the Y coordinate to make the vertical order of the two formula character information consistent; sort the two formula character information according to the X coordinate and combine the formula characters into the corresponding formula text string; perform the text content difference analysis step on the formula text string to determine the difference area and difference type; For the two tables to be compared, obtain the text content from the two tables; concatenate the text content according to the order of rows and / or columns to obtain the concatenated text string; perform the text content difference analysis step on the text string to determine the difference area and difference type.

3. An electronic device, characterized in that, The method includes a processor and a memory, the memory storing computer-executable instructions that can be executed by the processor, the processor executing the computer-executable instructions to implement the method of claim 1.

Citation Information

Patent Citations

  • Self-duplicate-checking method for typeset document content based on teaching aid book publishing

    CN111563372A

  • Document comparison method and device, equipment and medium

    CN115937888A

  • Document comparison method and device, equipment and medium

    CN115937891A

  • PDF archive resource efficient extraction method and text recognition system

    CN118762368A