下载日期戳 pdf

发布于 2024-10-16 22:39:32 字数 125 浏览 2 评论 0原文

我有一个 PDF 供用户下载。但是,我需要在 PDF 文本中注明下载日期。

有没有办法在 PDF 上插入“现在日期”印记,以便在打开时动态添加它?

也许您可以将 JavaScript 添加到 PDF 中?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坦然微笑 2024-10-23 22:39:32

您可以在将 PDF 提供给用户之前在服务器上对 PDF 进行签名和时间戳。签名可以每天执行一次(除非您需要更精细的粒度(如果时间戳时间))。这是为 PDF 添加时间戳的唯一可靠方法。另外,签名是可以删除的,如果你想添加一个不容易删除的水印,那就另当别论了。

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.

酒解孤独 2024-10-23 22:39:32

JS 听起来像是一个不错的选择……大多数情况下。

您可以在希望显示日期的位置添加一个空文本字段。当有人第一次打开 PDF 时,您可以设置该字段的值。

问题:

  1. Reader 无法保存更改的 PDF,除非已通过 Acrobat 启用 Reader。
  2. 该脚本将在 PDF 打开时运行,而不是在下载时运行。

如果你确实想标记他们的下载时间,你需要在服务器上进行。再次字段,只是这次有一些字节偏移量。

将关键字(或作者,无论如何......您不使用的文档信息字段之一)设置为一堆空白......足以容纳您最大的时间戳。在脚本中,当打开表单时,您始终将该信息字段写入时间戳字段。不用担心读者启用。

现在,要实际写入时间戳,您需要知道 PDF 中该信息字段的确切字节偏移量,并且您需要知道必须使用多少空白空间,这样您就不会意外溢出(这将是非常严重的)坏的)。当需要提供 PDF 时,您会吸收字节,更改时间戳,然后服务器这些修改后的字节。

这是最有效(也是最脆弱)的方法。


如果您希望以正确的方式做事,请使用您最喜欢的 PDF 库来更改表单值并提供生成的 PDF。不需要脚本,但服务器的工作量明显增加。


注意:多个字段可以共享相同的名称。它们也自动共享相同的值。因此,如果您希望时间戳显示在每个页面上,则不需要“timestamp1”、“timestamp2”等。您可以为所有字段指定相同的名称,然后设置一次值。 “您最喜欢的 PDF 库”可能无法很好地处理这个问题。 iText 这样做,我相信其他人也这样做。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文