Search in sources :

Example 71 with ValidationError

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

the class CIDType0DescriptorHelper method extractFontFile.

@Override
public PDStream extractFontFile(PDFontDescriptor fontDescriptor) {
    PDStream ff3 = fontDescriptor.getFontFile3();
    if (ff3 != null) {
        // Stream validation should be done by the StreamValidateHelper. Process font specific check
        COSStream stream = ff3.getCOSObject();
        if (stream == null) {
            this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile is missing"));
            this.fContainer.notEmbedded();
        } else {
            // Length1/2/3 aren't mandatory for this type of font
            // But the Subtype is a mandatory field with specific values
            String st = stream.getNameAsString(COSName.SUBTYPE);
            if (!(FONT_DICTIONARY_VALUE_TYPE0C.equals(st) || FONT_DICTIONARY_VALUE_TYPE1C.equals(st))) {
                this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": invalid /Subtype /" + st + " in /FontFile3 stream"));
            }
            checkCIDSet(fontDescriptor);
        }
    }
    return ff3;
}
Also used : COSStream(org.apache.pdfbox.cos.COSStream) PDStream(org.apache.pdfbox.pdmodel.common.PDStream) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

Example 72 with ValidationError

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

the class FontDescriptorHelper method validate.

public void validate() {
    PDFontDescriptor fd = this.font.getFontDescriptor();
    boolean isStandard14 = false;
    if (this.font instanceof PDFont) {
        isStandard14 = ((PDFont) font).isStandard14();
    }
    // Only a PDFontDescriptorDictionary provides a way to embedded the font program.
    if (fd != null) {
        fontDescriptor = fd;
        if (!isStandard14) {
            checkMandatoryFields(fontDescriptor.getCOSObject());
        }
        if (hasOnlyOneFontFile(fontDescriptor)) {
            PDStream fontFile = extractFontFile(fontDescriptor);
            if (fontFile != null) {
                processFontFile(fontDescriptor, fontFile);
                checkFontFileMetaData(fontDescriptor, fontFile);
            }
        } else {
            if (fontFileNotEmbedded(fontDescriptor)) {
                this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": FontFile entry is missing from FontDescriptor"));
                this.fContainer.notEmbedded();
            } else {
                this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": They is more than one FontFile"));
            }
        }
    } else {
        this.fContainer.push(new ValidationError(ERROR_FONTS_DESCRIPTOR_INVALID, this.font.getName() + ": FontDescriptor is null or is an AFM Descriptor"));
        this.fContainer.notEmbedded();
    }
}
Also used : PDFont(org.apache.pdfbox.pdmodel.font.PDFont) PDStream(org.apache.pdfbox.pdmodel.common.PDStream) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) PDFontDescriptor(org.apache.pdfbox.pdmodel.font.PDFontDescriptor)

Example 73 with ValidationError

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

the class FontDescriptorHelper method checkMandatoryFields.

protected boolean checkMandatoryFields(COSDictionary fDescriptor) {
    boolean result = true;
    StringBuilder missingFields = new StringBuilder();
    for (String field : MANDATORYFIELDS) {
        if (!fDescriptor.containsKey(field)) {
            if (missingFields.length() > 1) {
                missingFields.append(", ");
            }
            missingFields.append(field);
        }
    }
    if (fDescriptor.containsKey(COSName.TYPE)) {
        COSBase type = fDescriptor.getItem(COSName.TYPE);
        if (!COSName.FONT_DESC.equals(type)) {
            this.fContainer.push(new ValidationError(ERROR_FONTS_DESCRIPTOR_INVALID, this.font.getName() + ": /Type in FontDescriptor must be /FontDescriptor, but is " + type));
            result = false;
        }
    }
    if (missingFields.length() > 0) {
        this.fContainer.push(new ValidationError(ERROR_FONTS_DESCRIPTOR_INVALID, this.font.getName() + ": some mandatory fields are missing from the FontDescriptor: " + missingFields + "."));
        result = false;
    }
    return result;
}
Also used : COSBase(org.apache.pdfbox.cos.COSBase) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

Example 74 with ValidationError

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

the class TrueTypeDescriptorHelper method extractFontFile.

@Override
public PDStream extractFontFile(PDFontDescriptor fontDescriptor) {
    PDStream fontFile = fontDescriptor.getFontFile2();
    COSStream stream = (fontFile == null ? null : fontFile.getCOSObject());
    if (stream == null) {
        this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile2 is missing"));
        this.fContainer.notEmbedded();
        return null;
    }
    if (stream.getInt(COSName.LENGTH1) <= 0) {
        this.fContainer.push(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID, fontDescriptor.getFontName() + ": The FontFile entry /Length1 is invalid"));
        return null;
    }
    return fontFile;
}
Also used : COSStream(org.apache.pdfbox.cos.COSStream) PDStream(org.apache.pdfbox.pdmodel.common.PDStream) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

Example 75 with ValidationError

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

the class Type1DescriptorHelper method checkMandatoryFields.

@Override
protected boolean checkMandatoryFields(COSDictionary fDescriptor) {
    boolean result = super.checkMandatoryFields(fDescriptor);
    /*
         * if this font is a subset, the CharSet entry must be present in the FontDescriptor
         */
    if (isSubSet(fontDescriptor.getFontName())) {
        String charsetStr = fontDescriptor.getCharSet();
        if (charsetStr == null || "".equals(charsetStr)) {
            this.fContainer.push(new ValidationError(ERROR_FONTS_CHARSET_MISSING_FOR_SUBSET, fontDescriptor.getFontName() + ": The Charset entry is missing for the Type1 Subset"));
            result = false;
        }
    }
    return result;
}
Also used : 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