<repositories> <repository> <id>com.e-iceblue</id> <url>http://repo.e-iceblue.cn/repository/maven-public/</url> </repository> </repositories><dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.pdf.free</artifactId> <version>3.9.0</version> </dependency></dependencies>
代码示例import com.spire.pdf.FileFormat;import com.spire.pdf.PdfDocument;import com.spire.pdf.actions.PdfJavaScriptAction;public class ExpiryDate { public static void main(String[] args) { //创建PdfDocument对象 PdfDocument doc = new PdfDocument(); //加载一个PDF文档 doc.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.pdf"); //通过JavaScript设置过期时间,过期警告信息并关闭文档 String javaScript = "var rightNow = new Date();" + "var endDate = new Date('February 23, 2021 16:40:59');" + "if(rightNow.getTime() > endDate)" + "app.alert('该文档已过期,请联系我们获取新文档',1);" + "this.closeDoc();"; //根据JS创建PdfJavaScriptAction PdfJavaScriptAction js = new PdfJavaScriptAction(javaScript); //将PdfJavaScriptAction设置为文档打开后的动作 doc.setAfterOpenAction(js); //保存文档 doc.saveToFile("output/ExpiryDate.pdf", FileFormat.PDF); }}
结果文档(图片来源网络,侵删)
0 评论