Example usage for org.apache.pdfbox.cos COSName getPDFName

List of usage examples for org.apache.pdfbox.cos COSName getPDFName

Introduction

In this page you can find the example usage for org.apache.pdfbox.cos COSName getPDFName.

Prototype

public static COSName getPDFName(String aName) 

Source Link

Document

This will get a COSName object with that name.

Usage

From source file:net.padaf.preflight.graphics.ShadingPattern.java

License:Apache License

/**
 * Because of a Shading Pattern can be used as an Indirect Object or Directly
 * define in an other dictionary, there are two ways to obtain the Shading
 * Pattern dictionary according to the pattern attribute. This method returns
 * the Shading pattern dictionary represented by the pattern attribute or
 * contained in it./*from  w w  w.  j  a v a 2 s  .  c  om*/
 * 
 * This is the first method called by the validate method.
 * 
 * @param errors
 *          the list of error to update if there are no Shading pattern in the
 *          pattern COSDictionary.
 * @return the ShadingPattern dictionary
 */
protected COSDictionary getShadingDictionary(List<ValidationError> errors) {
    if (!"Shading".equals(pattern.getNameAsString(COSName.getPDFName(DICTIONARY_KEY_TYPE)))) {
        COSBase shading = pattern.getItem(COSName.getPDFName(PATTERN_KEY_SHADING));
        if (shading == null) {
            errors.add(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION));
            return null;
        }
        return COSUtils.getAsDictionary(shading, cosDoc);
    } else {
        return pattern;
    }
}

From source file:net.padaf.preflight.graphics.ShadingPattern.java

License:Apache License

/**
 * Checks if the given shading pattern contains the ShadingType entry and if
 * the ColorSapce entry is consistent which rules of the PDF Reference and the
 * ISO 190005-1:2005 Specification./*  ww  w . j a v a2  s  . c o m*/
 * 
 * This method is called by the validate method.
 * 
 * @param shadingDict
 *          the Shading pattern dictionary to check
 * @param errors
 *          the list of error to update if the validation fails
 * @return true if the Shading pattern is valid, false otherwise.
 * @throws ValidationException
 */
protected boolean checkShadingDictionary(COSDictionary shadingDict, List<ValidationError> errors)
        throws ValidationException {
    if (shadingDict.getItem(COSName.getPDFName(PATTERN_KEY_SHADING_TYPE)) == null) {
        errors.add(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION));
        return false;
    }

    COSBase csImg = shadingDict.getItem(COSName.getPDFName(XOBJECT_DICTIONARY_KEY_COLOR_SPACE));
    ColorSpaceHelper csh = ColorSpaceHelperFactory.getColorSpaceHelper(csImg, documentHandler,
            ColorSpaceRestriction.NO_PATTERN);
    return csh.validate(errors);
}

From source file:net.padaf.preflight.graphics.TilingPattern.java

License:Apache License

/**
 * This method checks if required fields are present.
 * /*from w  w  w.j a  v  a  2  s  . c o m*/
 * @param result
 *          the list of error to update if the validation fails.
 * @return true if all fields are present, false otherwise.
 */
protected boolean checkMandatoryFields(List<ValidationError> errors) {
    boolean res = pattern.getItem(COSName.getPDFName(DICTIONARY_KEY_RESOURCES)) != null;
    res = res && pattern.getItem(COSName.getPDFName(PATTERN_KEY_BBOX)) != null;
    res = res && pattern.getItem(COSName.getPDFName(PATTERN_KEY_PAINT_TYPE)) != null;
    res = res && pattern.getItem(COSName.getPDFName(PATTERN_KEY_TILING_TYPE)) != null;
    res = res && pattern.getItem(COSName.getPDFName(PATTERN_KEY_XSTEP)) != null;
    res = res && pattern.getItem(COSName.getPDFName(PATTERN_KEY_YSTEP)) != null;
    if (!res) {
        errors.add(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION));
    }
    return res;
}

From source file:net.padaf.preflight.graphics.XObjFormValidator.java

License:Apache License

@Override
protected boolean checkMandatoryFields(List<ValidationError> result) {
    boolean lastMod = this.xobject.getItem(COSName.getPDFName("LastModified")) != null;
    boolean pieceInfo = this.xobject.getItem(COSName.getPDFName("PieceInfo")) != null;
    // type and subtype checked before to create the Validator.
    if (lastMod ^ pieceInfo) {
        result.add(new ValidationError(ERROR_GRAPHIC_MISSING_FIELD));
        return false;
    }/*w  w w  .  j ava 2s . c  om*/

    COSBase bbBase = this.xobject.getItem(COSName.getPDFName(XOBJECT_DICTIONARY_KEY_BBOX));
    // ---- BBox is an Array (Rectangle)
    if (bbBase == null || !COSUtils.isArray(bbBase, cosDocument)) {
        result.add(new ValidationError(ERROR_GRAPHIC_INVALID_BBOX));
        return false;
    }
    return true;
}

