use of org.apache.xmpbox.schema.XMPBasicSchema in project pdfbox by apache.
the class DeserializationTest method testWihtAttributesAsProperties.
@Test
void testWihtAttributesAsProperties() throws Exception {
InputStream fis = DomXmpParser.class.getResourceAsStream("/validxmp/attr_as_props.xml");
DomXmpParser xdb = new DomXmpParser();
XMPMetadata meta = xdb.parse(fis);
AdobePDFSchema pdf = meta.getAdobePDFSchema();
assertEquals("GPL Ghostscript 8.64", pdf.getProducer());
DublinCoreSchema dc = meta.getDublinCoreSchema();
assertEquals("application/pdf", dc.getFormat());
XMPBasicSchema basic = meta.getXMPBasicSchema();
assertNotNull(basic.getCreateDate());
}
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 OpenOLAT by OpenOLAT.
the class PdfDocument method addMetadata.
public void addMetadata(String title, String subject, String author) throws IOException, TransformerException {
PDDocumentCatalog catalog = document.getDocumentCatalog();
PDDocumentInformation info = document.getDocumentInformation();
Calendar date = Calendar.getInstance();
info.setAuthor(author);
info.setCreator(author);
info.setCreationDate(date);
info.setModificationDate(date);
info.setTitle(title);
info.setSubject(subject);
XMPMetadata metadata = XMPMetadata.createXMPMetadata();
AdobePDFSchema pdfSchema = metadata.createAndAddAdobePDFSchema();
pdfSchema.setProducer("OpenOLAT");
XMPBasicSchema basicSchema = metadata.createAndAddXMPBasicSchema();
basicSchema.setModifyDate(date);
basicSchema.setCreateDate(date);
basicSchema.setCreatorTool("OpenOLAT");
basicSchema.setMetadataDate(date);
DublinCoreSchema dcSchema = metadata.createAndAddDublinCoreSchema();
dcSchema.setTitle(title);
dcSchema.addCreator(author);
dcSchema.setDescription(subject);
PDMetadata metadataStream = new PDMetadata(document);
// Create and return XMP data structure in XML format
try (ByteArrayOutputStream xmpOutputStream = new ByteArrayOutputStream()) {
new XmpSerializer().serialize(metadata, xmpOutputStream, true);
metadataStream.importXMPMetadata(xmpOutputStream.toByteArray());
} catch (IOException e) {
log.error("", e);
}
catalog.setMetadata(metadataStream);
}
use of org.apache.xmpbox.schema.XMPBasicSchema in project gdmatrix by gdmatrix.
the class PdfboxSigner method setDocumentInfo.
private PDDocument setDocumentInfo(PDDocument document, DocumentInfo docInfo) throws TransformerException, IOException {
PDDocument outDocument = null;
if (docInfo != null) {
PDDocumentInformation info = document.getDocumentInformation();
// Change document metadata
if (docInfo.getAuthor() != null)
info.setAuthor(docInfo.getAuthor());
if (docInfo.getTitle() != null)
info.setTitle(docInfo.getTitle());
if (docInfo.getSubject() != null)
info.setSubject(docInfo.getSubject());
if (docInfo.getKeywords() != null)
info.setKeywords(docInfo.getKeywords());
document.setDocumentInformation(info);
XMPMetadata metadata = XMPMetadata.createXMPMetadata();
AdobePDFSchema pdfSchema = metadata.createAndAddAdobePDFSchema();
if (info.getKeywords() != null)
pdfSchema.setKeywords(info.getKeywords());
if (info.getProducer() != null)
pdfSchema.setProducer(info.getProducer());
XMPBasicSchema basicSchema = metadata.createAndAddXMPBasicSchema();
if (info.getModificationDate() != null)
basicSchema.setModifyDate(info.getModificationDate());
if (info.getCreationDate() != null)
basicSchema.setCreateDate(info.getCreationDate());
if (info.getCreator() != null)
basicSchema.setCreatorTool(info.getCreator());
if (info.getCreationDate() != null)
basicSchema.setMetadataDate(info.getCreationDate());
DublinCoreSchema dcSchema = metadata.createAndAddDublinCoreSchema();
if (info.getTitle() != null)
dcSchema.setTitle(info.getTitle());
if (info.getAuthor() != null)
dcSchema.addCreator(info.getAuthor());
if (info.getSubject() != null)
dcSchema.setDescription(info.getSubject());
PDMetadata metadataStream = new PDMetadata(document);
PDDocumentCatalog catalog = document.getDocumentCatalog();
catalog.setMetadata(metadataStream);
XmpSerializer serializer = new XmpSerializer();
ByteArrayOutputStream out = new ByteArrayOutputStream();
serializer.serialize(metadata, out, false);
metadataStream.importXMPMetadata(out.toByteArray());
// Save all document & reload is needed.
File tmpFile = File.createTempFile("metadata", ".pdf");
try (FileOutputStream fos = new FileOutputStream(tmpFile);
FileInputStream fis = new FileInputStream(tmpFile)) {
document.save(fos);
outDocument = PDDocument.load(fis);
document.close();
} finally {
tmpFile.delete();
}
}
return outDocument;
}
Aggregations