}
}
private void extractMetadata(PDDocument document, Metadata metadata)
throws TikaException {
PDDocumentInformation info = document.getDocumentInformation();
metadata.set(PagedText.N_PAGES, document.getNumberOfPages());
addMetadata(metadata, TikaCoreProperties.TITLE, info.getTitle());
addMetadata(metadata, TikaCoreProperties.CREATOR, info.getAuthor());
addMetadata(metadata, TikaCoreProperties.CREATOR_TOOL, info.getCreator());
addMetadata(metadata, TikaCoreProperties.KEYWORDS, info.getKeywords());
addMetadata(metadata, "producer", info.getProducer());
// TODO: Move to description in Tika 2.0
addMetadata(metadata, TikaCoreProperties.TRANSITION_SUBJECT_TO_OO_SUBJECT, info.getSubject());
addMetadata(metadata, "trapped", info.getTrapped());
try {
// TODO Remove these in Tika 2.0
addMetadata(metadata, "created", info.getCreationDate());
addMetadata(metadata, TikaCoreProperties.CREATED, info.getCreationDate());
} catch (IOException e) {
// Invalid date format, just ignore
}
try {
Calendar modified = info.getModificationDate();
addMetadata(metadata, Metadata.LAST_MODIFIED, modified);
addMetadata(metadata, TikaCoreProperties.MODIFIED, modified);
} catch (IOException e) {
// Invalid date format, just ignore
}
// All remaining metadata is custom
// Copy this over as-is
List<String> handledMetadata = Arrays.asList(new String[] {
"Author", "Creator", "CreationDate", "ModDate",
"Keywords", "Producer", "Subject", "Title", "Trapped"
});
for(COSName key : info.getDictionary().keySet()) {
String name = key.getName();
if(! handledMetadata.contains(name)) {
addMetadata(metadata, name, info.getDictionary().getDictionaryObject(key));
}
}
}