Working with metadata in EPUB e-books
Leave feedback
EPUB is an e-book file format that uses the “.epub” file extension. EPUB is supported by many e-readers, and compatible software is available for most smartphones, tablets, and computers.
NotePlease find more information on the format at https://en.wikipedia.org/wiki/EPUB
The GroupDocs.Metadata API supports extracting format-specific information from EPUB files.
The following are the steps to read native EPUB metadata.
- Load an EPUB file
- Get the root metadata package
- Extract the native metadata package using the EpubRootPackage.getEpubPackage method
- Read the EPUB metadata properties
advanced_usage.managing_metadata_for_specific_formats.
try (Metadata metadata = new Metadata(Constants.InputEpub)) {
EpubRootPackage root = metadata.getRootPackageGeneric();
System.out.println(root.getEpubPackage().getVersion());
System.out.println(root.getEpubPackage().getUniqueIdentifier());
System.out.println(root.getEpubPackage().getImageCover() != null ? root.getEpubPackage().getImageCover().length : 0);
}
The GroupDocs.Metadata API also supports updating some metadata properties of an EPUB file. Please see the code snippet below to learn how to do that.
advanced_usage.managing_metadata_for_specific_formats.
try (Metadata metadata = new Metadata(Constants.InputEpub)) {
EpubRootPackage root = metadata.getRootPackageGeneric();
root.getEpubPackage().setCreator("GroupDocs");
root.getEpubPackage().setDescription("test e-book");
root.getEpubPackage().setFormat("EPUB");
root.getEpubPackage().setDate(new Date().toString());
// ...
metadata.save(Constants.OutputEpub);
}
Dublin Core metadata is a set of certain metadata properties that are intended to describe various digital resources. Please find more information on the Dublin Core standard at https://en.wikipedia.org/wiki/Dublin_Core. The code sample below shows how to extract Dublin Core metadata from a EPUB e-book using the GroupDocs.Metadata API.
advanced_usage.managing_metadata_for_specific_formats.
try (Metadata metadata = new Metadata(Constants.InputEpub)) {
EpubRootPackage root = metadata.getRootPackageGeneric();
System.out.println(root.getDublinCorePackage().getRights());
System.out.println(root.getDublinCorePackage().getPublisher());
System.out.println(root.getDublinCorePackage().getTitle());
System.out.println(root.getDublinCorePackage().getCreator());
System.out.println(root.getDublinCorePackage().getLanguage());
System.out.println(root.getDublinCorePackage().getDate());
// ...
}
Please see the the DublinCorePackage class to get more information on supported Dublin Core metadata properties.
The GroupDocs.Metadata API also allows updating DublinCore metadata properties in an EPUB file. Please check the code sample below.
advanced_usage.managing_metadata_for_specific_formats.
try (Metadata metadata = new Metadata(Constants.InputEpub)) {
EpubRootPackage root = metadata.getRootPackageGeneric();
root.getDublinCorePackage().setProperties(new WithNameSpecification("dc:creator"), new PropertyValue("GroupDocs"));
root.getDublinCorePackage().setProperties(new WithNameSpecification("dc:description"), new PropertyValue("test e-book"));
root.getDublinCorePackage().setProperties(new WithNameSpecification("dc:title"), new PropertyValue("test EPUB"));
root.getDublinCorePackage().setProperties(new WithNameSpecification("dc:date"), new PropertyValue(new Date().toString()));
// ...
metadata.save(Constants.OutputEpub);
}
You may easily run the code above and see the feature in action in our GitHub examples:
Along with full featured Java library we provide simple, but powerful free Apps.
You are welcome to view and edit metadata of PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, emails, images and more with our free online Free Online Document Metadata Viewing and Editing App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.