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