|
// Loads PDF document
PdfLoadedDocument lDoc = new PdfLoadedDocument("file.pdf");
//Creates a new document
PdfDocument document = new PdfDocument();
//Imports the pages from the lDoc
document.ImportPageRange(lDoc, 0, lDoc.Pages.Count - 1);
PdfJavaScriptAction javaAction = new PdfJavaScriptAction("app.alert(\"Hello World !!! \")");
document.Actions.AfterOpen = javaAction;
//Saves the document
document.Save("sample.pdf");
//Closes the documents
document.Close(true);
lDoc.Close(true); |
|
//Javascript action to validate date and throw alert message.
PdfJavaScriptAction javaAction = new PdfJavaScriptAction("var myDate = new Date(2020, 05, 19); var today = Date.now(); if (myDate < today) { app.alert(\"This files has expired at 19/06/2020.\"); }");
//Add action to execute the script while opening the PDF document
document.Actions.AfterOpen = javaAction; |
In regards to the PdfJavaScriptAction, is there a way to have the expiration date (expireDate), dynamic, say 30 days from the day the pdf was downloaded?
PdfJavaScriptAction scriptAction = new PdfJavaScriptAction("function Expire()" +
"{var currentDate = new Date();" +
"var expireDate = new Date(2018, 9, 30);" +
"if (currentDate > expireDate)" +
"{app.alert(\"This Document has Expired.\");" +
"this.closeDoc();}" +
"} " +
" Expire(); ");
|
DateTime startDate = DateTime.Now.Date;
DateTime expiryDate1 = startDate.AddDays(15);
PdfJavaScriptAction scriptAction = new PdfJavaScriptAction("function Expire()
{
var currentDate = new Date();
var expireDate = new Date("+ expiryDate1.Year.ToString() + "," + expiryDate1.Month.ToString() + "," + expiryDate1.Day.ToString() + ");
if (currentDate > expireDate)
{
app.alert(\"This Document has Expired.\");
this.closeDoc();
}
}
Expire();
");
|
It's great Gowthamraj!
Is there any way to avoid bypass this method by disabling Javascript?
Or, in other hand, to overwrite the file to avoid any other bypass?
Thanks a lot.