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));
}
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());
}
}
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());
}
}
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;
}
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);
}
}
Aggregations