Hi Team,
we are trying to set expiration to the PDF File. Below is the code . Expired PDF is getting closed in Adobe Reader but not getting closed when opened in browsers like Chrome, Firefox etc.
I want to check if we could add any javascript which doesnt allow the PDF File to be read in Browsers when expired. Could you please suggest.
Code:
Document doc = new Document();
doc.getPages().add();
java.time.LocalDate date1=java.time.LocalDate.now().minusDays(10);
int year = date1.getYear();
int mon=date1.getMonthValue();
int dated=date1.getDayOfMonth();
JavascriptAction javaScript = new JavascriptAction(
“// Get the current date and time\n” +
“var rightNow = new Date();\n” +
“var endDate = new Date(2021, 03, 01);\n” +
“if(rightNow > endDate)\n” +
“{\n” +
“app.alert(“This Document has Expired.”);\n” +
“this.closeDoc();\n” +
“}”);
doc.setOpenAction(javaScript);
doc.save(dataDir + “PDFExpiry.pdf”);
Thanks,
Karthik