PDF (Portable Document Format) file comparison method based on minimum editing distance

Through the PDF file comparison method based on the minimum editing distance, the page rendering and hashing algorithm are used to generate eigenvalue sequences, and differential comparisons are made for text, paths and image elements, which solves the problem of low accuracy and efficiency of PDF comparison tools in the prior art. , achieving efficient and accurate PDF comparison effect.

CN119129572APending Publication Date: 2024-12-13赛博爱思(上海)软件科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411251165.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-06
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

Existing PDF comparison tools are not accurate and inefficient when processing complex documents, resulting in low efficiency in the proofreading process, affecting printing progress and quality.

Method used

Using the PDF file comparison method based on the minimum edit distance, the eigenvalue sequence is generated through page rendering, MD5 value calculation and hashing algorithm, the eigenvalue sequence differences are compared using the minimum editing algorithm, and the difference comparison is made for text, paths and image elements to generate Difference sequence.

Benefits of technology

It improves the accuracy and speed of PDF comparison, reduces the demand for computing resources, avoids missed and missed detection, enhances the accuracy and stability of comparison, and improves user experience and satisfaction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119129572A_ABST
    Figure CN119129572A_ABST
Patent Text Reader

Abstract

The invention discloses a PDF (Portable Document Format) file comparison method based on a minimum editing distance, which comprises the following steps of: rendering a page of a first PDF file and a page of a second PDF file to obtain a rendered first bitmap and a rendered second bitmap, respectively calculating MD5 values of the bitmaps for the first bitmap and the second bitmap, and comparing the MD5 values of the bitmaps with the MD5 values of the first bitmap and the second bitmap; obtaining a feature value sequence of the first PDF file page and a feature value sequence of the second PDF file page; comparing the difference between the feature value sequence of the first PDF file page and the feature value sequence of the second PDF file page according to a minimum editing algorithm to obtain a difference sequence; and respectively carrying out difference comparison on the text element type, the image element type and the path element type on the page marked as the modified page in the difference sequence to finish comparison of the first PDF file and the second PDF file. According to the invention, the accuracy and speed of document comparison are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of computer technology, and in particular relates to a PDF file comparison method based on a minimum edit distance. Background Art

[0002] With the advancement of printing technology, the reliance on manual labor for printing proofreading is constantly decreasing, but it still requires a lot of manpower and material resources. Before typesetting and printing, typesetters still need to proofread the printed materials many times. When comparing the content of this modification with the content of the last modification, the difference is not easy to be detected. The efficiency of the entire proofreading process is not very high, which affects the printing progress and quality. At present, a portable document format file (Portable Document Format, referred to as PDF) comparison tool has been developed to perform PDF proofreading, reduce human errors in printing proofreading, and improve proofreading efficiency. The PDF comparison tools in the prior art mainly include Adobe Acrobat, DiffPDF, Beyond Compare, etc. These tools can help users compare the differences in documents, but there are problems of low accuracy and low comparison efficiency. The existence of the problem is mainly because the algorithms and technologies of the existing tools are not advanced enough, resulting in low accuracy when processing complex documents. Summary of the invention

[0003] To solve the above technical problems, the present invention proposes a method for comparing PDF files based on minimum edit distance, which improves the accuracy and speed of document comparison.

[0004] To achieve the above object, the present invention provides a method for comparing PDF files based on minimum edit distance, comprising: Rendering a page of the first PDF file and a page of the second PDF file to obtain a first bitmap and a second bitmap after rendering, calculating MD5 values ​​of the first bitmap and the second bitmap respectively, and obtaining a feature value sequence of the first PDF file page and a feature value sequence of the second PDF file page; Comparing the difference between the feature value sequence of the first PDF file page and the feature value sequence of the second PDF file page according to a minimum editing algorithm to obtain a difference sequence; For the pages marked as modified in the difference sequence, text element type, image element type and path element type are compared respectively to complete the comparison between the first PDF file and the second PDF file.

[0005] According to the method for comparing PDF files based on the minimum edit distance provided by the present invention, rendering a page of a first PDF file and a page of a second PDF file includes: The pages of the first PDF file and the pages of the second PDF file are rendered into 400*400 bitmaps.

