Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save quantentunnels/e54480950faf5492b30b to your computer and use it in GitHub Desktop.
Save quantentunnels/e54480950faf5492b30b to your computer and use it in GitHub Desktop.

Diffing PDFs for git

Visual difftool

One can use MD5 or plain text diff to see differences in PDF files. If that's not enough, here's how to use diffpdf which knows how to diff based on appearance or words.

  • apt-get install diffpdf
  • edit your ~/.gitconfig to add this:
[difftool "diffpdf"]
  cmd = diffpdf \"$LOCAL\" \"$REMOTE\"
  • then use with:
git difftool --tool=diffpdf your_pdf_file.pdf
  • to always use that diff methods for pdf put the wollowing in your .gitattributes:
*.pdf difftool=diffpdf

Text mode

For command line use there ist pdftotext, which renders the PDF as plain text. The following instructions are from [https://tante.cc/2009/03/24/versioning-pdf-files-with-git/]

  • git needs the contents to diff on stdout. You have to write a short wrapper for pdftotext. Call it “pdf2txt”, put it in /usr/local/bin or if you have it in ~/bin. It contains:
#!/bin/bash
pdftotext $1 -
  • add the following to your ~/.gitconfig
[diff "pdf"]
    textconv = pdf2txt
  • In your repository edit the file .gitattributes and add the line
*.pdf diff=pdf
@quantentunnels
Copy link
Author

Git tricks for programming and tex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment