It is quite a frequent question on the PDF forums, asking how to compare 2 versions of a PDF file to see what has changed. This is actually one of those cases where generally the person means something slightly different.
Usually, this means ‘how can I see what has changed visually‘. PDF is a flexible file format in which you can do things in many different ways. So you could create 2 different PDF versions of a file using Acrobat and Ghostscript (as an example). The files would (hopefully) be identical. But the files would be different sizes and the internal structure of each would be very different.
As part of developing a PDF library, we want to do an awful lot of regression testing to make sure that we do not break anything. So we need to compare a lot of files. We also like to test each change individually so we can investigate any problems.
So the way we compare PDF files is to extract the text and to convert the PDF to a png. Here is the Java code we use. We compare this against a baseline. You still need a human to verify any changes, but it does provide very quick regression tests.
If the results are identical, we can be confident that the file has not changed. And doing the same with 2 PDF files allows you to quickly review and changes, especially if you get the comparison to highlight the area on the PNG which has changed.
We find that a very good way to compare PDF file results. What works for you?
Are you a Developer working with PDF files?
Our developers guide contains a large number of technical posts to help you understand the PDF file Format.
Do you need to solve any of these problems?
Display PDF documents in a Web app |
Use PDF Forms in a web browser |
Convert PDF Documents to an image |
Work with PDF Documents in Java |
I wrote a tool for comparing two PDFs easily, see http://github.com/vslavik/diff-pdf
It can produce a new PDF with the changes marked up and has an interactive GUI for inspecting the changes as well.