From source file:net.padaf.preflight.graphics.XObjFormValidator.java

License:Apache License

/**
 * A Form XObject may contain a Group object (Key =" Group"). If a Group
 * object is present, this method checks if the S entry is present and if its
 * value is different from "Transparency".
 * // w  ww . ja va 2  s  .co m
 * @param error
 *          the list of error to update if the validation fails.
 * @return true if the validation succeed, false otherwise
 * @throws ValidationException
 */
protected boolean checkGroup(List<ValidationError> error) throws ValidationException {
    COSBase baseGroup = this.xobject.getItem(COSName.getPDFName(XOBJECT_DICTIONARY_KEY_GROUP));

    COSDictionary groupDictionary = COSUtils.getAsDictionary(baseGroup, cosDocument);
    if (groupDictionary != null) {
        if (!XOBJECT_DICTIONARY_KEY_GROUP.equals(groupDictionary.getNameAsString(DICTIONARY_KEY_TYPE))) {
            throw new ValidationException("The Group dictionary hasn't Group as Type value");
        }

        String sVal = groupDictionary.getNameAsString(XOBJECT_DICTIONARY_KEY_GROUP_S);
        if (sVal == null || XOBJECT_DICTIONARY_VALUE_S_TRANSPARENCY.equals(sVal)) {
            error.add(new ValidationError(ERROR_GRAPHIC_TRANSPARENCY_GROUP,
                    "Group has a transparency S entry or the S entry is null."));
            return false;
        }
    }
    return true;
}

From source file:net.padaf.preflight.graphics.XObjFormValidator.java

License:Apache License

/**
 * Check if there are no PS entry in the Form XObject dictionary
 * /*  w  ww .j a  va 2 s .c  om*/
 * @param errors
 *          the list of error to update if the validation fails.
 * @return true if PS entry is missing, false otherwise
 */
protected boolean checkPS(List<ValidationError> errors) {
    // 6.2.4 and 6.2.5 no PS
    if (this.xobject.getItem(COSName.getPDFName("PS")) != null) {
        errors.add(
                new ValidationError(ValidationConstants.ERROR_GRAPHIC_UNEXPECTED_KEY, "Unexpected 'PS' Key"));
        return false;
    }
    return true;
}

From source file:net.padaf.preflight.graphics.XObjFormValidator.java

License:Apache License

/**
 * Check the SUbtype2 entry according to the 6.2.5 of the ISO 190005-1:2005
 * specification./*w ww.  j ava2s.  c o m*/
 * 
 * @param errors
 *          the list of error to update if the validation fails.
 * @return true if Subtype2 is missing or different from PS, false otherwise
 */
protected boolean checkSubtype2Value(List<ValidationError> errors) {
    // 6.2.5 if Subtype2, value not PS
    if (this.xobject.getItem(COSName.getPDFName("Subtype2")) != null) {
        if ("PS".equals(this.xobject.getNameAsString(COSName.getPDFName("Subtype2")))) {
            errors.add(new ValidationError(ValidationConstants.ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
                    "Unexpected 'PS' value for 'Subtype2' Key"));
            return false;
        }
    }
    return true;
}

From source file:net.padaf.preflight.graphics.XObjImageValidator.java

License:Apache License

@Override
protected boolean checkMandatoryFields(List<ValidationError> result) {
    boolean res = this.xobject.getItem(COSName.getPDFName("Width")) != null;
    res = res && this.xobject.getItem(COSName.getPDFName("Height")) != null;
    // type and subtype checked before to create the Validator.
    if (!res) {//from  w ww.  ja v  a 2 s  .  co m
        result.add(new ValidationError(ERROR_GRAPHIC_MISSING_FIELD));
    }
    return res;
}

From source file:net.padaf.preflight.graphics.XObjImageValidator.java

License:Apache License

protected void checkAlternates(List<ValidationError> result) throws ValidationException {
    if (this.xobject.getItem(COSName.getPDFName("Alternates")) != null) {
        result.add(new ValidationError(ValidationConstants.ERROR_GRAPHIC_UNEXPECTED_KEY,
                "Unexpected 'Alternates' Key"));
    }// w  w w.  jav a 2s.c  o  m
}

From source file:net.padaf.preflight.graphics.XObjImageValidator.java

License:Apache License

protected void checkInterpolate(List<ValidationError> result) throws ValidationException {
    if (this.xobject.getItem(COSName.getPDFName("Interpolate")) != null) {
        if (this.xobject.getBoolean(COSName.getPDFName("Interpolate"), true)) {
            result.add(new ValidationError(ValidationConstants.ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY,
                    "Unexpected 'true' value for 'Interpolate' Key"));
        }//from   ww w  .  j a va 2s.  c om
    }
}