Search in sources :

Example 76 with ValidationError

use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.

the class FontMetaDataValidation method analyseRights.

/**
 * If XMP MetaData are present, they must have followings information :
 * <UL>
 * <li>dc:rights
 * <li>Marked (with the value true)
 * <li>Owner
 * <li>UsageTerms
 * </UL>
 *
 * @param metadata
 *            XMPMetaData of the Font File Stream
 * @param fontDesc
 *            The FontDescriptor dictionary
 * @param ve
 *            the list of validation error to update if the validation fails
 * @return true if the analysis found no problems, false if it did.
 */
public boolean analyseRights(XMPMetadata metadata, PDFontDescriptor fontDesc, List<ValidationError> ve) {
    DublinCoreSchema dc = metadata.getDublinCoreSchema();
    if (dc != null) {
        ArrayProperty copyrights = dc.getRightsProperty();
        if (copyrights == null || copyrights.getContainer() == null || copyrights.getContainer().getAllProperties().isEmpty()) {
            ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_PROPERTY_MISSING, "CopyRights is missing from the XMP information (dc:rights) of the Font File Stream."));
            return false;
        }
    }
    XMPRightsManagementSchema rights = metadata.getXMPRightsManagementSchema();
    if (rights != null) {
        BooleanType marked = rights.getMarkedProperty();
        if (marked != null && !marked.getValue()) {
            ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_PROPERTY_MISSING, "the XMP information (xmpRights:Marked) is invalid for the Font File Stream."));
            return false;
        }
    /*
             * rights.getUsageTerms() & rights.getOwnerValue() should be present but it is only a recommendation : may
             * be it should be useful to append a Warning if these entries are missing.
             */
    }
    return true;
}
Also used : ArrayProperty(org.apache.xmpbox.type.ArrayProperty) BooleanType(org.apache.xmpbox.type.BooleanType) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) DublinCoreSchema(org.apache.xmpbox.schema.DublinCoreSchema) XMPRightsManagementSchema(org.apache.xmpbox.schema.XMPRightsManagementSchema)

Example 77 with ValidationError

use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.

the class StandardColorSpaceHelper method processIndexedColorSpace.

/**
 * Method called by the processAllColorSpace if the ColorSpace to check is Indexed. Because this kind of ColorSpace
 * can have a Base color space, the processAllColorSpace is called to check this base color space. (Indexed and
 * Pattern can't be a Base color space)
 *
 * @param colorSpace
 *            the color space object to check.
 */
protected void processIndexedColorSpace(PDColorSpace colorSpace) {
    PDIndexed indexed = (PDIndexed) colorSpace;
    PDColorSpace based = indexed.getBaseColorSpace();
    ColorSpaces cs = ColorSpaces.valueOf(based.getName());
    if (cs == ColorSpaces.Indexed || cs == ColorSpaces.I) {
        context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_INDEXED, "Indexed color space can't be used as Base color space"));
        return;
    }
    if (cs == ColorSpaces.Pattern) {
        context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_INDEXED, "Pattern color space can't be used as Base color space"));
        return;
    }
    processAllColorSpace(based);
}
Also used : PDIndexed(org.apache.pdfbox.pdmodel.graphics.color.PDIndexed) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) PDColorSpace(org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace)

Example 78 with ValidationError

use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.

the class StandardColorSpaceHelper method processICCBasedColorSpace.

/**
 * Method called by the processAllColorSpace if the ColorSpace to check is a ICCBased color space. Because this kind
 * of ColorSpace can have alternate color space, the processAllColorSpace is called to check this alternate color
 * space. (Pattern is forbidden as Alternate Color Space)
 *
 * @param colorSpace
 *            the color space object to check.
 */
protected void processICCBasedColorSpace(PDColorSpace colorSpace) {
    PDICCBased iccBased = (PDICCBased) colorSpace;
    try {
        ICC_Profile.getInstance(iccBased.getPDStream().createInputStream());
        PDColorSpace altpdcs = iccBased.getAlternateColorSpace();
        if (altpdcs != null) {
            ColorSpaces altCsId = ColorSpaces.valueOf(altpdcs.getName());
            if (altCsId == ColorSpaces.Pattern) {
                context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_COLOR_SPACE_FORBIDDEN, "Pattern is forbidden as AlternateColorSpace of a ICCBased"));
            }
        /*
                 * According to the ISO-19005-1:2005
                 * 
                 * A conforming reader shall render ICCBased colour spaces as specified by the ICC specification,
                 * and shall not use the Alternate colour space specified in an ICC profile stream dictionary
                 * 
                 * We don't check the alternate ColorSpaces
                 */
        }
    } catch (IllegalArgumentException e) {
        // this is not a ICC_Profile
        context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_ICCBASED, "ICCBased color space is invalid: " + e.getMessage(), e));
    } catch (IOException e) {
        context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE, "Unable to read ICCBase color space: " + e.getMessage(), e));
    }
}
Also used : PDICCBased(org.apache.pdfbox.pdmodel.graphics.color.PDICCBased) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) IOException(java.io.IOException) PDColorSpace(org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace)

Example 79 with ValidationError

use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.

the class StandardColorSpaceHelper method processSeparationColorSpace.

/**
 * Method called by the processAllColorSpace if the ColorSpace to check is Separation. Because this kind of
 * ColorSpace can have an alternate color space, the processAllColorSpace is called to check this alternate color
 * space. (Indexed, Separation, DeviceN and Pattern can't be a Base color space)
 *
 * @param colorSpace
 *            the color space object to check.
 */
protected void processSeparationColorSpace(PDColorSpace colorSpace) {
    try {
        COSBase cosAlt = ((COSArray) colorSpace.getCOSObject()).getObject(2);
        PDColorSpace altCol = PDColorSpace.create(cosAlt);
        if (altCol != null) {
            ColorSpaces acs = ColorSpaces.valueOf(altCol.getName());
            switch(acs) {
                case Separation:
                case DeviceN:
                case Pattern:
                case Indexed:
                case I:
                    context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_ALTERNATE, acs.getLabel() + " color space can't be used as alternate color space"));
                    break;
                default:
                    processAllColorSpace(altCol);
            }
        }
    } catch (IOException e) {
        context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE, "Unable to read Separation color space : " + e.getMessage(), e));
    }
}
Also used : COSArray(org.apache.pdfbox.cos.COSArray) COSBase(org.apache.pdfbox.cos.COSBase) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) IOException(java.io.IOException) PDColorSpace(org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace)

Example 80 with ValidationError

use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.

the class StandardColorSpaceHelper method processDeviceNColorSpace.

/**
 * Method called by the processAllColorSpace if the ColorSpace to check is DeviceN. Because this kind of ColorSpace
 * can have alternate color space, the processAllColorSpace is called to check this alternate color space. (There
 * are no restrictions on the Alternate Color space)
 *
 * @param colorSpace
 *            the color space object to check.
 */
protected void processDeviceNColorSpace(PDColorSpace colorSpace) {
    PDDeviceN deviceN = (PDDeviceN) colorSpace;
    try {
        if (iccpw == null) {
            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_MISSING, "DestOutputProfile is missing"));
            return;
        }
        COSBase cosAlt = ((COSArray) colorSpace.getCOSObject()).getObject(2);
        PDColorSpace altColor = PDColorSpace.create(cosAlt);
        if (altColor != null) {
            processAllColorSpace(altColor);
        }
        int numberOfColorants = 0;
        PDDeviceNAttributes attr = deviceN.getAttributes();
        if (attr != null) {
            final Map<String, PDSeparation> colorants = attr.getColorants();
            if (colorants != null) {
                numberOfColorants = colorants.size();
                for (PDSeparation col : colorants.values()) {
                    if (col != null) {
                        processAllColorSpace(col);
                    }
                }
            }
        }
        int numberOfComponents = deviceN.getNumberOfComponents();
        if (numberOfColorants > MAX_DEVICE_N_LIMIT || numberOfComponents > MAX_DEVICE_N_LIMIT) {
            context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE_TOO_MANY_COMPONENTS_DEVICEN, "DeviceN has too many tint components or colorants"));
        }
    } catch (IOException e) {
        context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID_COLOR_SPACE, "Unable to read DeviceN color space : " + e.getMessage(), e));
    }
}
Also used : PDSeparation(org.apache.pdfbox.pdmodel.graphics.color.PDSeparation) COSArray(org.apache.pdfbox.cos.COSArray) PDDeviceN(org.apache.pdfbox.pdmodel.graphics.color.PDDeviceN) COSBase(org.apache.pdfbox.cos.COSBase) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) IOException(java.io.IOException) PDColorSpace(org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace) PDDeviceNAttributes(org.apache.pdfbox.pdmodel.graphics.color.PDDeviceNAttributes)

Aggregations

ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)108 COSBase (org.apache.pdfbox.cos.COSBase)36 COSDictionary (org.apache.pdfbox.cos.COSDictionary)28 IOException (java.io.IOException)27 COSDocument (org.apache.pdfbox.cos.COSDocument)13 COSObject (org.apache.pdfbox.cos.COSObject)13 COSArray (org.apache.pdfbox.cos.COSArray)10 COSStream (org.apache.pdfbox.cos.COSStream)10 COSString (org.apache.pdfbox.cos.COSString)8 PDColorSpace (org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace)8 ValidationException (org.apache.pdfbox.preflight.exception.ValidationException)8 COSName (org.apache.pdfbox.cos.COSName)7 COSObjectKey (org.apache.pdfbox.cos.COSObjectKey)7 PreflightPath (org.apache.pdfbox.preflight.PreflightPath)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 PDStream (org.apache.pdfbox.pdmodel.common.PDStream)5 PreflightParser (org.apache.pdfbox.preflight.parser.PreflightParser)5 DublinCoreSchema (org.apache.xmpbox.schema.DublinCoreSchema)5 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)4