Search in sources :

Example 6 with PreflightConfiguration

use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.

the class PreflightStreamEngine method checkSetColorSpaceOperators.

/**
 * This method validates if the ColorSpace used as operand is consistent with
 * the color space defined in OutputIntent dictionaries.
 *
 * @param operator
 * @param arguments
 * @throws IOException
 */
protected void checkSetColorSpaceOperators(Operator operator, List<COSBase> arguments) throws IOException {
    if (!("CS".equals(operator.getName()) || "cs".equals(operator.getName()))) {
        return;
    }
    String colorSpaceName;
    if (arguments.get(0) instanceof COSString) {
        colorSpaceName = (arguments.get(0)).toString();
    } else if (arguments.get(0) instanceof COSName) {
        colorSpaceName = ((COSName) arguments.get(0)).getName();
    } else {
        registerError("The operand " + arguments.get(0) + " for colorSpace operator " + operator.getName() + " doesn't have the expected type", ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY);
        return;
    }
    ColorSpaceHelper csHelper = null;
    ColorSpaces cs = null;
    try {
        cs = ColorSpaces.valueOf(colorSpaceName);
    } catch (IllegalArgumentException e) {
        /*
             * The color space is unknown. Try to access the resources dictionary, the color space can be a reference.
             */
        PDColorSpace pdCS = this.getResources().getColorSpace(COSName.getPDFName(colorSpaceName));
        if (pdCS != null) {
            cs = ColorSpaces.valueOf(pdCS.getName());
            PreflightConfiguration cfg = context.getConfig();
            ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
            csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_RESTRICTION);
        }
    }
    if (cs == null) {
        registerError("The ColorSpace " + colorSpaceName + " is unknown", ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY);
        return;
    }
    if (csHelper == null) {
        PDColorSpace pdCS = PDColorSpace.create(COSName.getPDFName(colorSpaceName));
        PreflightConfiguration cfg = context.getConfig();
        ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
        csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.NO_RESTRICTION);
    }
    csHelper.validate();
}
Also used : PreflightConfiguration(org.apache.pdfbox.preflight.PreflightConfiguration) COSName(org.apache.pdfbox.cos.COSName) ColorSpaces(org.apache.pdfbox.preflight.graphic.ColorSpaces) ColorSpaceHelperFactory(org.apache.pdfbox.preflight.graphic.ColorSpaceHelperFactory) COSString(org.apache.pdfbox.cos.COSString) ColorSpaceHelper(org.apache.pdfbox.preflight.graphic.ColorSpaceHelper) COSString(org.apache.pdfbox.cos.COSString) PDColorSpace(org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace)

Example 7 with PreflightConfiguration

use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.

the class PreflightStreamEngine method getColorSpaceHelper.

private ColorSpaceHelper getColorSpaceHelper(PDColorSpace pdCS) {
    PreflightConfiguration cfg = context.getConfig();
    ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
    return csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.ONLY_DEVICE);
}
Also used : PreflightConfiguration(org.apache.pdfbox.preflight.PreflightConfiguration) ColorSpaceHelperFactory(org.apache.pdfbox.preflight.graphic.ColorSpaceHelperFactory)

Example 8 with PreflightConfiguration

use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.

the class TestPreflightConfiguration method testGetValidationProcess_MissingProcess.

@Test(expected = MissingValidationProcessException.class)
public void testGetValidationProcess_MissingProcess() throws Exception {
    PreflightConfiguration configuration = PreflightConfiguration.createPdfA1BConfiguration();
    configuration.getInstanceOfProcess("unknownProcess");
}
Also used : PreflightConfiguration(org.apache.pdfbox.preflight.PreflightConfiguration) Test(org.junit.Test)

Example 9 with PreflightConfiguration

use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.

the class TestPreflightConfiguration method testReplaceValidationProcess.

@Test
public void testReplaceValidationProcess() throws Exception {
    PreflightConfiguration configuration = PreflightConfiguration.createPdfA1BConfiguration();
    String processName = "mock-process";
    configuration.replaceProcess(processName, MockProcess.class);
    assertEquals(MockProcess.class, configuration.getInstanceOfProcess(processName).getClass());
    configuration.replaceProcess(processName, MockProcess2.class);
    assertEquals(MockProcess2.class, configuration.getInstanceOfProcess(processName).getClass());
}
Also used : PreflightConfiguration(org.apache.pdfbox.preflight.PreflightConfiguration) Test(org.junit.Test)

Example 10 with PreflightConfiguration

use of org.apache.pdfbox.preflight.PreflightConfiguration in project pdfbox by apache.

the class ContextHelper method callValidation.

/**
 * Put the element to check on the top of the ValidationPath and call the validation method on the Process.
 *
 * @param context
 *            (mandatory) the preflight context that contains all required information
 * @param element
 * @param processName
 *            the process to instantiate and to compute
 * @throws ValidationException
 */
private static void callValidation(PreflightContext context, Object element, String processName) throws ValidationException {
    PreflightPath validationPath = context.getValidationPath();
    if (hasRecursion(context, element, validationPath)) {
        return;
    }
    boolean needPop = validationPath.pushObject(element);
    PreflightConfiguration config = context.getConfig();
    ValidationProcess process = config.getInstanceOfProcess(processName);
    process.validate(context);
    if (needPop) {
        validationPath.pop();
    }
}
Also used : PreflightConfiguration(org.apache.pdfbox.preflight.PreflightConfiguration) ValidationProcess(org.apache.pdfbox.preflight.process.ValidationProcess) PreflightPath(org.apache.pdfbox.preflight.PreflightPath)

Aggregations

PreflightConfiguration (org.apache.pdfbox.preflight.PreflightConfiguration)11 ColorSpaceHelperFactory (org.apache.pdfbox.preflight.graphic.ColorSpaceHelperFactory)5 PDColorSpace (org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace)4 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)4 ColorSpaceHelper (org.apache.pdfbox.preflight.graphic.ColorSpaceHelper)4 IOException (java.io.IOException)3 Test (org.junit.Test)3 COSBase (org.apache.pdfbox.cos.COSBase)2 COSName (org.apache.pdfbox.cos.COSName)2 HashMap (java.util.HashMap)1 COSArray (org.apache.pdfbox.cos.COSArray)1 COSDictionary (org.apache.pdfbox.cos.COSDictionary)1 COSDocument (org.apache.pdfbox.cos.COSDocument)1 COSObjectKey (org.apache.pdfbox.cos.COSObjectKey)1 COSString (org.apache.pdfbox.cos.COSString)1 PDResources (org.apache.pdfbox.pdmodel.PDResources)1 PreflightPath (org.apache.pdfbox.preflight.PreflightPath)1 ColorSpaces (org.apache.pdfbox.preflight.graphic.ColorSpaces)1 ValidationProcess (org.apache.pdfbox.preflight.process.ValidationProcess)1