[0006] According to the PDF file comparison method based on minimum edit distance provided by the present invention, calculating the MD5 values ​​of the first bitmap and the second bitmap respectively further includes introducing a hash algorithm to convert the content of the bitmap into a feature value.

[0007] According to the method for comparing PDF files based on minimum edit distance provided by the present invention, obtaining a difference sequence includes: Compare the feature value sequence of the first PDF file page with the feature value sequence of the second PDF file page, obtain the same parts, and mark the same parts as the same index; comparing the feature value sequence of the first PDF file page with the feature value sequence of the second PDF file page, and marking a portion that exists in the feature value sequence of the first PDF file page but does not exist in the feature value sequence of the second PDF file page as an index for page deletion; comparing the feature value sequence of the first PDF file page with the feature value sequence of the second PDF file page, and marking a portion that is present in the feature value sequence of the second PDF file page but not in the feature value sequence of the first PDF file page as an index for page addition; The feature value sequence of the first PDF file page and the feature value sequence of the second PDF file page are compared, and parts of the feature value sequence of the first PDF file page and the feature value sequence of the second PDF file page that exist but have different contents are marked as page updated indexes.

[0008] According to the PDF file comparison method based on minimum edit distance provided by the present invention, performing text element type difference comparison on the pages marked as modified in the difference sequence includes: For the pages marked as modified in the difference sequence, extract the text content, font size and color to generate a first text element feature value sequence and a second text element feature value sequence; The difference between the first text element feature value sequence and the second text element feature value sequence is compared using a minimum editing algorithm to obtain a text difference sequence, and the text difference sequence is marked with a text addition index, a text deletion index, a text modification index and a text identical index.

[0009] According to the PDF file comparison method based on minimum edit distance provided by the present invention, performing path element type difference comparison on the pages marked as modified in the difference sequence includes: For the pages marked as modified in the difference sequence, extract the data information of the path points, serialize the point set into a string and convert it into an MD5 value, and generate a feature value sequence of the first path element and a feature value sequence of the second path element; The difference between the feature value sequence of the first path element and the feature value sequence of the second path element is compared using a minimum editing algorithm to obtain a path difference sequence, and the path addition index, path deletion index, path modification index and path identical index are marked in the path difference sequence.

[0010] According to the PDF file comparison method based on the minimum edit distance provided by the present invention, performing image element type difference comparison on the pages marked as modified in the difference sequence includes: For the pages marked as modified in the difference sequence, the MD5 value, position, width and height information of the bitmap data of the image are obtained in advance to generate a feature value sequence of the first image element and a feature value sequence of the second image element; The difference between the feature value sequence of the first image element and the feature value sequence of the second image element is compared using a minimum editing algorithm to obtain an image difference sequence, and the image difference sequence is marked with an image addition index, an image deletion index, an image modification index and an image identical index.

[0011] Technical effects of the present invention: (1) The present invention can improve the computing performance and efficiency of internal or external devices. By using the minimum editing algorithm to compare the differences of PDF documents, the amount of calculation in the comparison process can be greatly reduced and the comparison speed can be improved. Compared with traditional PDF comparison tools, the present invention can ensure the accuracy and efficiency of comparison while greatly reducing the computing resources, thereby improving the performance and efficiency of internal and external devices.

[0012] (2) The present invention can improve the accuracy and precision of PDF comparison. By extracting key information of text, path and image elements, the present invention can accurately detect differences in PDF documents, avoiding problems such as missed detection and false detection that may exist in traditional comparison tools. At the same time, the present invention uses the MD5 algorithm to generate element feature value sequences, which can effectively avoid the problem of feature value conflicts and improve the accuracy and reliability of comparison.

[0013] (3) The present invention can improve the stability of PDF comparison. The present invention adopts advanced technical means, such as the minimum editing algorithm, the MD5 algorithm, etc., to ensure the stability and reliability of the comparison. At the same time, the present invention uses a simple and intuitive interface design, so that users can easily use the tool to complete the comparison operation, thereby improving the user's trust and satisfaction with the tool.

