0
votes

Can I use iText API for comparing two PDF files? I have gone through various approaches on stackoverflow for comparing PDF files such as tools, some utilities such as imagemagick etc. The PDFs which I wish to compare are fiancial reports with graphs, tables and text etc. We have to compare a large number of files and would like to do it through command line utility. There is a ComparePDF command line tool but its just outputs whether two files are conatining differences. We will like to print a log of file differences. Can we accomplish this through iText?

2
Do you want to compare text containing in the PDF ? - Bhavik Ambani
I see multiple comments / answers asking you to clarify your question, but the details don't come. As it is now nearly two months old I assume you either found a solution or gave up... If you did find a solution, posting it here for for future reference would be cool. You could do something back for others looking for answers to this. As it stands I gave the question a -1. Unclear and no feedback to the people trying to help you. - Stijn de Witt
I understand and apologize. We still have not found any solution. We thought iText could achieve it but as the comments sugested u need to use a combination of technologies to achieve this. I did not get enough time after this to do more research. One thing on my mind is trying modifying the code of diffpdf tool so that it can be automaticly called for a large number of files. The tool is nice and does what we need but its UI has not been automated. - GordanWebb

2 Answers

6
votes

What do you want to compare? iText could be used to compare structure and syntax, but... two different PDFs that look identical to the human eye, may have a completely different structure and syntax internally.

At iText, we have written JUnit tests that use GhostScript to create images of each page. These images are compared to each other on a pixel per pixel basis.

We also use iText in JUnit tests, but these tests look at the structure and the syntax more than at the content.

0
votes

You need to use the Myers O(ND) diff algorithm for PDF comparison , itext or pdfbox api dont provide the method for pdf comparison , you can extract the text of these files and coordinates using itext , later use the Myers O(ND) diff algorithm to find the difference and highlight the changes.