use of org.apache.pdfbox.preflight.PreflightConfiguration 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;
}
use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.
the class ShadingPatternValidationProcess method checkColorSpace.
/**
* Checks if the ColorSapce entry is consistent which rules of the PDF Reference and the ISO 190005-1:2005
* Specification.
*
* This method is called by the validate method.
*
* @param context the preflight context.
* @param page the page to check.
* @param shadingRes the Shading pattern to check.
* @throws ValidationException
*/
protected void checkColorSpace(PreflightContext context, PDPage page, PDShading shadingRes) throws ValidationException {
try {
PDColorSpace pColorSpace = shadingRes.getColorSpace();
PreflightConfiguration config = context.getConfig();
ColorSpaceHelperFactory csFact = config.getColorSpaceHelperFact();
ColorSpaceHelper csh = csFact.getColorSpaceHelper(context, pColorSpace, ColorSpaceRestriction.NO_PATTERN);
csh.validate();
} catch (IOException e) {
LOGGER.debug("Unable to get the color space", e);
context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_UNKNOWN_COLOR_SPACE, e.getMessage()));
}
}
use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.
the class SinglePageValidationProcess method validateColorSpaces.
/**
* Check that all ColorSpace present in the Resource dictionary are conforming to the ISO 19005:2005-1
* specification.
*
* @param context the preflight context.
* @param page the page to check.
*/
protected void validateColorSpaces(PreflightContext context, PDPage page) {
PDResources resources = page.getResources();
if (resources != null) {
PreflightConfiguration config = context.getConfig();
ColorSpaceHelperFactory colorSpaceFactory = config.getColorSpaceHelperFact();
for (COSName name : resources.getColorSpaceNames()) {
try {
PDColorSpace pdCS = resources.getColorSpace(name);
ColorSpaceHelper csHelper = colorSpaceFactory.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_RESTRICTION);
csHelper.validate();
} catch (IOException e) {
// fixme: this code was previously in PDResources
LOGGER.debug("Unable to create colorspace", e);
}
}
}
}
use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.
the class TestPreflightConfiguration method testGetValidationProcess_MissingProcess_NoError.
@Test
public void testGetValidationProcess_MissingProcess_NoError() throws Exception {
PreflightConfiguration configuration = PreflightConfiguration.createPdfA1BConfiguration();
configuration.setErrorOnMissingProcess(false);
configuration.getInstanceOfProcess("unknownProcess");
}
use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.
the class CatalogValidationProcess method validateOutputIntent.
/**
* This method checks the content of each OutputIntent. The S entry must contain GTS_PDFA1. The DestOuputProfile
* must contain a valid ICC Profile Stream.
*
* If there are more than one OutputIntent, they have to use the same ICC Profile.
*
* This method returns a list of ValidationError. It is empty if no errors have been found.
*
* @param ctx
* @throws ValidationException
*/
public void validateOutputIntent(PreflightContext ctx) throws ValidationException {
COSDocument cosDocument = ctx.getDocument().getDocument();
COSBase cBase = catalog.getCOSObject().getItem(COSName.getPDFName(DOCUMENT_DICTIONARY_KEY_OUTPUT_INTENTS));
COSArray outputIntents = COSUtils.getAsArray(cBase, cosDocument);
Map<COSObjectKey, Boolean> tmpDestOutputProfile = new HashMap<>();
for (int i = 0; outputIntents != null && i < outputIntents.size(); ++i) {
COSDictionary outputIntentDict = COSUtils.getAsDictionary(outputIntents.get(i), cosDocument);
if (outputIntentDict == null) {
addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, "OutputIntent object is null or isn't a dictionary"));
} else {
// S entry is mandatory and must be equals to GTS_PDFA1
String sValue = outputIntentDict.getNameAsString(OUTPUT_INTENT_DICTIONARY_KEY_S);
if (!OUTPUT_INTENT_DICTIONARY_VALUE_GTS_PDFA1.equals(sValue)) {
addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_S_VALUE_INVALID, "The S entry of the OutputIntent isn't GTS_PDFA1"));
continue;
}
// OutputConditionIdentifier is a mandatory field
String outputConditionIdentifier = outputIntentDict.getString(OUTPUT_INTENT_DICTIONARY_KEY_OUTPUT_CONDITION_IDENTIFIER);
if (outputConditionIdentifier == null) {
// empty string is authorized (it may be an application specific value)
addValidationError(ctx, new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, "The OutputIntentCondition is missing"));
continue;
}
/*
* If OutputConditionIdentifier is "Custom" or a non Standard ICC Characterization : DestOutputProfile
* and Info are mandatory DestOutputProfile must be a ICC Profile
*
* Because of PDF/A conforming file needs to specify the color characteristics, the DestOutputProfile is
* checked even if the OutputConditionIdentifier isn't "Custom"
*/
COSBase destOutputProfile = outputIntentDict.getItem(OUTPUT_INTENT_DICTIONARY_KEY_DEST_OUTPUT_PROFILE);
validateICCProfile(destOutputProfile, tmpDestOutputProfile, ctx);
PreflightConfiguration config = ctx.getConfig();
if (config.isLazyValidation() && !isStandardICCCharacterization(outputConditionIdentifier)) {
String info = outputIntentDict.getString(COSName.getPDFName(OUTPUT_INTENT_DICTIONARY_KEY_INFO));
if (info == null || "".equals(info)) {
ValidationError error = new ValidationError(ERROR_GRAPHIC_OUTPUT_INTENT_INVALID_ENTRY, "The Info entry of a OutputIntent dictionary is missing");
error.setWarning(true);
addValidationError(ctx, error);
continue;
}
}
}
}
}
Aggregations