[0014] In summary, the PDF comparison tool provided by the present invention has multiple beneficial effects such as improved computing performance and efficiency, improved accuracy and precision, and improved stability, and can provide users with more efficient, accurate, and stable PDF comparison services, thereby improving user experience and satisfaction. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings: Figure 1 The figure is a flowchart of a method for comparing PDF files based on minimum edit distance according to an embodiment of the present invention. DETAILED DESCRIPTION

[0016] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0017] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0018] like Figure 1 As shown, this embodiment provides a method for comparing PDF files based on a minimum edit distance, including: Rendering the pages of the first PDF file and the pages of the second PDF file to obtain the rendered first bitmap and the second bitmap, calculating the MD5 values ​​of the bitmaps for the first bitmap and the second bitmap, respectively, to obtain the feature value sequence of the pages of the first PDF file and the feature value sequence of the pages of the second PDF file; Comparing the difference between the feature value sequence of the first PDF file page and the feature value sequence of the second PDF file page according to the minimum editing algorithm to obtain a difference sequence; For the pages marked as modified in the difference sequence, the text element type, image element type and path element type are compared respectively to complete the comparison between the first PDF file and the second PDF file.

[0019] Further, obtaining the difference sequence includes: Compare the feature value sequence of the first PDF file page with the feature value sequence of the second PDF file page, obtain the same parts, and mark the same parts as the same index; comparing the feature value sequence of the first PDF file page with the feature value sequence of the second PDF file page, and marking a portion that exists in the feature value sequence of the first PDF file page but does not exist in the feature value sequence of the second PDF file page as an index for page deletion; comparing the feature value sequence of the first PDF file page with the feature value sequence of the second PDF file page, and marking a portion that is present in the feature value sequence of the second PDF file page but not in the feature value sequence of the first PDF file page as an index for page addition; The feature value sequence of the first PDF file page and the feature value sequence of the second PDF file page are compared, and parts of the feature value sequence of the first PDF file page and the feature value sequence of the second PDF file page that exist but have different contents are marked as page updated indexes.

[0020] Further, performing text element type difference comparison on the pages marked as modified in the difference sequence includes: For the pages marked as modified in the difference sequence, extract the text content, font size and color to generate a first text element feature value sequence and a second text element feature value sequence; The difference between the first text element feature value sequence and the second text element feature value sequence is compared using a minimum editing algorithm to obtain a text difference sequence, and the text difference sequence is marked with a text addition index, a text deletion index, a text modification index and a text identical index.

[0021] Further, performing path element type difference comparison on the pages marked as modified in the difference sequence includes: For the pages marked as modified in the difference sequence, extract the data information of the path points, serialize the point set into a string and convert it into an MD5 value, and generate a feature value sequence of the first path element and a feature value sequence of the second path element; The difference between the feature value sequence of the first path element and the feature value sequence of the second path element is compared using a minimum editing algorithm to obtain a path difference sequence, and the path addition index, path deletion index, path modification index and path identical index are marked in the path difference sequence.

[0022] Further, performing image element type difference comparison on the pages marked as modified in the difference sequence includes: For the pages marked as modified in the difference sequence, the MD5 value, position, width and height information of the bitmap data of the image are obtained in advance to generate a feature value sequence of the first image element and a feature value sequence of the second image element; The difference between the feature value sequence of the first image element and the feature value sequence of the second image element is compared using a minimum editing algorithm to obtain an image difference sequence, and the image difference sequence is marked with an image addition index, an image deletion index, an image modification index and an image identical index.

[0023] The PDF comparison tool created by the present invention uses an advanced page rendering technology, which can render two PDF pages into a 400*400 bitmap and calculate the MD5 value of the bitmap to obtain the feature value of each page. Compared with traditional PDF comparison tools, this page rendering technology can more accurately capture all the details of the document page, including text, pictures, paths and other contents, thereby improving the accuracy of the comparison.

[0024] When calculating the MD5 value of the bitmap, the present invention also introduces a hash algorithm, which can quickly convert the content of the bitmap into a unique feature value. By comparing the feature values ​​of two PDF pages, the differences between the documents can be accurately detected, further improving the accuracy and speed of the comparison.

