use of org.apache.pdfbox.pdmodel.interactive.action.PDAnnotationAdditionalActions in project tika by apache.
the class AbstractPDF2XHTML method handleWidget.
private void handleWidget(PDAnnotationWidget widget) throws TikaException, SAXException, IOException {
if (widget == null) {
return;
}
handleDestinationOrAction(widget.getAction(), ActionTrigger.ANNOTATION_WIDGET);
PDAnnotationAdditionalActions annotationActions = widget.getActions();
if (annotationActions != null) {
handleDestinationOrAction(annotationActions.getBl(), ActionTrigger.ANNOTATION_LOSE_INPUT_FOCUS);
handleDestinationOrAction(annotationActions.getD(), ActionTrigger.ANNOTATION_MOUSE_CLICK);
handleDestinationOrAction(annotationActions.getE(), ActionTrigger.ANNOTATION_CURSOR_ENTERS);
handleDestinationOrAction(annotationActions.getFo(), ActionTrigger.ANNOTATION_RECEIVES_FOCUS);
handleDestinationOrAction(annotationActions.getPC(), ActionTrigger.ANNOTATION_PAGE_CLOSED);
handleDestinationOrAction(annotationActions.getPI(), ActionTrigger.ANNOTATION_PAGE_NO_LONGER_VISIBLE);
handleDestinationOrAction(annotationActions.getPO(), ActionTrigger.ANNOTATION_PAGE_OPENED);
handleDestinationOrAction(annotationActions.getPV(), ActionTrigger.ANNOTATION_PAGE_VISIBLE);
handleDestinationOrAction(annotationActions.getU(), ActionTrigger.ANNOTATION_MOUSE_RELEASED);
handleDestinationOrAction(annotationActions.getX(), ActionTrigger.ANNOTATION_CURSOR_EXIT);
}
}
use of org.apache.pdfbox.pdmodel.interactive.action.PDAnnotationAdditionalActions in project pdfbox by apache.
the class FieldTriggers method main.
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"))) {
PDAcroForm acroForm = document.getDocumentCatalog().getAcroForm();
// Get the field and the widget associated to it.
// Note: there might be multiple widgets
PDField field = acroForm.getField("SampleField");
PDAnnotationWidget widget = field.getWidgets().get(0);
// Some of the actions are available to the widget, some are available to the form field.
// See Table 8.44 and Table 8.46 in the PDF 1.7 specification
// Actions for the widget
PDAnnotationAdditionalActions annotationActions = new PDAnnotationAdditionalActions();
// Create an action when entering the annotations active area
PDActionJavaScript jsEnterAction = new PDActionJavaScript();
jsEnterAction.setAction("app.alert(\"On 'enter' action\")");
annotationActions.setE(jsEnterAction);
// Create an action when exiting the annotations active area
PDActionJavaScript jsExitAction = new PDActionJavaScript();
jsExitAction.setAction("app.alert(\"On 'exit' action\")");
annotationActions.setX(jsExitAction);
// Create an action when the mouse button is pressed inside the annotations active area
PDActionJavaScript jsMouseDownAction = new PDActionJavaScript();
jsMouseDownAction.setAction("app.alert(\"On 'mouse down' action\")");
annotationActions.setD(jsMouseDownAction);
// Create an action when the mouse button is released inside the annotations active area
PDActionJavaScript jsMouseUpAction = new PDActionJavaScript();
jsMouseUpAction.setAction("app.alert(\"On 'mouse up' action\")");
annotationActions.setU(jsMouseUpAction);
// Create an action when the annotation gets the input focus
PDActionJavaScript jsFocusAction = new PDActionJavaScript();
jsFocusAction.setAction("app.alert(\"On 'focus' action\")");
annotationActions.setFo(jsFocusAction);
// Create an action when the annotation loses the input focus
PDActionJavaScript jsBlurredAction = new PDActionJavaScript();
jsBlurredAction.setAction("app.alert(\"On 'blurred' action\")");
annotationActions.setBl(jsBlurredAction);
widget.setActions(annotationActions);
// Actions for the field
PDFormFieldAdditionalActions fieldActions = new PDFormFieldAdditionalActions();
// Create an action when the user types a keystroke in the field
PDActionJavaScript jsKeystrokeAction = new PDActionJavaScript();
jsKeystrokeAction.setAction("app.alert(\"On 'keystroke' action\")");
fieldActions.setK(jsKeystrokeAction);
// Create an action when the field is formatted to display the current value
PDActionJavaScript jsFormattedAction = new PDActionJavaScript();
jsFormattedAction.setAction("app.alert(\"On 'formatted' action\")");
fieldActions.setF(jsFormattedAction);
// Create an action when the field value changes
PDActionJavaScript jsChangedAction = new PDActionJavaScript();
jsChangedAction.setAction("app.alert(\"On 'change' action\")");
// fieldActions.setV(jsChangedAction);
// Create an action when the field value changes
PDActionJavaScript jsRecalculateAction = new PDActionJavaScript();
jsRecalculateAction.setAction("app.alert(\"On 'recalculate' action\")");
fieldActions.setC(jsRecalculateAction);
// Set the Additional Actions entry for the field
// Note: this is a workaround as if there is only one widget the widget
// and the form field may share the same dictionary. Now setting the
// fields Additional Actions entry directly will overwrite the settings done for
// the widget.
// https://issues.apache.org/jira/browse/PDFBOX-3036
field.getActions().getCOSObject().addAll(fieldActions.getCOSObject());
document.save("target/FieldTriggers.pdf");
}
}
Aggregations