Search in sources :

Example 1 with TextType

use of org.apache.xmpbox.type.TextType in project pdfbox by apache.

the class FontMetaDataValidation method analyseFontName.

/**
 * Value of the dc:title must be the same as the FontName in the font descriptor.
 *
 * @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
 */
public boolean analyseFontName(XMPMetadata metadata, PDFontDescriptor fontDesc, List<ValidationError> ve) {
    String fontName = fontDesc.getFontName();
    String noSubSetName = fontName;
    if (FontDescriptorHelper.isSubSet(fontName)) {
        noSubSetName = fontName.split("\\+")[1];
    }
    DublinCoreSchema dc = metadata.getDublinCoreSchema();
    if (dc != null && dc.getTitleProperty() != null) {
        String defaultTitle = dc.getTitle("x-default");
        if (defaultTitle != null) {
            if (!defaultTitle.equals(fontName) && (noSubSetName != null && !defaultTitle.equals(noSubSetName))) {
                StringBuilder sb = new StringBuilder(80);
                sb.append("FontName").append(" present in the FontDescriptor dictionary doesn't match with XMP information dc:title of the Font File Stream.");
                ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_MISMATCH, sb.toString()));
                return false;
            }
            // --- default value is the right one
            return true;
        } else {
            Iterator<AbstractField> it = dc.getTitleProperty().getContainer().getAllProperties().iterator();
            boolean empty = true;
            while (it.hasNext()) {
                empty = false;
                AbstractField tmp = it.next();
                if (tmp instanceof TextType) {
                    String val = ((TextType) tmp).getStringValue();
                    if (val.equals(fontName) || val.equals(noSubSetName)) {
                        // value found, return
                        return true;
                    }
                }
            }
            // title doesn't match, it is an error.
            StringBuilder sb = new StringBuilder(80);
            sb.append("FontName");
            if (empty) {
                sb.append(" present in the FontDescriptor dictionary can't be found in XMP information the Font File Stream.");
                ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_PROPERTY_MISSING, sb.toString()));
            } else {
                sb.append(" present in the FontDescriptor dictionary doesn't match with XMP information dc:title of the Font File Stream.");
                ve.add(new ValidationError(PreflightConstants.ERROR_METADATA_MISMATCH, sb.toString()));
            }
            return false;
        }
    }
    return true;
}
Also used : AbstractField(org.apache.xmpbox.type.AbstractField) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) DublinCoreSchema(org.apache.xmpbox.schema.DublinCoreSchema) TextType(org.apache.xmpbox.type.TextType)

Example 2 with TextType

use of org.apache.xmpbox.type.TextType in project pdfbox by apache.

the class AdobePDFSchema method setKeywords.

/**
 * Set the PDF keywords
 *
 * @param value
 *            Value to set
 */
public void setKeywords(String value) {
    TextType keywords;
    keywords = createTextType(KEYWORDS, value);
    addProperty(keywords);
}
Also used : TextType(org.apache.xmpbox.type.TextType)

Example 3 with TextType

use of org.apache.xmpbox.type.TextType in project pdfbox by apache.

the class PDFAIdentificationSchema method setConformance.

/**
 * Set the PDF/A conformance level
 *
 * @param value
 *            The conformance level value to set
 * @throws BadFieldValueException
 *             If Conformance Value not 'A', 'B' or 'U' (PDF/A-2 and PDF/A-3)
 */
public void setConformance(String value) throws BadFieldValueException {
    if (value.equals("A") || value.equals("B") || value.equals("U")) {
        TextType conf = createTextType(CONFORMANCE, value);
        addProperty(conf);
    } else {
        throw new BadFieldValueException("The property given not seems to be a PDF/A conformance level (must be A, B or U)");
    }
}
Also used : BadFieldValueException(org.apache.xmpbox.type.BadFieldValueException) TextType(org.apache.xmpbox.type.TextType)

Example 4 with TextType

use of org.apache.xmpbox.type.TextType in project pdfbox by apache.

the class PhotoshopSchema method setTransmissionReference.

public void setTransmissionReference(String text) {
    TextType tt = (TextType) instanciateSimple(TRANSMISSION_REFERENCE, text);
    setTransmissionReferenceProperty(tt);
}
Also used : TextType(org.apache.xmpbox.type.TextType)

Example 5 with TextType

use of org.apache.xmpbox.type.TextType in project pdfbox by apache.

the class PhotoshopSchema method setCategory.

public void setCategory(String text) {
    TextType tt = (TextType) instanciateSimple(CATEGORY, text);
    setCategoryProperty(tt);
}
Also used : TextType(org.apache.xmpbox.type.TextType)

Aggregations

TextType (org.apache.xmpbox.type.TextType)37 AbstractField (org.apache.xmpbox.type.AbstractField)5 ArrayProperty (org.apache.xmpbox.type.ArrayProperty)5 Test (org.junit.Test)4 Method (java.lang.reflect.Method)3 Attribute (org.apache.xmpbox.type.Attribute)3 XMPMetadata (org.apache.xmpbox.XMPMetadata)2 InputStream (java.io.InputStream)1 Calendar (java.util.Calendar)1 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)1 DublinCoreSchema (org.apache.xmpbox.schema.DublinCoreSchema)1 BadFieldValueException (org.apache.xmpbox.type.BadFieldValueException)1 BooleanType (org.apache.xmpbox.type.BooleanType)1 DateType (org.apache.xmpbox.type.DateType)1 IntegerType (org.apache.xmpbox.type.IntegerType)1 TypeMapping (org.apache.xmpbox.type.TypeMapping)1 URIType (org.apache.xmpbox.type.URIType)1 URLType (org.apache.xmpbox.type.URLType)1 DomXmpParser (org.apache.xmpbox.xml.DomXmpParser)1