Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active October 27, 2023 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/f042bfdab47ce0f808c5fed74cbc3d44 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/f042bfdab47ce0f808c5fed74cbc3d44 to your computer and use it in GitHub Desktop.
Manage EPUB Metadata using C#
// Read Dublin Core metadata using C#
using (Metadata metadata = new Metadata("path/ebook.epub"))
{
var root = metadata.GetRootPackage<EpubRootPackage>();
Console.WriteLine(root.DublinCorePackage.Rights);
Console.WriteLine(root.DublinCorePackage.Publisher);
Console.WriteLine(root.DublinCorePackage.Title);
Console.WriteLine(root.DublinCorePackage.Creator);
Console.WriteLine(root.DublinCorePackage.Language);
Console.WriteLine(root.DublinCorePackage.Date);
}
// Read EPUB metadata using C#
using (Metadata metadata = new Metadata("path/ebook.epub"))
{
var root = metadata.GetRootPackage<EpubRootPackage>();
Console.WriteLine(root.EpubPackage.Version);
Console.WriteLine(root.EpubPackage.UniqueIdentifier);
Console.WriteLine(root.EpubPackage.ImageCover != null ? root.EpubPackage.ImageCover.Length : 0);
Console.WriteLine(root.EpubPackage.Description);
Console.WriteLine(root.EpubPackage.Title);
}
// Update Dublin Core metadata using C#
using (Metadata metadata = new Metadata("path/ebook.epub"))
{
var root = metadata.GetRootPackage<EpubRootPackage>();
root.DublinCorePackage.SetProperties(p => p.Name == "dc:creator", new PropertyValue("GroupDocs"));
root.DublinCorePackage.SetProperties(p => p.Name == "dc:description", new PropertyValue("metadata updated e-book"));
root.DublinCorePackage.SetProperties(p => p.Name == "dc:title", new PropertyValue("Sample EPUB"));
root.DublinCorePackage.SetProperties(p => p.Name == "dc:date", new PropertyValue(DateTime.Now.ToString()));
metadata.Save("path/ebook.epub");
}
// Update EPUB metadata using C#
using (Metadata metadata = new Metadata("path/ebook.epub"))
{
var root = metadata.GetRootPackage<EpubRootPackage>();
root.EpubPackage.Creator = "GroupDocs";
root.EpubPackage.Description = "metadata updated e-book";
root.EpubPackage.Format = "EPUB";
root.EpubPackage.Date = DateTime.Now.ToString();
metadata.Save("path/ebook.epub");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment