Search in sources :

Example 31 with ValidationError

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

the class DescendantFontValidator method checkMandatoryField.

@Override
protected void checkMandatoryField() {
    boolean arePresent = fontDictionary.containsKey(COSName.TYPE);
    arePresent &= fontDictionary.containsKey(COSName.SUBTYPE);
    arePresent &= fontDictionary.containsKey(COSName.BASE_FONT);
    arePresent &= fontDictionary.containsKey(COSName.CIDSYSTEMINFO);
    arePresent &= fontDictionary.containsKey(COSName.FONT_DESC);
    if (!arePresent) {
        this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, font.getName() + ": Required keys are missing"));
    }
    checkCIDSystemInfo(fontDictionary.getItem(COSName.CIDSYSTEMINFO));
    checkCIDToGIDMap(fontDictionary.getItem(COSName.CID_TO_GID_MAP));
}
Also used : ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

Example 32 with ValidationError

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

the class Type0FontValidator method compareCIDSystemInfo.

/**
 * The CIDSystemInfo must have the same Registry and Ordering for CMap and CIDFont. This control is useless if CMap
 * is Identity-H or Identity-V so this method is called by the checkCMap method.
 *
 * @param cmap
 */
private void compareCIDSystemInfo(COSDictionary cmap) {
    COSDictionary fontDictionary = font.getCOSObject();
    COSArray array = COSUtils.getAsArray(fontDictionary.getItem(COSName.DESCENDANT_FONTS), cosDocument);
    if (array != null && array.size() > 0) {
        COSDictionary cidFont = COSUtils.getAsDictionary(array.get(0), cosDocument);
        COSDictionary cmsi = COSUtils.getAsDictionary(cmap.getItem(COSName.CIDSYSTEMINFO), cosDocument);
        COSDictionary cfsi = COSUtils.getAsDictionary(cidFont.getItem(COSName.CIDSYSTEMINFO), cosDocument);
        String regCM = COSUtils.getAsString(cmsi.getItem(COSName.REGISTRY), cosDocument);
        String ordCM = COSUtils.getAsString(cmsi.getItem(COSName.ORDERING), cosDocument);
        String regCF = COSUtils.getAsString(cfsi.getItem(COSName.REGISTRY), cosDocument);
        String ordCF = COSUtils.getAsString(cfsi.getItem(COSName.ORDERING), cosDocument);
        if (!regCF.equals(regCM) || !ordCF.equals(ordCM)) {
            this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_SYSINFO, font.getName() + ": The CIDSystemInfo is inconsistent"));
        }
    }
}
Also used : COSDictionary(org.apache.pdfbox.cos.COSDictionary) COSArray(org.apache.pdfbox.cos.COSArray) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

Example 33 with ValidationError

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

the class Type0FontValidator method processDescendantFont.

/**
 * Extract the single CIDFont from the descendant array. Create a FontValidator for this CIDFont
 * and launch its validation.
 *
 * @throws org.apache.pdfbox.preflight.exception.ValidationException if there is an error
 * validating the CIDFont.
 */
protected void processDescendantFont() throws ValidationException {
    COSDictionary fontDictionary = font.getCOSObject();
    // a CIDFont is contained in the DescendantFonts array
    COSArray array = COSUtils.getAsArray(fontDictionary.getItem(COSName.DESCENDANT_FONTS), cosDocument);
    if (array == null || array.size() != 1) {
        /*
             * in PDF 1.4, this array must contain only one element, because of a PDF/A should be a PDF 1.4, this method
             * returns an error if the array has more than one element.
             */
        this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_INVALID, font.getName() + ": CIDFont is missing from the DescendantFonts array or the size of array is greater than 1"));
        return;
    }
    COSDictionary cidFont = COSUtils.getAsDictionary(array.get(0), cosDocument);
    if (cidFont == null) {
        this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_INVALID, font.getName() + ": The DescendantFonts array should have one element with is a dictionary."));
        return;
    }
    FontValidator<? extends FontContainer<? extends PDCIDFont>> cidFontValidator = createDescendantValidator(cidFont);
    if (cidFontValidator != null) {
        this.fontContainer.setDelegateFontContainer(cidFontValidator.getFontContainer());
        cidFontValidator.validate();
    }
}
Also used : COSDictionary(org.apache.pdfbox.cos.COSDictionary) COSArray(org.apache.pdfbox.cos.COSArray) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

Example 34 with ValidationError

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

the class Type0FontValidator method checkCIDSystemInfo.

/**
 * Check the content of the CIDSystemInfo dictionary. A CIDSystemInfo dictionary must contain :
 * <UL>
 * <li>a Name - Registry
 * <li>a Name - Ordering
 * <li>a Integer - Supplement
 * </UL>
 *
 * @param sysinfo
 * @return the validation result.
 */
protected boolean checkCIDSystemInfo(COSBase sysinfo) {
    boolean result = true;
    COSDictionary cidSysInfo = COSUtils.getAsDictionary(sysinfo, cosDocument);
    if (cidSysInfo != null) {
        COSBase reg = cidSysInfo.getItem(COSName.REGISTRY);
        COSBase ord = cidSysInfo.getItem(COSName.ORDERING);
        COSBase sup = cidSysInfo.getItem(COSName.SUPPLEMENT);
        if (!(COSUtils.isString(reg, cosDocument) && COSUtils.isString(ord, cosDocument) && COSUtils.isInteger(sup, cosDocument))) {
            this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_SYSINFO));
            result = false;
        }
    } else {
        this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_SYSINFO));
        result = false;
    }
    return result;
}
Also used : COSDictionary(org.apache.pdfbox.cos.COSDictionary) COSBase(org.apache.pdfbox.cos.COSBase) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

Example 35 with ValidationError

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

the class Type3FontValidator method checkFontBBox.

/**
 * Check that the FontBBox element has the right format as declared in the
 * PDF reference document.
 */
private void checkFontBBox() {
    COSBase fontBBox = fontDictionary.getItem(COSName.FONT_BBOX);
    if (!COSUtils.isArray(fontBBox, cosDocument)) {
        this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, font.getName() + ": The FontBBox element isn't an array"));
        return;
    }
    /*
         * check the content of the FontBBox. Should be an array with 4 numbers
         */
    COSArray bbox = COSUtils.getAsArray(fontBBox, cosDocument);
    if (bbox.size() != 4) {
        this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, font.getName() + ": The FontBBox element is invalid"));
        return;
    }
    for (int i = 0; i < 4; i++) {
        COSBase elt = bbox.get(i);
        if (!(COSUtils.isFloat(elt, cosDocument) || COSUtils.isInteger(elt, cosDocument))) {
            this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, font.getName() + ": An element of FontBBox isn't a number"));
            return;
        }
    }
}
Also used : COSArray(org.apache.pdfbox.cos.COSArray) COSBase(org.apache.pdfbox.cos.COSBase) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

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