A PDF document comparison method and system based on intelligent differential merging
This paper compares PDF documents using an intelligent differential merging method, renders them as low-resolution bitmaps and generates visual fingerprints. By utilizing the Myers differential algorithm and spatial hash grouping strategy, it solves the accuracy and efficiency problems of existing PDF document comparison methods, and achieves efficient and accurate document comparison.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- AFIRSTSOFT CO LTD
- Filing Date
- 2025-12-30
- Publication Date
- 2026-05-29
AI Technical Summary
Existing PDF document comparison methods lack accuracy when page content changes, have high computational complexity, and are prone to falsely reporting document differences, making it difficult to meet the needs of real-time comparison.
The intelligent differential merging method is adopted. By rendering PDF pages as low-resolution bitmaps, a visual fingerprint is generated using a high-speed hash algorithm. The Myers differential algorithm is used for global comparison to identify deletion-insertion adjacent patterns, construct candidate page pairs, and lock the best match by combining pre-filtering and weighted similarity calculation. A spatial hash grouping strategy is used for internal object comparison.
It achieves high-precision and high-performance PDF document comparison, reduces computational complexity, quickly identifies subtle changes, and improves comparison efficiency and accuracy.
Smart Images

Figure CN122113838A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method and system for comparing PDF documents based on intelligent differential merging. Background Technology
[0002] With the rapid development of the digital age, electronic documents are widely used, and PDF documents are one of the main formats for electronic document transmission and storage. Therefore, accurately comparing the subtle differences between two PDF document versions is crucial. Existing PDF document comparison methods typically use simple page number index matching or brute-force polling to compare objects pairwise, which has the following drawbacks: First, existing PDF document comparison methods cannot accurately identify page modifications when only a few content changes occur. Furthermore, for text comparison, existing methods usually require extracting the plain text of the page before calculating the differences, ignoring the rendering attributes of the PDF document, resulting in a lack of accuracy in the comparison results. Second, for complex pages containing massive vector paths or dense text blocks, existing PDF document comparison methods usually use brute-force polling to compare objects pairwise, which has high computational complexity and is prone to software response delays or even process crashes, and cannot meet the real-time comparison requirements of engineering-level documents. Third, existing PDF document comparison methods often rely on strict binary stream comparison when comparing images or rendered pages. They lack fault tolerance mechanisms and are prone to misreporting non-substantial changes in the underlying data as document differences, generating a large amount of noisy data.
[0003] Therefore, we need to develop a PDF document comparison method and system based on intelligent differential merging, which can reduce comparison complexity, improve comparison efficiency, and accurately identify subtle changes in PDF documents, thereby achieving high-precision and high-performance PDF document comparison. Summary of the Invention
[0004] The purpose of this invention is to provide a PDF document comparison method and system based on intelligent differential merging, so as to solve the problems mentioned in the background art of low efficiency, insufficient accuracy, and inability to meet users' real-time comparison needs.
[0005] To achieve the above objectives, the present invention adopts the following technical solution: According to one aspect of the present invention, a PDF document comparison method based on intelligent differential merging is provided, the method comprising the following steps: Traverse the pages of the source PDF document and the target PDF document, render each page of the two PDF documents into a fixed-size low-resolution bitmap, and use a high-speed hash algorithm to calculate the complete pixel data buffer of the bitmap to generate a hash value, and use the hash value as the visual fingerprint of the corresponding page. The visual fingerprint sequences of the two PDF documents are compared using the Myers difference algorithm to generate a difference sequence containing three basic operations: equality, deletion, and insertion. Traverse the difference sequence to identify the regions where all deletion operation sequences are adjacent to insertion operation sequences, and construct candidate page pairs based on the regions; The candidate page pairs are pre-filtered, and a weighted similarity calculation is performed on the pre-filtered candidate page pairs to obtain a similarity score; The similarity score is compared with a preset judgment threshold to lock the best candidate page pair, and the deletion operation node and insertion operation node corresponding to the best candidate page pair in the difference sequence are merged and replaced into a modification operation node; For each modification operation node, the source page and target page are compared using spatial quantization indexing technology, and the final comparison result is output.
[0006] According to another aspect of the present invention, a PDF document comparison system based on intelligent differential merging is provided. The system includes: a visual fingerprint generation module, a page sequence comparison module, a candidate page pair construction module, a page pre-filtering module, an operation reconstruction module, and a deep comparison module. Wherein: The aforementioned visual fingerprint generation module is used to traverse the pages of the source PDF document and the target PDF document, render each page of the two PDF documents into a fixed-size low-resolution bitmap, and use a high-speed hash algorithm to calculate the complete pixel data buffer of the bitmap to generate a hash value, and use the hash value as the visual fingerprint of the corresponding page. The aforementioned page sequence comparison module is used to compare the visual fingerprint sequences of the two PDF documents using the Myers difference algorithm, and generate a difference sequence containing three basic operations: equality, deletion, and insertion. The aforementioned candidate page pair construction module is used to traverse the difference sequence, identify the regions where all deletion operation sequences are adjacent to insertion operation sequences, and construct candidate page pairs based on the regions. The aforementioned page pre-filtering module is used to perform pre-filtering on the candidate page pairs and to calculate a weighted similarity score on the candidate page pairs that pass the pre-filtering. The above-mentioned operation reconstruction module is used to compare the similarity score with a preset judgment threshold, lock the best candidate page pair, and merge and replace the deletion operation node and insertion operation node corresponding to the best candidate page pair in the difference sequence into a modification operation node. The aforementioned deep comparison module is used to compare internal objects of the source and target pages corresponding to each modification operation node using spatial quantization indexing technology, and output the final comparison results.
[0007] Based on the aforementioned scheme, the generation of the difference sequence containing three basic operations—equality, deletion, and insertion—is specifically as follows: Using the first visual fingerprint sequence of the source PDF document and the second visual fingerprint sequence of the target PDF document as input, the Myers difference algorithm is used to perform dynamic programming search in the diagonal direction formed by the matching of sequence elements to calculate the shortest editing path required to convert the first visual fingerprint sequence into the second visual fingerprint sequence. Based on the shortest edit path, generate and output a difference sequence containing three basic operations: equality, deletion, and insertion.
[0008] Among them, the equality operation means that the content in the source PDF document and the target PDF document are the same; the deletion operation means that the content exists in the source PDF document but does not exist in the target PDF document; the insertion operation means that the content does not exist in the source PDF document but exists in the target PDF document.
[0009] Based on the aforementioned scheme, the construction of candidate page pairs based on the region specifically involves: Using each page to be deleted in the deletion operation sequence in the region as the base page, an index search interval is dynamically defined in the adjacent insertion operation sequence according to the preset window range. Each page to be inserted within the index search range is combined with the baseline page to construct the candidate page pair.
[0010] Based on the aforementioned scheme, the pre-filtering of the candidate page pairs specifically involves: Perform geometric dimension verification on the candidate page pair, compare the width or height of the two pages in the current candidate page pair, and determine whether the difference in size of any dimension exceeds a first preset threshold. If the difference exceeds the limit, it is determined to be a significant difference, and the current candidate page pair is skipped, ending the current comparison. If it does not exceed the limit, then perform complexity dimension verification, count the number of key type objects in the two pages of the current candidate page pair, and determine whether the difference in number ratio exceeds the second preset threshold. If the difference exceeds the limit, it is determined to be a significant difference, and the current candidate page pair is skipped, ending the current comparison. If the limit is not exceeded, the current candidate page pair is retained, and the next candidate page pair is pre-filtered. The steps of geometric dimension verification and complexity dimension verification are repeated until all candidate page pairs have been pre-filtered.
[0011] Based on the aforementioned scheme, the weighted similarity calculation for the pre-filtered candidate page pairs specifically involves: Both pages in the pre-filtered candidate page pair are deconstructed into text layer, image layer, path layer, and shadow layer, and the matching rate of elements in each layer is calculated separately. Based on the current page type and content characteristics, a weight coefficient is dynamically assigned to the matching rate; The matching rate is multiplied by its corresponding weight coefficient and then summed. A smoothing factor is introduced to output a similarity score that is normalized to be between 0 and 1.
[0012] Based on the aforementioned scheme, the comparison of internal objects using spatial quantization indexing technology specifically involves: The source page and target page corresponding to the modified operation node are used as the final page pair; The internal objects of the page in the final page pair are grouped using a spatial hash grouping strategy, and the internal objects of the page in the group are analyzed for differences according to their types using the corresponding depth comparison strategy. Based on the comprehensive difference analysis results, the final comparison results are output.
[0013] Specifically, a spatial hashing grouping strategy is used to group the internal objects of the final page pair, as follows: Calculate the coordinates of the geometric center point of the object inside the page, quantize and encode the coordinates, and generate a spatial index key; Using a hash mapping table, objects within a page with the same spatial index key are grouped into the same logical bucket.
[0014] Specifically, for the page-internal objects within the group, a corresponding depth comparison strategy is used to perform difference analysis based on their type, including: If the object is a path object, the fill rules, stroke status, graphic status parameters, color space, and coordinate sequence of all geometric key points constituting the path of the two path objects are compared to generate the first comparison result. If the object is an image object, then a concatenated comparison is performed, specifically: Determine whether two image objects reference the same resource ID. If so, the two image objects are considered the same, and the comparison ends. If not, read the compressed data streams of the two image objects, calculate the checksums of the two compressed data streams respectively. If the lengths of the two compressed data streams are the same and the checksums are consistent, the two image objects are considered the same, and the comparison ends. If the two image objects are still different after the above comparison, completely decode the two image objects into bitmap data, compare the metadata and pixel matrix of the bitmap data, and generate a second comparison result. If the object is a text object, the characters are aggregated into logical words, a composite fingerprint containing text content and style attributes is generated for each logical word, and the composite fingerprint sequences of the source page and the target page are differentially compared to generate a third comparison result. The final comparison result is output by combining the first, second, and third comparison results.
[0015] As can be seen from the above technical solution, compared with the prior art, the present invention has at least the following advantages and positive effects: (1) The present invention renders the PDF page as a low-resolution bitmap and calculates the hash fingerprint, and then performs a global comparison of the visual fingerprint sequence through the Myers differential algorithm. It actively detects the deletion-insertion adjacent pattern and constructs candidate page pairs, which can not only quickly filter the PDF page, but also intelligently focus on the page area where the content may be modified.
[0016] (2) The present invention pre-filters candidate page pairs and calculates similarity scores. Based on threshold judgment and greedy strategy, it locks the best match. It can quickly eliminate obviously mismatched page pairs at low cost and automatically and accurately reconstruct the underlying abstract deletion and insertion operations into modification operations, thereby more accurately identifying subtle changes in PDF documents.
[0017] (3) The present invention uses a spatial hash grouping strategy to group the objects inside the page in the final page pair, which can greatly reduce the complexity of object-level comparison, solve the performance bottleneck of micro-comparison, and improve the speed and efficiency of PDF document comparison.
[0018] (4) The present invention designs cascaded and deep feature comparison strategies for text, images and path objects respectively, which can accurately capture the subtle differences in content and style features in PDF documents, thereby achieving high-precision and high-performance PDF document comparison. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below only involve some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 A flowchart of a PDF document comparison method based on intelligent differential merging provided by an embodiment of the present invention is shown; Figure 2 The flowchart of a method for global comparison of visual fingerprint sequences using the Myers difference algorithm provided in an embodiment of the present invention is shown. Figure 3 The flowchart illustrates a method for pre-filtering candidate page pairs provided by an embodiment of the present invention. Figure 4 The flowchart illustrates a method for internal object comparison based on spatial quantization indexing technology provided by an embodiment of the present invention. Figure 5 A schematic diagram of the structure of a PDF document comparison system based on intelligent differential merging provided in an embodiment of the present invention is shown; in, Figure 5 The annotations in the accompanying drawings are explained as follows: 500 - A PDF document comparison system based on intelligent differential merging; 501 - Visual fingerprint generation module; 5011 - Page rendering unit; 5012 - Hash calculation unit; 502 - Page sequence alignment module; 503 - Candidate page pair construction module; 504 - Page pre-filtering module; 5041 - Page pre-filtering unit; 5042 - Similarity calculation unit; 505 - Operation reconstruction module; 5051 - Threshold determination unit; 5052 - Operation reconstruction unit; 506 - Deep comparison module; 5061 - Object grouping unit; 5062 - Difference analysis unit. Detailed Implementation
[0021] To more clearly explain the purpose, technical solutions, and advantages of the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein. On the contrary, these embodiments are provided so that the present invention will be more comprehensive and complete, and fully convey the concept of the exemplary embodiments to those skilled in the art.
[0022] Furthermore, the described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Numerous specific details are provided in the following description to give a full understanding of embodiments of the invention. However, those skilled in the art will recognize that the technical solutions of the invention can be practiced without one or more of the specific details, or other methods, components, apparatuses, steps, etc., can be employed. In other instances, well-known methods, apparatuses, implementations, or operations are not shown or described in detail to avoid obscuring various aspects of the invention.
[0023] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0024] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.
[0025] The present invention will now be described in detail with reference to specific embodiments: Example 1
[0026] like Figure 1 As shown in the figure, this embodiment of the invention provides a PDF document comparison method based on intelligent differential merging. The specific steps of the method are as follows: S1: Traverse the pages of the source PDF document and the target PDF document, render each page of the two PDF documents into a fixed-size low-resolution bitmap, and use a high-speed hash algorithm to calculate the complete pixel data buffer of the bitmap to generate a hash value, and use the hash value as the visual fingerprint of the corresponding page. In this embodiment, the pages of both the source and target PDF documents are first iterated through one by one, and the rendering engine is invoked to render each page of both documents into a fixed-size low-resolution bitmap. After obtaining the bitmap, a high-speed hash algorithm is used to calculate the complete pixel data buffer of each bitmap one by one to generate a hash value. This hash value is then used as the visual fingerprint of the corresponding page. This process continues until every page of both the source and target PDF documents has been calculated, resulting in a first visual fingerprint sequence for the source PDF document and a second visual fingerprint sequence for the target PDF document. The high-speed hash algorithm includes modern non-cryptographic hash algorithms such as xxHash and MurmurHash, and is not limited to these in this embodiment.
[0027] S2: The visual fingerprint sequences of the two PDF documents are compared using the Myers difference algorithm to generate a difference sequence containing three basic operations: equality, deletion, and insertion. Furthermore, after obtaining the first visual fingerprint sequence of the source PDF document and the second visual fingerprint sequence of the target PDF document, the Myers difference algorithm is used to perform a global comparison of the visual fingerprint sequences of the two PDF documents, such as... Figure 2 As shown, the specific steps include the following: S201: Using the first visual fingerprint sequence of the source PDF document and the second visual fingerprint sequence of the target PDF document as input, the Myers difference algorithm is used to perform dynamic programming search in the diagonal direction formed by the matching of sequence elements to calculate the shortest editing path required to convert the first visual fingerprint sequence into the second visual fingerprint sequence. S202: Based on the shortest editing path, generate and output a difference sequence containing three basic operations: equality, deletion, and insertion.
[0028] The EQUAL operation refers to the source PDF document and the target PDF document having the same content; the DELETE operation refers to the source PDF document containing content that is not present in the target PDF document; and the INSERT operation refers to the source PDF document containing content that is not present in the target PDF document. The following examples provide a more detailed explanation: Assuming the first visual fingerprint sequence of the source PDF document is [P1, P2, P3, P4, P5], and the second visual fingerprint sequence of the target PDF document is [P1, P2, P3', P4, P6], then after comparison using the Myers difference algorithm, the following difference sequence will be obtained: EQUAL: (P1, P1); EQUAL: (P2, P2); DELETE: (P3, _); INSERT: (P3`, _); EQUAL: (P4, P4); INSERT: (P6, _).
[0029] S3: Traverse the difference sequence, identify the regions where all deletion operation sequences are adjacent to insertion operation sequences, and construct candidate page pairs based on the regions; Further, after obtaining the difference sequence through step S2, the difference sequence is traversed to identify the regions where all deletion operation sequences are adjacent to insertion operation sequences, and a sliding window strategy is used to construct candidate page pairs. The specific steps include: taking each page to be deleted in the deletion operation sequence in the region as the base page, dynamically defining an index search interval in the adjacent insertion operation sequence according to a preset window range; and combining each page to be inserted in the index search interval with the base page to construct the candidate page pairs.
[0030] In this process, the regions immediately adjacent to the insertion operation sequence of all deletion operation sequences are identified. For example, in step S2, DELETE: (P3, _)→INSERT: (P3`, _) is identified.
[0031] S4: Perform pre-filtering on the candidate page pairs, and calculate a weighted similarity score on the candidate page pairs that pass the pre-filtering; Furthermore, after constructing candidate page pairs, pre-filtering is performed using low-cost feature validation to eliminate combinations with significant differences. For example... Figure 3 As shown, pre-filtering specifically includes the following steps: S301: Perform geometric dimension verification on the candidate page pair, compare the width or height of the two pages in the current candidate page pair, and determine whether the difference in size of any dimension exceeds the first preset threshold. If the difference exceeds the limit, proceed to step S303, determine that the difference is significant, skip the current candidate page pair, and end the current comparison. If it does not exceed the limit, proceed to step S302 to perform complexity dimension verification, count the number of key type objects in the two pages of the current candidate page pair, and determine whether the difference in number ratio exceeds the second preset threshold. If the difference exceeds the limit, proceed to step S303, determine that the difference is significant, skip the current candidate page pair, and end the current comparison. S304: If not more than 100, retain the current candidate page pair; S305: Perform pre-filtering for the next candidate page pair, repeating the steps of geometric dimension verification and complexity dimension verification until all candidate page pairs have been pre-filtered.
[0032] Furthermore, when performing complexity dimension verification, the number of key type objects on the page is counted. The key type objects mainly include path objects, image objects, and text objects. Furthermore, after pre-filtering all candidate page pairs, a weighted similarity calculation is performed on the remaining candidate page pairs to obtain a similarity score; the calculation process specifically includes: Both pages in the pre-filtered candidate page pair are deconstructed into text layer, image layer, path layer, and shadow layer, and the matching rate of elements in each layer is calculated separately. Based on the current page type and content characteristics, a weight coefficient is dynamically assigned to the matching rate; for example, the path layer has a higher weight in the drawing page, and the text layer has a higher weight in the contract page, etc. The matching rate is multiplied by its corresponding weight coefficient and then summed. A smoothing factor is introduced to output a similarity score that is normalized to be between 0 and 1.
[0033] S5: Compare the similarity score with a preset judgment threshold, lock the best candidate page pair, and merge and replace the deletion operation node and insertion operation node corresponding to the best candidate page pair in the difference sequence into a single modification operation node; Furthermore, after obtaining the similarity score, the system locks the best match based on threshold determination and a greedy strategy. Specifically, the similarity score is compared with a preset determination threshold. During the sliding window search process, once the similarity score of a candidate page pair exceeds the preset determination threshold, the system immediately determines it as the best match and terminates the current window's search for subsequent candidate pages.
[0034] Furthermore, after identifying the best candidate page pair, the delete and insert operation nodes corresponding to the best candidate page pair in the original difference sequence are merged and replaced with a single modify operation node. Using the difference sequence exemplified in step S2, if the delete and insert operation nodes for the best candidate page pair are DELETE: (P3, _) and INSERT: (P3`, _), then the difference sequence will be reconstructed as follows: EQUAL: (P1, P1); EQUAL: (P2, P2); MODIFY: (P3, P3`); EQUAL: (P4, P4); INSERT: (P6, _).
[0035] S6: For each modification operation node, the source page and target page are compared using spatial quantization indexing technology, and the final comparison result is output.
[0036] Furthermore, for pages confirmed as modified, spatial quantization indexing technology is used to compare internal objects, such as... Figure 4 As shown, the specific steps include the following: S401: The source page and target page corresponding to the modification operation node are taken as the final page pair; S402: Use a spatial hash grouping strategy to group the page internal objects in the final page pair; Specifically, the spatial hash grouping strategy is as follows: Calculate the coordinates of the geometric center point of the object inside the page, quantize and encode the coordinates, and generate a spatial index key; Using a hash mapping table, objects within a page with the same spatial index key are grouped into the same logical bucket.
[0037] S403: Perform difference analysis on the page objects within the group according to their types using the corresponding depth comparison strategies; Specifically, the difference analysis includes: If the object is a path object, the fill rules, stroke status, graphic status parameters, color space, and coordinate sequence of all geometric key points constituting the path of the two path objects are compared to generate the first comparison result. If the object is an image object, then a concatenated comparison is performed, specifically: Determine whether two image objects reference the same resource ID. If so, the two image objects are considered the same, and the comparison ends. If not, read the compressed data streams of the two image objects, calculate the checksums of the two compressed data streams respectively. If the lengths of the two compressed data streams are the same and the checksums are consistent, the two image objects are considered the same, and the comparison ends. If the two image objects are still different after the above comparison, completely decode the two image objects into bitmap data, compare the metadata and pixel matrix of the bitmap data, and generate a second comparison result. The metadata of the bitmap data includes, but is not limited to, width, height, bit depth, color format, and palette data. If the object is a text object, the characters are aggregated into logical words, a composite fingerprint containing text content and style attributes is generated for each logical word, and the composite fingerprint sequences of the source page and the target page are differentially compared to generate a third comparison result. The composite fingerprint not only includes the Unicode encoding of the text, but also encodes typographic attributes such as font family name, font size, font weight (bold), slant (italic), fill color value, and rendering mode (such as solid or hollow).
[0038] S404: Based on the comprehensive difference analysis results, output the final comparison results.
[0039] Furthermore, after performing differential analysis on the internal objects of the page within the group using corresponding deep comparison strategies, the comparison results for each object are obtained. The first comparison result, the second comparison result, and the third comparison result are combined to output the final comparison result. The final comparison result can be a structured differential analysis report, which summarizes all add, delete, and modify operations at the object level of the currently modified page, including the change type, object location, attribute details, and is associated with the page-level modification node.
[0040] The PDF document comparison method described in this embodiment first renders the PDF page as a low-resolution bitmap and calculates its hash fingerprint. Then, it uses the Myers difference algorithm to perform a global comparison of the visual fingerprint sequence, actively detecting deletion-insertion adjacent patterns and constructing candidate page pairs. This method can quickly filter PDF pages and intelligently focus on page areas where content modifications may have occurred. By pre-filtering, threshold-based judgment, and a greedy strategy to lock in the best match, it can quickly eliminate obviously mismatched page pairs at low cost. The method employs a spatial hash grouping strategy to group the internal objects of the final page pairs and designs cascaded and deep feature comparison strategies for text, images, and path objects respectively. This not only greatly reduces the complexity of object-level comparison and improves the comparison speed but also more accurately identifies subtle changes in PDF documents, thereby achieving high-precision and high-performance PDF document comparison.
[0041] Example 2 like Figure 5 As shown, this embodiment of the invention provides a PDF document comparison system 500 based on intelligent differential merging. The system includes: a visual fingerprint generation module 501, a page sequence alignment module 502, a candidate page pair construction module 503, a page pre-filtering module 504, an operation reconstruction module 505, and a depth comparison module 506; wherein: The visual fingerprint generation module 501 is used to traverse the pages of the source PDF document and the target PDF document, render each page of the two PDF documents into a fixed-size low-resolution bitmap, and use a high-speed hash algorithm to calculate the complete pixel data buffer of the bitmap to generate a hash value, and use the hash value as the visual fingerprint of the corresponding page. The visual fingerprint generation module 501 includes: a page rendering unit 5011 and a hash calculation unit 5012; wherein: The aforementioned page rendering unit 5011 is configured to: traverse the pages of the source PDF document and the target PDF document, and render each page of the two PDF documents into a low-resolution bitmap of a fixed size; The hash calculation unit 5012 is configured to: use a high-speed hash algorithm to calculate the complete pixel data buffer of the bitmap obtained in the page rendering unit 5011, generate a hash value, and use the hash value as the visual fingerprint of the corresponding page.
[0042] The page sequence comparison module 502 is used to compare the visual fingerprint sequences of the two PDF documents using the Myers difference algorithm to generate a difference sequence containing three basic operations: equality, deletion, and insertion. The process involves a global comparison of the visual fingerprint sequences of two PDF documents using the Myers difference algorithm, specifically including the following steps: Using the first visual fingerprint sequence of the source PDF document and the second visual fingerprint sequence of the target PDF document as input, the Myers difference algorithm is used to perform dynamic programming search in the diagonal direction formed by the matching of sequence elements to calculate the shortest editing path required to convert the first visual fingerprint sequence into the second visual fingerprint sequence. Based on the shortest edit path, generate and output a difference sequence containing three basic operations: equality, deletion, and insertion.
[0043] The candidate page pair construction module 503 is used to traverse the difference sequence, identify the regions where all deletion operation sequences are adjacent to the insertion operation sequence, and construct candidate page pairs based on the regions. The specific steps of constructing candidate page pairs include: taking each page to be deleted in the deletion operation sequence of the region as a base page, dynamically defining an index search interval in the adjacent insertion operation sequence according to a preset window range; and combining each page to be inserted in the index search interval with the base page to construct the candidate page pairs.
[0044] The page pre-filtering module 504 is used to perform pre-filtering on the candidate page pairs and to calculate the weighted similarity of the candidate page pairs that pass the pre-filtering to obtain a similarity score. The page pre-filtering module 504 includes: a page pre-filtering unit 5041 and a similarity calculation unit 5042; wherein: The aforementioned page pre-filtering unit 5041 is configured to perform pre-filtering on the candidate page pairs constructed in the candidate page pair construction module 503, specifically including the following steps: Perform geometric dimension verification on the candidate page pair, compare the width or height of the two pages in the current candidate page pair, and determine whether the difference in size of any dimension exceeds a first preset threshold. If the difference exceeds the limit, it is determined to be a significant difference, and the current candidate page pair is skipped, ending the current comparison. If it does not exceed the limit, then perform complexity dimension verification, count the number of key type objects in the two pages of the current candidate page pair, and determine whether the difference in number ratio exceeds the second preset threshold. If the difference exceeds the limit, it is determined to be a significant difference, and the current candidate page pair is skipped, ending the current comparison. If the limit is not exceeded, the current candidate page pair is retained, and the next candidate page pair is pre-filtered. The steps of geometric dimension verification and complexity dimension verification are repeated until all candidate page pairs have been pre-filtered.
[0045] The aforementioned similarity calculation unit 5042 is configured to: perform weighted similarity calculation on the candidate page pairs retained in the page pre-filtering unit 5041 to obtain a similarity score; wherein the calculation process specifically includes: Both pages in the pre-filtered candidate page pair are deconstructed into text layer, image layer, path layer, and shadow layer, and the matching rate of elements in each layer is calculated separately. Based on the current page type and content characteristics, a weight coefficient is dynamically assigned to the matching rate; The matching rate is multiplied by its corresponding weight coefficient and then summed. A smoothing factor is introduced to output a similarity score that is normalized to be between 0 and 1.
[0046] The operation reconstruction module 505 is used to compare the similarity score with a preset judgment threshold, lock the best candidate page pair, and merge and replace the deletion operation node and insertion operation node corresponding to the best candidate page pair in the difference sequence into a modification operation node. Operation reconstruction module 505 includes: threshold determination unit 5051 and operation reconstruction unit 5052; wherein: The threshold determination unit 5051 is configured to: compare the similarity score calculated in the similarity calculation unit 5042 with the preset determination threshold, and lock the best candidate page pair; The aforementioned operation reconstruction unit 5052 is configured to: based on the best candidate page pair obtained in the threshold determination unit 5051, merge and replace the deletion operation node and insertion operation node corresponding to the best candidate page pair in the original difference sequence into a modification operation node.
[0047] The deep comparison module 506 is used to compare the internal objects of the source page and target page corresponding to each modification operation node using spatial quantization indexing technology, and output the final comparison result. The deep comparison module 506 includes: an object grouping unit 5061 and a difference analysis unit 5062; wherein: The aforementioned object grouping unit 5061 is configured to: treat the source page and target page corresponding to each modification operation node as a final page pair, and group the internal objects of the page in the final page pair using a spatial hash grouping strategy; wherein, the spatial hash grouping strategy specifically includes: Calculate the coordinates of the geometric center point of the object inside the page, quantize and encode the coordinates, and generate a spatial index key; Using a hash mapping table, objects within a page with the same spatial index key are grouped into the same logical bucket.
[0048] The aforementioned difference analysis unit 5062 is configured to: based on the grouping results of the object grouping unit 5061, perform difference analysis on the page objects within the group according to their types using corresponding depth comparison strategies, and synthesize the difference analysis results to output the final comparison result; wherein, the difference analysis specifically includes: If the object is a path object, the fill rules, stroke status, graphic status parameters, color space, and coordinate sequence of all geometric key points constituting the path of the two path objects are compared to generate the first comparison result. If the object is an image object, then a concatenated comparison is performed, specifically: Determine whether two image objects reference the same resource ID. If so, the two image objects are considered the same, and the comparison ends. If not, read the compressed data streams of the two image objects, calculate the checksums of the two compressed data streams respectively. If the lengths of the two compressed data streams are the same and the checksums are consistent, the two image objects are considered the same, and the comparison ends. If the two image objects are still different after the above comparison, completely decode the two image objects into bitmap data, compare the metadata and pixel matrix of the bitmap data, and generate a second comparison result. If the object is a text object, the characters are aggregated into logical words, a composite fingerprint containing text content and style attributes is generated for each logical word, and the composite fingerprint sequences of the source page and the target page are differentially compared to generate a third comparison result. The final comparison result is output by combining the first, second, and third comparison results.
[0049] In this embodiment, a hash fingerprint is first calculated based on the visual fingerprint generation module 501, and then the visual fingerprint sequence is globally compared using the Myers difference algorithm in the page sequence comparison module 502. This allows for quick and intelligent focusing on areas in the PDF page where content modifications may have occurred. Pre-filtering is performed by the page pre-filtering module 504, and the best match is locked using threshold judgment and a greedy strategy in the operation reconstruction module 505. This allows for the rapid elimination of obviously mismatched page pairs at low cost. The depth comparison module 506 uses a spatial hash grouping strategy to group the internal objects of the final page pair, and designs cascaded and depth feature comparison strategies for text, images, and path objects respectively. This not only greatly reduces the complexity of object-level comparison and improves the comparison speed, but also more accurately identifies subtle changes in the PDF document, thereby achieving high-precision and high-performance PDF document comparison.
[0050] Other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of the invention are indicated by the claims. It should be understood that the invention is not limited to the precise structures described above and shown in the drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.
Claims
1. A PDF document comparison method based on intelligent differential merging, characterized in that, Includes the following steps: Traverse the pages of the source PDF document and the target PDF document, render each page of the two PDF documents into a fixed-size low-resolution bitmap, and use a high-speed hash algorithm to calculate the complete pixel data buffer of the bitmap to generate a hash value, and use the hash value as the visual fingerprint of the corresponding page. The visual fingerprint sequences of the two PDF documents are compared using the Myers difference algorithm to generate a difference sequence containing three basic operations: equality, deletion, and insertion. Traverse the difference sequence to identify the regions where all deletion operation sequences are adjacent to insertion operation sequences, and construct candidate page pairs based on the regions; The candidate page pairs are pre-filtered, and a weighted similarity calculation is performed on the pre-filtered candidate page pairs to obtain a similarity score; The similarity score is compared with a preset judgment threshold to lock the best candidate page pair, and the deletion operation node and insertion operation node corresponding to the best candidate page pair in the difference sequence are merged and replaced into a modification operation node; For each modification operation node, the source page and target page are compared using spatial quantization indexing technology, and the final comparison result is output.
2. The PDF document comparison method according to claim 1, characterized in that, The generation of the difference sequence, which includes three basic operations: equality, deletion, and insertion, is specifically as follows: Using the first visual fingerprint sequence of the source PDF document and the second visual fingerprint sequence of the target PDF document as input, the Myers difference algorithm is used to perform dynamic programming search in the diagonal direction formed by the matching of sequence elements to calculate the shortest editing path required to convert the first visual fingerprint sequence into the second visual fingerprint sequence. Based on the shortest edit path, generate and output a difference sequence containing three basic operations: equality, deletion, and insertion.
3. The PDF document comparison method according to claim 1, characterized in that, The construction of candidate page pairs based on the region specifically involves: Using each page to be deleted in the deletion operation sequence of the region as the base page, an index search interval is dynamically defined in the adjacent insertion operation sequence according to the preset window range. Each page to be inserted within the index search range is combined with the baseline page to construct the candidate page pair.
4. The PDF document comparison method according to claim 1, characterized in that, The pre-filtering of the candidate page pairs specifically involves: Perform geometric dimension verification on the candidate page pair, compare the width or height of the two pages in the current candidate page pair, and determine whether the difference in size of any dimension exceeds a first preset threshold. If the difference exceeds the limit, it is determined to be a significant difference, and the current candidate page pair is skipped, ending the current comparison. If it does not exceed the limit, then perform complexity dimension verification, count the number of key type objects in the two pages of the current candidate page pair, and determine whether the difference in number ratio exceeds the second preset threshold. If the difference exceeds the limit, it is determined to be a significant difference, and the current candidate page pair is skipped, ending the current comparison. If the limit is not exceeded, the current candidate page pair is retained, and the next candidate page pair is pre-filtered. The steps of geometric dimension verification and complexity dimension verification are repeated until all candidate page pairs have been pre-filtered.
5. The PDF document comparison method according to claim 1, characterized in that, The weighted similarity calculation for the pre-filtered candidate pages is specifically as follows: Both pages in the pre-filtered candidate page pair are deconstructed into text layer, image layer, path layer, and shadow layer, and the matching rate of elements in each layer is calculated separately. Based on the current page type and content characteristics, a weight coefficient is dynamically assigned to the matching rate; The matching rate is multiplied by its corresponding weight coefficient and then summed. A smoothing factor is introduced to output a similarity score that is normalized to be between 0 and 1.
6. The PDF document comparison method according to claim 1, characterized in that, The comparison of internal objects using spatial quantization indexing technology specifically involves: The source page and target page corresponding to the modified operation node are used as the final page pair; The internal objects of the page in the final page pair are grouped using a spatial hash grouping strategy, and the internal objects of the page in the group are analyzed for differences according to their types using the corresponding depth comparison strategy. Based on the comprehensive difference analysis results, the final comparison results are output.
7. The PDF document comparison method according to claim 6, characterized in that, The spatial hashing grouping strategy is used to group the internal objects of the final page pair, specifically as follows: Calculate the coordinates of the geometric center point of the object inside the page, quantize and encode the coordinates, and generate a spatial index key; Using a hash mapping table, objects within a page with the same spatial index key are grouped into the same logical bucket.
8. The PDF document comparison method according to claim 6, characterized in that, The method of performing difference analysis on the page objects within the group using corresponding deep comparison strategies according to their types specifically includes: If the object is a path object, compare the fill rules, stroke status, graphic status parameters, color space, and coordinate sequence of all geometric key points that make up the path between the two path objects. If the object is an image object, then perform a concatenated comparison; If the object is a text object, the characters are aggregated into logical words, a composite fingerprint containing text content and style attributes is generated for each logical word, and the composite fingerprint sequences of the source page and the target page are compared differentially.
9. The PDF document comparison method according to claim 8, characterized in that, The cascaded comparison specifically refers to: Determine whether two image objects reference the same resource ID. If so, determine that the two image objects are the same and end the comparison. If not, read the compressed data streams of the two image objects, calculate the checksums of the two compressed data streams respectively, and if the lengths of the two compressed data streams are the same and the checksums are consistent, then determine that the two image objects are the same and end the comparison. If the two image objects are still different, then the two image objects are completely decoded into bitmap data, and the metadata and pixel matrix of the bitmap data are compared.
10. A PDF document comparison system based on intelligent differential merging, characterized in that, include: The visual fingerprint generation module is used to traverse the pages of the source PDF document and the target PDF document, render each page of the two PDF documents into a fixed-size low-resolution bitmap, and use a high-speed hash algorithm to calculate the complete pixel data buffer of the bitmap to generate a hash value, and use the hash value as the visual fingerprint of the corresponding page. The page sequence comparison module is used to compare the visual fingerprint sequences of the two PDF documents using the Myers difference algorithm, and generate a difference sequence containing three basic operations: equality, deletion and insertion. The candidate page pair construction module is used to traverse the difference sequence, identify the regions where all deletion operation sequences are adjacent to insertion operation sequences, and construct candidate page pairs based on the regions. The page pre-filtering module is used to perform pre-filtering on the candidate page pairs and to calculate a weighted similarity score on the candidate page pairs that pass the pre-filtering. The operation reconstruction module is used to compare the similarity score with a preset judgment threshold, lock the best candidate page pair, and merge and replace the deletion operation node and insertion operation node corresponding to the best candidate page pair in the difference sequence into a modification operation node. The deep comparison module is used to compare internal objects of the source page and target page corresponding to each modification operation node using spatial quantization indexing technology, and output the final comparison results.