Closed LukeXF closed 3 years ago
Looks like addJavascript
was included in the latest commit 9 days ago https://github.com/Hopding/pdf-lib/pull/654 but has this been deployed in the latest version?
Version 1.11.2 doesn't seem to include any reference to addJavascript
https://unpkg.com/pdf-lib@1.11.2/dist/pdf-lib.js
pdfDoc.addJavascript('main', 'var year=2020; var month=11;today = new Date();today = new Date(today.getFullYear(), today.getMonth());expiry = new Date(year, month);if (today.getTime() > expiry.getTime())app.alert(\'The file is expired. You need a new one.\');');
Hello @LukeXF! addJavaScript
will be released with the next version of pdf-lib
. I'm hoping to cut the next version this weekend.
This feature was just released in version 1.12.0
: https://pdf-lib.js.org/docs/api/classes/pdfdocument#addjavascript
I've noticed that JavaScript doesn't seem to run when viewing a generated PDF in Google Chrome but does work in Adobe Acrobat. Any suggestions on how to make a PDF expire @Hopding ?
I have been designing/developing interactive PDF forms since Adobe Acrobat debuted back around 1993. In answer to the question pertaining to making PDFs expire, while I don't know about PDFs generated with pdf-lib and other similar PDF generators, what I do know is that a PDF can be set to expire using javascript in a PDF created in Acrobat (FWIW, I was able to do this years ago using Adobe Acrobat). As such, it would appear to make sense this should work in a PDF created in another app such as pdf-lib. The downside is that if JS has not been enabled or disabled on the user's computer, a PDF contingent on JS to expire won't work in which event the only option remaining appears to be using a DRM (Digital Rights Management) tool. As for a script to prevent sharing of a PDF, why not just password protect the PDF and provide the password solely to those you want to allow to open/use the PDF?
Hey @boilermaker73, we did extensive research on this and decided the technology wasn't there for the strategy we wanted to do. We were planning on sending custom PDFs to hundreds of mobile devices but there were too many issues with JavaScript not being enabled.
Regarding setting a password, this would be unusable for us as the process was meant to be seamless to hundreds of users. But that is a good point for others looking for a similar solution
Hi guys, is it possible to make PDFs generated with pdf-lib expire?
For example, see this tutorial in C#/VB: https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Security/How-to-Add-Expiry-Date-to-PDF-Files-in-C-VB.NET.html
And another in Python: https://docs.aspose.com/pdf/java/set-pdf-expiration-in-python/
I'm trying to make a PDF expire on a person's device after they have downloaded it from the server.