[0025] The PDF comparison tool created by the present invention adopts a minimum editing algorithm, which can compare the differences between the feature value sequences PA and PB of the document and generate a difference sequence PAB_DIFF, which includes four parts: page addition, deletion, update and the same index.

[0026] When generating a difference sequence, the minimum edit distance between PA and PB is first calculated, and then the difference sequence is generated according to the algorithm. Specifically, for the same parts in PA and PB, they are marked as the same index; for the parts in PA but not in PB, they are marked as the index of page deletion; for the parts in PB but not in PA, they are marked as the index of page addition; for the parts that exist in both PA and PB but have different contents, they are marked as the index of page update.

[0027] For the pages marked as modified in PAB_DIFF, the PDF comparison tool created by the present invention further compares the differences of text, image, and path element types. For text elements, key information such as text content, font, font size, and color are extracted, and the text element feature value sequences PTA and PTB are generated, namely [PTA1, PTA2, ..., PTAn], [PTB1, PTB2, ..., PTBm].

[0028] After generating the text element feature value sequence, the minimum edit algorithm is used to compare the differences between PTA and PTB, and the difference sequence PTAB_DIFF is obtained, which includes four parts: text addition, deletion, modification and the same index. Specifically, for the same parts in PTA and PTB, they are marked as the same index; for the parts that exist in PTA but not in PTB, they are marked as the index of text deletion; for the parts that exist in PTB but not in PTA, they are marked as the index of text addition; for the parts that exist in both PTA and PTB but have different contents, they are marked as the index of text modification.

[0029] For path elements and image elements, the PDF comparison tool created by the present invention also provides a difference comparison function. Specifically, for path elements, the data information of the path points will be extracted respectively, and the point set will be serialized into a string and converted into an MD5 value to generate the characteristic value sequences PPTA and PPTB of the path elements, namely [PPA1, PPA2, ..., PPAn], [PPB1, PPB2, ..., PPBm]. Then, the difference between PPTA and PPTB is compared using the minimum editing algorithm, and the difference sequence PPAB_DIFF is obtained, which includes four parts: path addition, deletion, modification and the same index.

[0030] For image elements, the MD5 value, position, width and height information of the image bitmap data are extracted to generate the feature value sequences PITA and PITB of the image elements, namely [PIA1,PIA2,...,PIAn], [PIB1,PIB2,...,PIBm]. Then, the difference between PITA and PITB is compared using the minimum editing algorithm, and the difference sequence PIAB_DIFF is obtained, which includes four parts: image addition, deletion, modification and the same index.

[0031] By generating a difference sequence of pages, texts, paths and images, the differences of pages, texts, paths and image elements in the document can be clearly displayed, providing users with a more intuitive and convenient way of comparison. At the same time, the feature value extraction and comparison of page content, text elements, path elements and image elements also ensures the accuracy and efficiency of the comparison, providing users with a more reliable and efficient PDF comparison tool.

[0032] The present invention can improve the computing performance and efficiency of internal devices or external devices. By using the minimum editing algorithm to compare the differences of PDF documents, the amount of calculation in the comparison process can be greatly reduced, and the comparison speed can be improved. Compared with traditional PDF comparison tools, the present invention can ensure the accuracy and efficiency of comparison while greatly reducing computing resources, thereby improving the performance and efficiency of internal and external devices. The present invention can improve the accuracy and precision of PDF comparison. By extracting key information of text, path and image elements, the present invention can accurately detect the differences in PDF documents, avoiding the problems of missed detection, false detection and the like that may exist in traditional comparison tools. At the same time, the present invention adopts the MD5 algorithm to generate the element feature value sequence, which can effectively avoid the problem of feature value conflict and improve the accuracy and reliability of comparison. The present invention can improve the stability of PDF comparison. The present invention adopts advanced technical means, such as the minimum editing algorithm, the MD5 algorithm, etc., which can ensure the stability and reliability of comparison. At the same time, the present invention uses a simple and intuitive interface design, so that users can easily use the tool to complete the comparison operation, thereby improving the user's trust and satisfaction with the tool. In summary, the PDF comparison tool provided by the present invention has multiple beneficial effects such as improved computing performance and efficiency, improved accuracy and precision, and improved stability, and can provide users with more efficient, accurate, and stable PDF comparison services, thereby improving user experience and satisfaction.

