Search in sources :

Example 6 with XMPBasicSchema

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

the class TestSynchronizedMetadataValidation method testBadSizeOfArrays.

/**
 * in XMP, Subject and Author must be embedded in a single entry text array This function check the detection of
 * multiple entries for these properties
 *
 * @throws Exception
 */
@Test
void testBadSizeOfArrays() 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");
    dc.addCreator("2ndCreator");
    // SUBJECT
    dico.setSubject("dicoSubj");
    dc.addSubject("XMPSubj");
    dc.addSubject("2ndSubj");
    // 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 7 with XMPBasicSchema

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

the class TestSynchronizedMetadataValidation method testAllInfoSynchronized.

/**
 * Check reaction when metadata are well-formed
 *
 * @throws Exception
 */
@Test
void testAllInfoSynchronized() throws Exception {
    initValues();
    // building temporary XMP metadata
    DublinCoreSchema dc = metadata.createAndAddDublinCoreSchema();
    XMPBasicSchema xmp = metadata.createAndAddXMPBasicSchema();
    AdobePDFSchema pdf = metadata.createAndAddAdobePDFSchema();
    // 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);
        // Checking all is synchronized
        assertEquals(0, 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) 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 8 with XMPBasicSchema

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

the class TestSynchronizedMetadataValidation method testPDFBox4292.

/**
 * Tests that two date values, which are from different time zones but
 * really identical, are detected as such.
 *
 * @throws Exception
 */
@Test
void testPDFBox4292() throws Exception {
    initValues();
    Calendar cal1 = org.apache.pdfbox.util.DateConverter.toCalendar("20180817115837+02'00'");
    Calendar cal2 = org.apache.xmpbox.DateConverter.toCalendar("2018-08-17T09:58:37Z");
    XMPBasicSchema xmp = metadata.createAndAddXMPBasicSchema();
    dico.setCreationDate(cal1);
    xmp.setCreateDate(cal2);
    dico.setModificationDate(cal1);
    xmp.setModifyDate(cal2);
    // Launching synchronization test
    try {
        ve = sync.validateMetadataSynchronization(doc, metadata);
        // Test unsychronized value
        assertEquals(0, ve.size());
    } catch (ValidationException e) {
        throw new Exception(e.getMessage());
    }
}
Also used : ValidationException(org.apache.pdfbox.preflight.exception.ValidationException) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema) IOException(java.io.IOException) ValidationException(org.apache.pdfbox.preflight.exception.ValidationException) Test(org.junit.jupiter.api.Test)

Example 9 with XMPBasicSchema

use of org.apache.xmpbox.schema.XMPBasicSchema in project mustangproject by ZUGFeRD.

the class ZUGFeRDExporter method makeDocPDFA3compliant.

private PDDocumentCatalog makeDocPDFA3compliant(String producer, String creator, boolean attachZugferdHeaders) throws IOException, TransformerException {
    String fullProducer = producer + " (via mustangproject.org " + Version.VERSION + ")";
    PDDocumentCatalog cat = doc.getDocumentCatalog();
    PDMetadata metadata = new PDMetadata(doc);
    cat.setMetadata(metadata);
    XMPMetadata xmp = XMPMetadata.createXMPMetadata();
    PDFAIdentificationSchema pdfaid = new PDFAIdentificationSchema(xmp);
    xmp.addSchema(pdfaid);
    DublinCoreSchema dc = xmp.createAndAddDublinCoreSchema();
    dc.addCreator(creator);
    XMPBasicSchema xsb = xmp.createAndAddXMPBasicSchema();
    xsb.setCreatorTool(creator);
    xsb.setCreateDate(GregorianCalendar.getInstance());
    // PDDocumentInformation pdi=doc.getDocumentInformation();
    PDDocumentInformation pdi = new PDDocumentInformation();
    pdi.setProducer(fullProducer);
    pdi.setAuthor(creator);
    doc.setDocumentInformation(pdi);
    AdobePDFSchema pdf = xmp.createAndAddAdobePDFSchema();
    pdf.setProducer(fullProducer);
    /*
		*
		* To be on the safe side, we use level B without Markinfo because we
		* can not guarantee that the user correctly tagged the templates for
		* the PDF.
		*/
    try {
        //$NON-NLS-1$ //$NON-NLS-1$
        pdfaid.setConformance(conformanceLevel.getLetter());
    } catch (BadFieldValueException ex) {
        // supplied, however the enum enforces that the conformance level is valid.
        throw new Error(ex);
    }
    pdfaid.setPart(3);
    if (attachZugferdHeaders) {
        addZugferdXMP(xmp);
    /*
								 * this is the only line where we do something
								 * Zugferd-specific, i.e. add PDF metadata
								 * specifically for Zugferd, not generically for
								 * a embedded file
								 */
    }
    XmpSerializer serializer = new XmpSerializer();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    serializer.serialize(xmp, baos, false);
    metadata.importXMPMetadata(baos.toByteArray());
    return cat;
}
Also used : BadFieldValueException(org.apache.xmpbox.type.BadFieldValueException) XmpSerializer(org.apache.xmpbox.xml.XmpSerializer) XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema) PDMetadata(org.apache.pdfbox.pdmodel.common.PDMetadata) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PDDocumentCatalog(org.apache.pdfbox.pdmodel.PDDocumentCatalog) PDFAIdentificationSchema(org.apache.xmpbox.schema.PDFAIdentificationSchema) XMPMetadata(org.apache.xmpbox.XMPMetadata) DublinCoreSchema(org.apache.xmpbox.schema.DublinCoreSchema) AdobePDFSchema(org.apache.xmpbox.schema.AdobePDFSchema) PDDocumentInformation(org.apache.pdfbox.pdmodel.PDDocumentInformation)

Example 10 with XMPBasicSchema

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

the class ExtractMetadata method showXMPBasicSchema.

private static void showXMPBasicSchema(XMPMetadata metadata) {
    XMPBasicSchema basic = metadata.getXMPBasicSchema();
    if (basic != null) {
        display("Create Date:", basic.getCreateDate());
        display("Modify Date:", basic.getModifyDate());
        display("Creator Tool:", basic.getCreatorTool());
    }
}
Also used : XMPBasicSchema(org.apache.xmpbox.schema.XMPBasicSchema)

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