Search in sources :

Example 11 with XMPBasicSchema

use of org.apache.xmpbox.schema.XMPBasicSchema in project pdfbox by apache.

the class MetadataValidationProcess method checkThumbnails.

// check thumbnails. See Bavaria Testsuite file PDFA_Conference_2009_nc.pdf for an example.
private void checkThumbnails(PreflightContext ctx, XMPMetadata metadata) {
    XMPBasicSchema xmp = metadata.getXMPBasicSchema();
    if (xmp == null) {
        return;
    }
    List<ThumbnailType> tbProp;
    try {
        tbProp = xmp.getThumbnailsProperty();
    } catch (BadFieldValueException e) {
        // should not happen here because it would have happened in XmpParser already
        addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_METADATA_FORMAT, e.getMessage(), e));
        return;
    }
    if (tbProp == null) {
        return;
    }
    tbProp.forEach(tb -> checkThumbnail(tb, ctx));
}
Also used : BadFieldValueException(org.apache.xmpbox.type.BadFieldValueException) XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) ThumbnailType(org.apache.xmpbox.type.ThumbnailType)

Example 12 with XMPBasicSchema

use of org.apache.xmpbox.schema.XMPBasicSchema in project pdfbox by apache.

the class TestSynchronizedMetadataValidation method testBadPrefixSchemas.

/**
 * Check reaction when metadata are well-formed
 *
 * @throws Exception
 */
@Test
void testBadPrefixSchemas() throws Exception {
    initValues();
    // building temporary XMP metadata
    DublinCoreSchema dc = new DublinCoreSchema(metadata, "dctest");
    metadata.addSchema(dc);
    XMPBasicSchema xmp = new XMPBasicSchema(metadata, "xmptest");
    metadata.addSchema(xmp);
    AdobePDFSchema pdf = new AdobePDFSchema(metadata, "pdftest");
    metadata.addSchema(pdf);
    // Writing info in XMP and Document Information dictionary
    // TITLE
    dico.setTitle(title);
    dc.setTitle("x-default", title);
    // AUTHOR
    dico.setAuthor(author);
    dc.addCreator(author);
    // SUBJECT
    dico.setSubject(subject);
    dc.addDescription("x-default", subject);
    // KEYWORDS
    dico.setKeywords(keywords);
    pdf.setKeywords(keywords);
    // CREATOR
    dico.setCreator(creator);
    xmp.setCreatorTool(creator);
    // PRODUCER
    dico.setProducer(producer);
    pdf.setProducer(producer);
    // CREATION DATE
    dico.setCreationDate(creationDate);
    xmp.setCreateDate(creationDate);
    // MODIFY DATE
    dico.setModificationDate(modifyDate);
    xmp.setModifyDate(modifyDate);
    // Launching synchronization test
    try {
        ve = sync.validateMetadataSynchronization(doc, metadata);
        for (ValidationError valid : ve) {
            assertEquals(PreflightConstants.ERROR_METADATA_WRONG_NS_PREFIX, valid.getErrorCode());
        }
    } catch (ValidationException e) {
        throw new Exception(e.getMessage());
    }
}
Also used : ValidationException(org.apache.pdfbox.preflight.exception.ValidationException) XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) DublinCoreSchema(org.apache.xmpbox.schema.DublinCoreSchema) AdobePDFSchema(org.apache.xmpbox.schema.AdobePDFSchema) IOException(java.io.IOException) ValidationException(org.apache.pdfbox.preflight.exception.ValidationException) Test(org.junit.jupiter.api.Test)

Example 13 with XMPBasicSchema

use of org.apache.xmpbox.schema.XMPBasicSchema in project pdfbox by apache.

the class TestSynchronizedMetadataValidation method testAllInfoUnsynchronized.

/**
 * Check the detection of unsynchronized information between Document Information dictionary and XMP
 *
 * @throws Exception
 */
@Test
void testAllInfoUnsynchronized() throws Exception {
    // building temporary XMP metadata
    DublinCoreSchema dc = metadata.createAndAddDublinCoreSchema();
    AdobePDFSchema pdf = metadata.createAndAddAdobePDFSchema();
    XMPBasicSchema xmp = metadata.createAndAddXMPBasicSchema();
    // Writing info in XMP and Document Information dictionary
    // TITLE
    dico.setTitle("dicoTitle");
    dc.setTitle("x-default", "XMPTitle");
    // AUTHOR
    dico.setAuthor("dicoAuthor");
    dc.addCreator("XMPAuthor");
    // SUBJECT
    dico.setSubject("dicoSubj");
    dc.addSubject("XMPSubj");
    // KEYWORDS
    dico.setKeywords("DicoKeywords");
    pdf.setKeywords("XMPkeywords");
    // CREATOR
    dico.setCreator("DicoCreator");
    xmp.setCreatorTool("XMPCreator");
    // PRODUCER
    dico.setProducer("DicoProducer");
    pdf.setProducer("XMPProducer");
    // CREATION DATE
    dico.setCreationDate(Calendar.getInstance());
    GregorianCalendar XMPCreate = new GregorianCalendar(2008, 11, 05);
    xmp.setCreateDate(XMPCreate);
    // MODIFY DATE
    dico.setModificationDate(Calendar.getInstance());
    GregorianCalendar XMPModify = new GregorianCalendar(2009, 10, 15);
    xmp.setModifyDate(XMPModify);
    // Launching synchronization test
    try {
        ve = sync.validateMetadataSynchronization(doc, metadata);
        // Test unsychronized value
        assertEquals(8, ve.size());
    } catch (ValidationException e) {
        throw new Exception(e.getMessage());
    }
}
Also used : ValidationException(org.apache.pdfbox.preflight.exception.ValidationException) XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema) GregorianCalendar(java.util.GregorianCalendar) DublinCoreSchema(org.apache.xmpbox.schema.DublinCoreSchema) AdobePDFSchema(org.apache.xmpbox.schema.AdobePDFSchema) IOException(java.io.IOException) ValidationException(org.apache.pdfbox.preflight.exception.ValidationException) Test(org.junit.jupiter.api.Test)

