We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

PDF Expiration - Browsers - Add Corrupt JavaScript

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

@karthik13

We have already shared the detailed findings with you in this thread.

Hi Fayyaz,

This Solution is not feasible as we want the users to not see the contents of document after specific period of time. if we add password, it would ask the password each time user opens the document. Please suggest.

Thanks,
Karthik

@karthik13

We are afraid that we cannot offer much in this case. As we already have shared all limitations with you, we regret that no solution would be possible for your case. In case you need more information or face any issues related to other functionalities of the API, please feel free to let us know.