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.
Find out more about our software for Developers
|Convert PDF to HTML5 or SVG|
|Convert AcroForms and XFA to HTML5|
|Java PDF SDK for working with PDF files|