Example 14 with XMPBasicSchema

use of org.apache.xmpbox.schema.XMPBasicSchema in project pdfbox by apache.

the class XMPMetadata method createAndAddXMPBasicSchema.

/**
 * Create and add a XMP Basic schema to this metadata.
 *
 * This method return the created schema to enter information
 *
 * @return schema added in order to work on it
 */
public XMPBasicSchema createAndAddXMPBasicSchema() {
    XMPBasicSchema xmpB = new XMPBasicSchema(this);
    xmpB.setAboutAsSimple("");
    addSchema(xmpB);
    return xmpB;
}
Also used : XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema)

Example 15 with XMPBasicSchema

use of org.apache.xmpbox.schema.XMPBasicSchema in project pdfbox by apache.

the class PDFMergerExample method createXMPMetadata.

private PDMetadata createXMPMetadata(COSStream cosStream, String title, String creator, String subject) throws BadFieldValueException, TransformerException, IOException {
    LOG.info("Setting XMP metadata (title, author, subject) for merged PDF");
    XMPMetadata xmpMetadata = XMPMetadata.createXMPMetadata();
    // PDF/A-1b properties
    PDFAIdentificationSchema pdfaSchema = xmpMetadata.createAndAddPDFAIdentificationSchema();
    pdfaSchema.setPart(1);
    pdfaSchema.setConformance("B");
    // Dublin Core properties
    DublinCoreSchema dublinCoreSchema = xmpMetadata.createAndAddDublinCoreSchema();
    dublinCoreSchema.setTitle(title);
    dublinCoreSchema.addCreator(creator);
    dublinCoreSchema.setDescription(subject);
    // XMP Basic properties
    XMPBasicSchema basicSchema = xmpMetadata.createAndAddXMPBasicSchema();
    Calendar creationDate = Calendar.getInstance();
    basicSchema.setCreateDate(creationDate);
    basicSchema.setModifyDate(creationDate);
    basicSchema.setMetadataDate(creationDate);
    basicSchema.setCreatorTool(creator);
    // Create and return XMP data structure in XML format
    try (ByteArrayOutputStream xmpOutputStream = new ByteArrayOutputStream();
        OutputStream cosXMPStream = cosStream.createOutputStream()) {
        new XmpSerializer().serialize(xmpMetadata, xmpOutputStream, true);
        cosXMPStream.write(xmpOutputStream.toByteArray());
        return new PDMetadata(cosStream);
    }
}
Also used : PDFAIdentificationSchema(org.apache.xmpbox.schema.PDFAIdentificationSchema) XmpSerializer(org.apache.xmpbox.xml.XmpSerializer) XMPMetadata(org.apache.xmpbox.XMPMetadata) Calendar(java.util.Calendar) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PDMetadata(org.apache.pdfbox.pdmodel.common.PDMetadata) DublinCoreSchema(org.apache.xmpbox.schema.DublinCoreSchema)

Aggregations

XMPBasicSchema (org.apache.xmpbox.schema.XMPBasicSchema)19 DublinCoreSchema (org.apache.xmpbox.schema.DublinCoreSchema)15 AdobePDFSchema (org.apache.xmpbox.schema.AdobePDFSchema)13 IOException (java.io.IOException)8 ValidationException (org.apache.pdfbox.preflight.exception.ValidationException)8 Test (org.junit.jupiter.api.Test)8 XMPMetadata (org.apache.xmpbox.XMPMetadata)7 PDDocumentInformation (org.apache.pdfbox.pdmodel.PDDocumentInformation)6 PDMetadata (org.apache.pdfbox.pdmodel.common.PDMetadata)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 GregorianCalendar (java.util.GregorianCalendar)5 PDDocumentCatalog (org.apache.pdfbox.pdmodel.PDDocumentCatalog)5 XmpSerializer (org.apache.xmpbox.xml.XmpSerializer)5 Calendar (java.util.Calendar)4 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)3 PDFAIdentificationSchema (org.apache.xmpbox.schema.PDFAIdentificationSchema)3 BadFieldValueException (org.apache.xmpbox.type.BadFieldValueException)3 File (java.io.File)2 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)2 DomXmpParser (org.apache.xmpbox.xml.DomXmpParser)2