Triggered Actions

Help
Anonymous
2012-10-10
2013-05-28

  • Anonymous
    2012-10-10

    Hello,

    How do I create a triggered action?

    What I have so far:

    PDAction notification = PDActionJavaScript.createNew('app.alert("Please close this tab.");')
    notification.cosGetDict().put(PDAdditionalActions.CN_trigger_DP, page.cosGetObject())
    

    The goal is to get the "Please close this tab" message to appear once the "DidPrint" trigger is triggered.

    Thanks for the help!

     

  • Anonymous
    2012-10-10

    Well the following code seems to work in Adobe Reader, but causes Chrome to blow up. Does it look accurate?

    PDAction notification = PDActionJavaScript.createNew('app.alert("Please close this tab.");') 
    PDAdditionalActions actions = PDAdditionalActions.META.createFromCos(notification.cosGetDict())
    actions.addAction(PDAdditionalActions.CN_trigger_DP, notification)
    actions.addAction(PDAdditionalActions.CN_trigger_DS, notification)
    document.setAdditionalActions(actions)
    
     
  • Elfi Heck
    Elfi Heck
    2012-10-11

    This code creates a new COS dictionary for your javascript action then creates a new additional actions object backed by the same dictionary. Then you add the action to the additional actions which on the COS level adds the dictionary to itself. Adobe reader seems to be able to detect the loop created by this but obviously Chrome does not. You need to change the "createFromCos" to "createNew".
    Generally every PDObject will have it's own dictionary so if you're creating a document from scratch you'll always need createNew(). createFromCos() is for existing dictionaries which you might have copied from another or read from an existing pdf file for example.