Related Article(s):
Created
October 27, 2023 06:57
-
-
Save GroupDocsGists/007b65c5b438f535a8f1c0002ffacd0b to your computer and use it in GitHub Desktop.
Manage EPUB Metadata using Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Read Dublin Core metadata using Java | |
try (Metadata metadata = new Metadata("path/ebook.epub")) { | |
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()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Read EPUB metadata using Java | |
try (Metadata metadata = new Metadata("path/ebook.epub")) { | |
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Update Dublin Core metadata using Java | |
try (Metadata metadata = new Metadata("path/ebook.epub")) { | |
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("path/ebook.epub"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Update EPUB metadata using Java | |
try (Metadata metadata = new Metadata("path/ebook.epub")) { | |
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("path/ebook.epub"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment