Hi,

> Am 14.07.2015 um 18:12 schrieb Tilman Hausherr <[email protected]>:
> 
> Yesterday I wrote a tool to show the Javascript code in a PDF. Some widgets 
> did have Javascript, but it wasn't possible to access this with our methods 
> (e.g. getK()), only by accessing the COSDictionary structure directly. The 
> reason is that these widgets have a getActions() method that return 
> PDAnnotationAdditionalActions and not PDFormFieldAdditionalActions. Here's my 
> code, which shows my workaround (at the line with "Merkwürdig"):
> 
>        if (field instanceof PDTerminalField)
>        {
>            PDTerminalField termField = (PDTerminalField) field;
>            for (PDAnnotationWidget widget : termField.getWidgets())
>            {
>                PDAction action = widget.getAction();
>                if (action instanceof PDActionJavaScript)
>                {
>                    System.out.println(field.getFullyQualifiedName() + ": " + 
> action.getClass().getSimpleName() + " js widget action:\n" + 
> action.getCOSObject());
>                    printPossibleJS(action);
>                }
>                PDAnnotationAdditionalActions actions = widget.getActions();
>                if (actions != null)
>                {
>                    System.out.println(field.getFullyQualifiedName() + ": " + 
> actions.getClass().getSimpleName() + " js widget actionS:\n" + 
> actions.getCOSObject());
> 
>                    // Merkwürdig, wieso bekomme ich nicht 
> PDFormFieldAdditionalActions sondern ein PDAnnotationAdditionalActions in dem 
> ein K ist aber kein getK() ?
>                    PDFormFieldAdditionalActions ffActions = new 
> PDFormFieldAdditionalActions((COSDictionary) actions.getCOSObject());
>                    printPossibleJS(ffActions.getK());
>                    printPossibleJS(ffActions.getC());
>                    printPossibleJS(ffActions.getF());
>                    printPossibleJS(ffActions.getV());
>                }
>            }
>        }
> 

would you have a sample file?

BR
Maruan

> ....
> 
>    private void printPossibleJS(PDAction kAction)
>    {
>        if (kAction instanceof PDActionJavaScript)
>        {
>            PDActionJavaScript jsAction = (PDActionJavaScript) kAction;
>            String jsString = jsAction.getAction();
>            if (!jsString.contains("\n"))
>            {
>                // Sonst erscheint in Netbeans nichts?!
>                jsString = jsString.replaceAll("\r", "\n").replaceAll("\n\n", 
> "\n");
>            }
>            System.out.println(jsString);
>            System.out.println();
>        }
>    }
> 
> So I'm wondering if this is a bug in the code, or rather the problem that 
> widgets are used both for annotations and fields?
> 
> Tilman
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to