use of org.apache.pdfbox.pdmodel.interactive.form.PDNonTerminalField in project pdfbox by apache.
the class AcroFormValidationProcess method validateField.
/**
* A and AA field are forbidden, this method checks if they are present and checks all children of this field. If the
* an Additional Action is present the error code ERROR_ACTION_FORBIDDEN_ADDITIONAL_ACTIONS_FIELD (6.2.3) is added
* to the error list If the an Action is present (in the Widget Annotation) the error
* ERROR_ACTION_FORBIDDEN_WIDGET_ACTION_FIELD (6.2.4) is added to the error list. (Remark : The widget validation
* will be done by the AnnotationValidationHelper, but some actions are authorized in a standard Widget)
*
* @param ctx the preflight context.
* @param field an acro forms field.
* @return the result of the check for A or AA entries.
* @throws IOException
*/
protected boolean validateField(PreflightContext ctx, PDField field) throws IOException {
boolean res = true;
PDFormFieldAdditionalActions aa = field.getActions();
if (aa != null) {
addValidationError(ctx, new ValidationError(ERROR_ACTION_FORBIDDEN_ADDITIONAL_ACTIONS_FIELD, "\"AA\" must not be used in a Field dictionary"));
res = false;
}
if (field instanceof PDTerminalField) {
// The widget validation will be done by the widget annotation, a widget contained in a Field can't have action.
List<PDAnnotationWidget> widgets = field.getWidgets();
if (res && widgets != null) {
for (PDAnnotationWidget widget : widgets) {
ContextHelper.validateElement(ctx, widget.getCOSObject(), ANNOTATIONS_PROCESS);
COSBase act = widget.getCOSObject().getDictionaryObject(COSName.A);
if (act != null) {
addValidationError(ctx, new ValidationError(ERROR_ACTION_FORBIDDEN_WIDGET_ACTION_FIELD, "\"A\" must not be used in a widget annotation"));
return false;
}
}
}
return exploreWidgets(ctx, field.getWidgets());
} else {
return res && exploreFields(ctx, ((PDNonTerminalField) field).getChildren());
}
}
use of org.apache.pdfbox.pdmodel.interactive.form.PDNonTerminalField in project tika by apache.
the class AbstractPDF2XHTML method processAcroField.
private void processAcroField(PDField field, final int currentRecursiveDepth) throws SAXException, IOException, TikaException {
if (currentRecursiveDepth >= MAX_ACROFORM_RECURSIONS) {
return;
}
PDFormFieldAdditionalActions pdFormFieldAdditionalActions = field.getActions();
if (pdFormFieldAdditionalActions != null) {
handleDestinationOrAction(pdFormFieldAdditionalActions.getC(), ActionTrigger.FORM_FIELD_RECALCULATE);
handleDestinationOrAction(pdFormFieldAdditionalActions.getF(), ActionTrigger.FORM_FIELD_FORMATTED);
handleDestinationOrAction(pdFormFieldAdditionalActions.getK(), ActionTrigger.FORM_FIELD_KEYSTROKE);
handleDestinationOrAction(pdFormFieldAdditionalActions.getV(), ActionTrigger.FORM_FIELD_VALUE_CHANGE);
}
if (field.getWidgets() != null) {
for (PDAnnotationWidget widget : field.getWidgets()) {
handleWidget(widget);
}
}
addFieldString(field);
if (field instanceof PDNonTerminalField) {
int r = currentRecursiveDepth + 1;
xhtml.startElement("ol");
for (PDField child : ((PDNonTerminalField) field).getChildren()) {
processAcroField(child, r);
}
xhtml.endElement("ol");
}
}
use of org.apache.pdfbox.pdmodel.interactive.form.PDNonTerminalField in project pdfbox by apache.
the class PrintFields method processField.
private void processField(PDField field, String sLevel, String sParent) throws IOException {
String partialName = field.getPartialName();
if (field instanceof PDNonTerminalField) {
if (!sParent.equals(field.getPartialName())) {
if (partialName != null) {
sParent = sParent + "." + partialName;
}
}
System.out.println(sLevel + sParent);
for (PDField child : ((PDNonTerminalField) field).getChildren()) {
processField(child, "| " + sLevel, sParent);
}
} else {
String fieldValue = field.getValueAsString();
StringBuilder outputString = new StringBuilder(sLevel);
outputString.append(sParent);
if (partialName != null) {
outputString.append(".").append(partialName);
}
outputString.append(" = ").append(fieldValue);
outputString.append(", type=").append(field.getClass().getName());
System.out.println(outputString);
}
}
Aggregations