use of org.apache.pdfbox.preflight.ValidationResult.ValidationError 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.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class BookmarkValidationProcess method validate.
@Override
public void validate(PreflightContext ctx) throws ValidationException {
PDDocumentCatalog catalog = ctx.getDocument().getDocumentCatalog();
if (catalog != null) {
PDDocumentOutline outlineHierarchy = catalog.getDocumentOutline();
if (outlineHierarchy != null) {
COSDictionary dict = outlineHierarchy.getCOSObject();
if (!checkIndirectObjects(ctx, dict)) {
return;
}
COSObject firstObj = toCOSObject(dict.getItem(COSName.FIRST));
COSObject lastObj = toCOSObject(dict.getItem(COSName.LAST));
// Count entry is mandatory if there are childrens
if (!isCountEntryPresent(dict) && (outlineHierarchy.getFirstChild() != null || outlineHierarchy.getLastChild() != null)) {
addValidationError(ctx, new ValidationError(ERROR_SYNTAX_TRAILER_OUTLINES_INVALID, "Outline Hierarchy doesn't have Count entry"));
} else if (isCountEntryPositive(ctx, dict) && (outlineHierarchy.getFirstChild() == null || outlineHierarchy.getLastChild() == null)) {
addValidationError(ctx, new ValidationError(ERROR_SYNTAX_TRAILER_OUTLINES_INVALID, "Outline Hierarchy doesn't have First and/or Last entry(ies)"));
} else {
exploreOutlineLevel(ctx, outlineHierarchy.getFirstChild(), firstObj, lastObj);
}
}
} else {
ctx.addValidationError(new ValidationError(ERROR_SYNTAX_NOCATALOG, "There is no /Catalog entry in the Document"));
}
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class BookmarkValidationProcess method checkIndirectObject.
// verify that if the named item exists, that it is is an indirect object
private boolean checkIndirectObject(PreflightContext ctx, COSDictionary dictionary, COSName name) {
COSBase item = dictionary.getItem(name);
if (item == null || item instanceof COSNull || item instanceof COSObject) {
return true;
}
addValidationError(ctx, new ValidationError(ERROR_SYNTAX_TRAILER_OUTLINES_INVALID, "/" + name.getName() + " entry must be an indirect object"));
return false;
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class CatalogValidationProcess method validateICCProfileNEntry.
private boolean validateICCProfileNEntry(COSStream stream, PreflightContext ctx, ICC_Profile iccp) {
COSDictionary streamDict = (COSDictionary) stream.getCOSObject();
if (!streamDict.containsKey(COSName.N)) {
addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, "/N entry of ICC profile is mandatory"));
return false;
}
COSBase nValue = streamDict.getItem(COSName.N);
if (!(nValue instanceof COSNumber)) {
addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, "/N entry of ICC profile must be a number, but is " + nValue));
return false;
}
int nNumberValue = ((COSNumber) nValue).intValue();
if (nNumberValue != 1 && nNumberValue != 3 && nNumberValue != 4) {
addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, "/N entry of ICC profile must be 1, 3 or 4, but is " + nNumberValue));
return false;
}
if (iccp.getNumComponents() != nNumberValue) {
addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, "/N entry of ICC profile is " + nNumberValue + " but the ICC profile has " + iccp.getNumComponents() + " components"));
return false;
}
return true;
}
use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.
the class CatalogValidationProcess method validateICCProfileVersion.
private boolean validateICCProfileVersion(ICC_Profile iccp, PreflightContext ctx) {
PreflightConfiguration config = ctx.getConfig();
// check the ICC Profile version (6.2.2)
if (iccp.getMajorVersion() == 2) {
if (iccp.getMinorVersion() > 0x40) {
// in PDF 1.4, max version is 02h.40h (meaning V 3.5)
// see the ICCProfile specification (ICC.1:1998-09)page 13 - §6.1.3 :
// The current profile version number is "2.4.0" (encoded as 02400000h")
ValidationError error = new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_TOO_RECENT, "Invalid version of the ICCProfile");
error.setWarning(config.isLazyValidation());
addValidationError(ctx, error);
return false;
}
// else OK
} else if (iccp.getMajorVersion() > 2) {
// in PDF 1.4, max version is 02h.40h (meaning V 3.5)
// see the ICCProfile specification (ICC.1:1998-09)page 13 - §6.1.3 :
// The current profile version number is "2.4.0" (encoded as 02400000h"
ValidationError error = new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_ICC_PROFILE_TOO_RECENT, "Invalid version of the ICCProfile");
error.setWarning(config.isLazyValidation());
addValidationError(ctx, error);
return false;
}
// else seems less than 2, so correct
return true;
}
Aggregations