public static function run($dataDir = null) { # Open a pdf document. $doc = new Document($dataDir . "input1.pdf"); $javascript = new JavascriptAction("var year=2014;\n var month=4;\n today = new Date();\n today = new Date(today.getFullYear(), today.getMonth());\n expiry = new Date(year, month);\n if (today.getTime() > expiry.getTime())\n app.alert('The file is expired. You need a new one.');"); $doc->setOpenAction($javascript); # save update document with new information $doc->save($dataDir . "set_expiration.pdf"); print "Update document information, please check output file." . PHP_EOL; }
public static function run($dataDir = null) { # Open a pdf document. $doc = new Document($dataDir . "input1.pdf"); # Adding JavaScript at Document Level # Instantiate JavascriptAction with desried JavaScript statement $javaScript = new JavascriptAction("this.print({bUI:true,bSilent:false,bShrinkToFit:true});"); # Assign JavascriptAction object to desired action of Document $doc->setOpenAction($javaScript); # Adding JavaScript at Page Level $doc->getPages()->get_Item(2)->getActions()->setOnOpen(new JavascriptAction("app.alert('page 2 is opened')")); $doc->getPages()->get_Item(2)->getActions()->setOnClose(new JavascriptAction("app.alert('page 2 is closed')")); # Save PDF Document $doc->save($dataDir . "JavaScript-Added.pdf"); print "Added JavaScript Successfully, please check the output file."; }