# Difference between two PDF files?

**URL:** <https://boards.straightdope.com/t/difference-between-two-pdf-files/472839>\
**Category:** Factual Questions\
**Created:** [November 15, 2008, 10:09am UTC](https://boards.straightdope.com/t/difference-between-two-pdf-files/472839 "2008-11-15T10:09:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Will\_Repair](https://avatars.discourse-cdn.com/v4/letter/w/a698b9/32.png) [@Will\_Repair](https://boards.straightdope.com/u/Will_Repair)\
**Post date:** [November 15, 2008, 10:09am UTC](https://boards.straightdope.com/t/difference-between-two-pdf-files/472839/1 "2008-11-15T10:09:57Z")

</div>

I’m going through thirty gigs of files from various sources trying to sort them. A lot of the original PDF files have been modified by someone adding their name to the first page. That’s easy to spot. But this is only one case of many I expect to encounter.

They are 16 pages of schematics. I see no difference other than the size. Konqueror with KPDF only shows a difference in the modified date and will open both of them. PDFEdit will not open the smaller file.

[517.6KB File](http://willrepair.com/SDMB/SmallFile.pdf)  
[899.7KB File](http://willrepair.com/SDMB/LargeFile.pdf)

Doubtful but is there anyway to find out what was modified, such as a table of contents added?

Is there a command line program that will list the differences between various PDF files?

---

<div class="post-metadata">

**Author:** ![psychonaut](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/psychonaut/32/4655_2.png) [@psychonaut](https://boards.straightdope.com/u/psychonaut)\
**Post date:** [November 15, 2008, 11:42am UTC](https://boards.straightdope.com/t/difference-between-two-pdf-files/472839/2 "2008-11-15T11:42:19Z")

</div>

> [@Will\_Repair](#):
>
> Is there a command line program that will list the differences between various PDF files?

To compare the text, use [GNU diff](http://www.gnu.org/software/diffutils/diffutils.html) (or your favourite GUI therefor) and [xpdf’s pdftotext](http://www.foolabs.com/xpdf/):

```auto

$ pdftotext file1.pdf >file1.txt
$ pdftotext file2.pdf >file2.txt
$ diff file1.txt file2.txt

```

To compare the metadata (title, author, bookmarks, etc.), use diff and [pdftk](http://www.accesspdf.com/pdftk/):

```auto

$ pdftk file1.pdf dump_data output file1.txt
$ pdftk file2.pdf dump_data output file2.txt
$ diff file1.txt file2.txt

```

To do very low-level comparison (for which you will probably need to know a bit about the PDF file format, which is a bit like PostScript), you can use pdftk to decompress the page stream:

```auto

$ pdftk file1.pdf output file1_uncompressed.pdf uncompress
$ pdftk file2.pdf output file2_uncompressed.pdf uncompress
$ diff file1_uncompressed.pdf file2_uncompressed.pdf

```

---

<div class="post-metadata">

**Author:** ![psychonaut](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/psychonaut/32/4655_2.png) [@psychonaut](https://boards.straightdope.com/u/psychonaut)\
**Post date:** [November 15, 2008, 12:01pm UTC](https://boards.straightdope.com/t/difference-between-two-pdf-files/472839/3 "2008-11-15T12:01:02Z")

</div>

Oh, and I just thought of a way to do visual page-by-page comparisons, which works even with pages that have graphics. You will end up with a PDF with the differences highlighted in red. Assume your two PDFs are called foo.pdf and bar.pdf with N pages. Then do the following (in bash):

```auto

$ pdftk foo.pdf burst output foo_%d.pdf
$ pdftk bar.pdf burst output bar_%d.pdf
$ for f in {1..N};do compare foo_$f.pdf bar_$f.pdf foobar_$f.pdf;done
$ pdftk foobar_{1..N}.pdf cat output foobar.pdf

```

These commands use pdftk’s burst function to split the PDF files into one file per page. It then calls ImageMagick’s compare function on each pair of files to produce a “difference” image. Then pdftk’s cat function is called to stitch the difference images back together into a PDF called foobar.pdf. View the PDF in your favourite PDF viewer and you’ll see all the parts that are the same in grey, and all the parts that are different in red.

---

<div class="post-metadata">

**Author:** ![Koxinga](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@Koxinga](https://boards.straightdope.com/u/Koxinga)\
**Post date:** [November 15, 2008, 5:23pm UTC](https://boards.straightdope.com/t/difference-between-two-pdf-files/472839/4 "2008-11-15T17:23:58Z")

</div>

You could print the pages out, place them side by side, and use [my method](http://boards.straightdope.com/sdmb/showpost.php?p=9089307&postcount=34).
