date stamp pdf on download

1.9k views Asked by At

I have a PDF which users can download. However, I need to have the date it was downloaded in the text on the PDF.

Is there a way to insert a "date now" stamp on a PDF so it is dynamically added on opening?

Perhaps you can add javascript to a PDF?

2

There are 2 answers

0
Mark Storer On

JS sounds like the way to go... mostly.

You could add an empty text field where you want the date to appear. When someone opens the PDF for the first time, you could then set the field's value.

ISSUES:

  1. Reader cannot save changed PDFs unless they have been Reader Enabled via Acrobat.
  2. The script will run when the PDF is opened not when it is downloaded.

If you really want to mark their download time, you need to do it on the server. Fields again, only this time with some byte offset monkeying.

Set the keywords (or author, whatever... one of the Doc Info fields you're not using) to a bunch of empty spaces... enough to accommodate your largest timestamp. In script, when the form is opened, you ALWAYS write that info field to your timestamp field. No worries about reader enabling.

Now, to actually write the timestamp, you need to know the exact byte offset of that info field in your PDF, and you need to know how much empty space you have to work with so you don't accidentally overflow (that would be Very Bad). When the time comes to serve up your PDF, you suck up the bytes, change the ones for your time stamp, and server those modified bytes.

That's the most efficient (and brittle) way to do it.


If you'd rather do things The Right Way, use your favorite PDF library to change the form value and serve up the resulting PDF. No script required, but significantly more work for your server.


Note: Multiple fields can share the same name. They automagically share the same value as well. So if you want the time stamp to show up on every page, you don't need "timestamp1", "timestamp2", and so on. You can give all the fields the same name, then set the value once. "Your favorite PDF library" might not handle this terribly well. iText does, I'm sure others do also.

0
Eugene Mayevski 'Callback On

You can sign and timestamp the PDF on the server before giving it to the user. Signing can be performed once a day (unless you need finer granularity if timestamp time). This is the only reliable way to put a timestamp to the PDF. Also, the signature can be removed, and if you want to add a watermark which can't be easily removed, this is a different story.