[0033] The above are only preferred specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for comparing PDF files based on minimum edit distance, characterized in that: include: Rendering a page of the first PDF file and a page of the second PDF file to obtain a first bitmap and a second bitmap after rendering, calculating MD5 values ​​of the first bitmap and the second bitmap respectively, and obtaining a feature value sequence of the first PDF file page and a feature value sequence of the second PDF file page; Comparing the difference between the feature value sequence of the first PDF file page and the feature value sequence of the second PDF file page according to a minimum editing algorithm to obtain a difference sequence; For the pages marked as modified in the difference sequence, text element type, image element type and path element type are compared respectively to complete the comparison between the first PDF file and the second PDF file.

2. The method for comparing PDF files based on minimum edit distance as claimed in claim 1, characterized in that: Rendering a page of the first PDF file and a page of the second PDF file includes: The pages of the first PDF file and the pages of the second PDF file are rendered into 400*400 bitmaps.

3. The method for comparing PDF files based on minimum edit distance as claimed in claim 1, characterized in that: Calculating the MD5 values ​​of the first bitmap and the second bitmap respectively also includes introducing a hash algorithm to convert the content of the bitmap into a characteristic value.

4. The method for comparing PDF files based on minimum edit distance as claimed in claim 1, characterized in that: Obtaining the difference sequence includes: Compare the feature value sequence of the first PDF file page with the feature value sequence of the second PDF file page, obtain identical parts, and mark the identical parts as identical indexes; Comparing the feature value sequence of the first PDF file page with the feature value sequence of the second PDF file page, marking a portion that exists in the feature value sequence of the first PDF file page but does not exist in the feature value sequence of the second PDF file page as an index for page deletion; comparing the feature value sequence of the first PDF file page with the feature value sequence of the second PDF file page, and marking a portion that is present in the feature value sequence of the second PDF file page but not in the feature value sequence of the first PDF file page as an index for page addition; The feature value sequence of the first PDF file page and the feature value sequence of the second PDF file page are compared, and parts of the feature value sequence of the first PDF file page and the feature value sequence of the second PDF file page that exist but have different contents are marked as page updated indexes.

5. The method for comparing PDF files based on minimum edit distance as claimed in claim 1, characterized in that: Comparing the text element type differences of the pages marked as modified in the difference sequence includes: For the pages marked as modified in the difference sequence, extract the text content, font size and color to generate a first text element feature value sequence and a second text element feature value sequence; The difference between the first text element feature value sequence and the second text element feature value sequence is compared using a minimum editing algorithm to obtain a text difference sequence, and the text difference sequence is marked with a text addition index, a text deletion index, a text modification index and a text identical index.

6. The method for comparing PDF files based on minimum edit distance as claimed in claim 1, characterized in that: Comparing the path element type differences of the pages marked as modified in the difference sequence includes: For the pages marked as modified in the difference sequence, extract the data information of the path points, serialize the point set into a string and convert it into an MD5 value, and generate a feature value sequence of the first path element and a feature value sequence of the second path element; The difference between the feature value sequence of the first path element and the feature value sequence of the second path element is compared using a minimum editing algorithm to obtain a path difference sequence, and the path addition index, path deletion index, path modification index and path identical index are marked in the path difference sequence.

7. The method for comparing PDF files based on minimum edit distance as claimed in claim 1, characterized in that: Comparing the image element type differences of the pages marked as modified in the difference sequence includes: For the pages marked as modified in the difference sequence, the MD5 value, position, width and height information of the bitmap data of the image are obtained in advance to generate a feature value sequence of the first image element and a feature value sequence of the second image element; The difference between the feature value sequence of the first image element and the feature value sequence of the second image element is compared using a minimum editing algorithm to obtain an image difference sequence, and the image difference sequence is marked with an image addition index, an image deletion index, an image modification index and an image identical index.