Monday, July 30, 2018

Setting a very low security expiry date on a pdf

Sometimes one wants someone (even oneself) to have a PDF that becomes unviewable past a certain date, but the expiry isn't meant to be secure--perhaps one is sharing a manuscript between friends but one doesn't want one's friend to access an out of date version.

Here's a simple way that works with Adobe's Acrobat Reader and maybe some other readers (but not all others--e.g., Sumatra ignores the expiry entirely), based on combining two ideas I found online. It only works on PDFs that haven't already been compressed or encrypted. Load the PDF into a text editor. Find the code /Type /Catalog. Insert this bit of code right after that code, changing the date to match your needs:
/Type /Catalog
/Names <<
    /JavaScript <<
      /Names [
        (EmbeddedJS)
        <<
          /S /JavaScript
          /JS (
var rightNow = new Date();
var endDate = new Date(2018, 7, 10); // expiry date: year, month (0=Jan, 11=Dec), day
if(rightNow.getTime() > endDate)
{
app.alert("This document has expired.");
this.closeDoc();
}
          )
        >>
      ]
    >>
  >>
Then load it into Acrobat Reader. Acrobat Reader should display it, but when you exit it will ask to save the file. Agree, as this will hide the above code and make it no longer easy to edit.

No comments:

Post a Comment