Time travel - how to edit PDFs from the past (on Mac)

Nov 22, 2021

If you want to modify a file so it looks like it was created or modified on a specific date, you've come to the right place.

For this example, I'll be using SmallPDF's example PDF.

 
TL;DR for the code wizards out there: use the touch -mt 202101310100 file.pdf command to change a file's created and modified dates (timestamp is in format YYYYMMDDHHSS). But watch out if your file is a PDF - you may need to clear the PDF's version history too (more on this below).

⏰ Changing a file's created and modified timestamps

If I open up my pdf-from-past folder in Finder, this is what I see:

A PDF created today
A PDF created today

sample.pdf was created and modified today (November 2021). Let's change it to January 2021.

Doctor Strange using the Time Stone
Doctor Strange using the Time Stone

Find your file in Terminal

  1. Open up Terminal (open Applications and launch Terminal.app)
  1. Enter the folder where your file lives, using the cd (change directory) command. For example, I'm entering my pdf-from-past folder with the command:
    1. cd Downloads/blog-samples/pdf-from-past
  1. Use the ls command to list files & directories in your current folder - your target file should be in there (mine is called sample.pdf):
    1. notion image

Use "touch" to change the file's timestamps

Change the file's created and modified dates with the touch -mt TIMESTAMP FILE command. For example, set sample.pdf's dates to 31 January 2021 at 0100:

touch -mt 202101310100 sample.pdf

The timestamp is in format YYYYMMDDHHSS. The result:

notion image
 

If you want to change the file's modified date, run the command again with a new timestamp. For example, change its modified date to 3 February 2021 at 0400:

touch -mt 202102030400 sample.pdf

The result:

notion image

And you're done! Time travel complete... unless your file is a PDF. 🤔

 

🚮 Clearing version history for PDFs

The Preview app on Mac supports version history for PDFs. Even after you've edited the PDF's metadata, the file's version history might reveal when it was actually edited.

When version history contradicts your PDF's timestamps
When version history contradicts your PDF's timestamps
 

Check if your PDF contains any previous versions

  1. Open your PDF using Preview on Mac
  1. Go to File > Revert To
  1. Does the list contain anything except "Browse All Versions..."?
 

My PDF contains one previous version:

My PDF contains one previous version (Last Opened - Today 15:00)
My PDF contains one previous version (Last Opened - Today 15:00)

Compress the PDF to wipe the file's version history

I couldn't figure out an easy way to clear a PDF's version history in Preview (please email me if you figure it out!) so I figured out a workaround: compress the PDF.

 

If your PDF contains sensitive data, compress it locally using a tool like Ghostscript.

 

For non-sensitive files, I just use SmallPDF because it's a bit easier.

⚠️
Do not upload sensitive files like identification or tax returns to SmallPDF (or any similar websites) - only process sensitive files on your own machine.
 
  1. Visit SmallPDF's compress PDF tool
  1. Upload your file
  1. Compress the file using "Basic compression"
    1. Performing "basic compression" on SmallPDF
      Performing "basic compression" on SmallPDF
  1. Download the compressed file
 

Now open the compressed file in Preview and check File > Revert To:

notion image
 

The versions list is empty! Nice!

 

However... our compressed file's timestamps are wrong. We need to change them again.

notion image

We can re-use the same commands from before and just tweak the filename to use the new file:

touch -mt 202101310100 sample-compressed.pdf
touch -mt 202102030400 sample-compressed.pdf
 

Done! The new sample-compressed.pdf file is smaller, doesn't have a version history, and has the correct created and modified dates! ⚡

Comparing the original and compressed file... both with the correct timestamps
Comparing the original and compressed file... both with the correct timestamps