public static void main(String[] args) throws IOException { // Load the PDF document created by SimpleForm.java try (PDDocument document = PDDocument.load(new File("target/SimpleForm.pdf"))) { // Note that the JavaScript will depend on the reader application. // The classes and methods available to Adobe Reader and Adobe Acrobat // are documented in the Acrobat SDK. String javaScript = "var now = util.printd('yyyy-mm-dd', new Date());" + "var oField = this.getField('SampleField');" + "oField.value = now;"; // Create an action as JavaScript action PDActionJavaScript jsAction = new PDActionJavaScript(); jsAction.setAction(javaScript); // Set the action to be executed when the document is opened document.getDocumentCatalog().setOpenAction(jsAction); document.save("target/UpdateFieldOnDocumentOpen.pdf"); } } }
/** * This will print the documents data. * * @param args The command line arguments. * * @throws IOException If there is an error parsing the document. */ public static void main( String[] args ) throws IOException { if( args.length != 2 ) { usage(); } else { try (PDDocument document = PDDocument.load(new File(args[0]))) { PDActionJavaScript javascript = new PDActionJavaScript( "app.alert( {cMsg: 'PDFBox rocks!', nIcon: 3, nType: 0, cTitle: 'PDFBox Javascript example' } );"); document.getDocumentCatalog().setOpenAction( javascript ); if( document.isEncrypted() ) { throw new IOException( "Encrypted documents are not supported for this example" ); } document.save( args[1] ); } } }
PDActionJavaScript jsEnterAction = new PDActionJavaScript(); jsEnterAction.setAction("app.alert(\"On 'enter' action\")"); annotationActions.setE(jsEnterAction); PDActionJavaScript jsExitAction = new PDActionJavaScript(); jsExitAction.setAction("app.alert(\"On 'exit' action\")"); annotationActions.setX(jsExitAction); PDActionJavaScript jsMouseDownAction = new PDActionJavaScript(); jsMouseDownAction.setAction("app.alert(\"On 'mouse down' action\")"); annotationActions.setD(jsMouseDownAction); PDActionJavaScript jsMouseUpAction = new PDActionJavaScript(); jsMouseUpAction.setAction("app.alert(\"On 'mouse up' action\")"); annotationActions.setU(jsMouseUpAction); PDActionJavaScript jsFocusAction = new PDActionJavaScript(); jsFocusAction.setAction("app.alert(\"On 'focus' action\")"); annotationActions.setFo(jsFocusAction); PDActionJavaScript jsBlurredAction = new PDActionJavaScript(); jsBlurredAction.setAction("app.alert(\"On 'blurred' action\")"); annotationActions.setBl(jsBlurredAction); PDActionJavaScript jsKeystrokeAction = new PDActionJavaScript(); jsKeystrokeAction.setAction("app.alert(\"On 'keystroke' action\")"); fieldActions.setK(jsKeystrokeAction); PDActionJavaScript jsFormattedAction = new PDActionJavaScript();
PDActionJavaScript javascript = new PDActionJavaScript("this.print();");
retval = new PDActionJavaScript(action); break; case PDActionGoTo.SUB_TYPE:
public static void main(String[] args) throws IOException { // Load the PDF document created by SimpleForm.java PDDocument document = PDDocument.load(new File("target/SimpleForm.pdf")); // Note that the JavaScript will depend on the reader application. // The classes and methods available to Adobe Reader and Adobe Acrobat // are documented in the Acrobat SDK. String javaScript = "var now = util.printd('yyyy-mm-dd', new Date());" + "var oField = this.getField('SampleField');" + "oField.value = now;"; // Create an action as JavaScript action PDActionJavaScript jsAction = new PDActionJavaScript(); jsAction.setAction(javaScript); // Set the action to be executed when the document is opened document.getDocumentCatalog().setOpenAction(jsAction); document.save("target/UpdateFieldOnDocumentOpen.pdf"); document.close(); } }
if( PDActionJavaScript.SUB_TYPE.equals( type ) ) retval = new PDActionJavaScript( action );
PDActionJavaScript jsEnterAction = new PDActionJavaScript(); jsEnterAction.setAction("app.alert(\"On 'enter' action\")"); annotationActions.setE(jsEnterAction); PDActionJavaScript jsExitAction = new PDActionJavaScript(); jsExitAction.setAction("app.alert(\"On 'exit' action\")"); annotationActions.setX(jsExitAction); PDActionJavaScript jsMouseDownAction = new PDActionJavaScript(); jsMouseDownAction.setAction("app.alert(\"On 'mouse down' action\")"); annotationActions.setD(jsMouseDownAction); PDActionJavaScript jsMouseUpAction = new PDActionJavaScript(); jsMouseUpAction.setAction("app.alert(\"On 'mouse up' action\")"); annotationActions.setU(jsMouseUpAction); PDActionJavaScript jsFocusAction = new PDActionJavaScript(); jsFocusAction.setAction("app.alert(\"On 'focus' action\")"); annotationActions.setFo(jsFocusAction); PDActionJavaScript jsBlurredAction = new PDActionJavaScript(); jsBlurredAction.setAction("app.alert(\"On 'blurred' action\")"); annotationActions.setBl(jsBlurredAction); PDActionJavaScript jsKeystrokeAction = new PDActionJavaScript(); jsKeystrokeAction.setAction("app.alert(\"On 'keystroke' action\")"); fieldActions.setK(jsKeystrokeAction); PDActionJavaScript jsFormattedAction = new PDActionJavaScript();
PDActionJavaScript javascript = new PDActionJavaScript( "app.alert( {cMsg: 'PDFBox rocks!', nIcon: 3, nType: 0, cTitle: 'PDFBox Javascript example' } );"); document.getDocumentCatalog().setOpenAction( javascript );
if (handler.getAttributeValue(elem, "onclick") != null && !"".equals(handler.getAttributeValue(elem, "onclick"))) { action = new PDActionJavaScript(handler.getAttributeValue(elem, "onclick")); } else { PDActionGoTo go = new PDActionGoTo();
if (handler.getAttributeValue(elem, "onclick") != null && !"".equals(handler.getAttributeValue(elem, "onclick"))) { action = new PDActionJavaScript(handler.getAttributeValue(elem, "onclick")); } else { PDActionGoTo go = new PDActionGoTo();
if (handler.getAttributeValue(elem, "onclick") != null && !"".equals(handler.getAttributeValue(elem, "onclick"))) { action = new PDActionJavaScript(handler.getAttributeValue(elem, "onclick")); } else { PDActionGoTo go = new PDActionGoTo();
doc.getDocumentCatalog().setAcroForm(acroForm); PDActionJavaScript javascript = new PDActionJavaScript( "function validate(index){ app.alert(index); }"); doc.getDocumentCatalog().setOpenAction(javascript); PDActionJavaScript tfJs = new PDActionJavaScript("validate("+1+");"); PDAnnotationAdditionalActions tfAction = new PDAnnotationAdditionalActions(); tfAction.setU(tfJs);
doc.getDocumentCatalog().setAcroForm(acroForm); PDActionJavaScript javascript = new PDActionJavaScript("function validate(index){ app.alert(index); }"); doc.getDocumentCatalog().setOpenAction( javascript ); button.setValue("Validate Button"); PDActionJavaScript tfJs = new PDActionJavaScript("validate("+1+");"); PDAnnotationAdditionalActions tfAction = new PDAnnotationAdditionalActions(); tfAction.setU(tfJs);
retval = new PDActionJavaScript(action); break; case PDActionGoTo.SUB_TYPE: