pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maruan Sahyoun <sahy...@fileaffairs.de>
Subject Re: Getting the javascript from form field widgets
Date Thu, 16 Jul 2015 20:55:10 GMT
Hi,

> Am 14.07.2015 um 18:12 schrieb Tilman Hausherr <THausherr@t-online.de>:
> 
> 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: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
View raw message