using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; using VersOne.Epub; namespace GxPress.Common.Epub { /// /// 分析Epub /// public static class Analysis { /// /// 加工制造 /// public static void ProcessMake() { // var url = "https://apk.tederen.com/service/cache/20200525/7682915b9dc44f8e98781ddd839291a9.epub"; // FileStream fs = new FileStream(url, FileMode.Open, FileAccess.Read); // // 读取文件的 byte[] // byte[] bytes = new byte[fs.Length]; // fs.Read(bytes, 0, bytes.Length); // fs.Close(); // // 把 byte[] 转换成 Stream // Stream stream = new MemoryStream(bytes); //获取 EpubBook epubBook = EpubReader.ReadBook("wwwroot/cache/20200529/e875998ea9e3407888d93f9060a4154a.epub"); //标题 string title = epubBook.Title; //作者 string author = epubBook.Author; //作者集合 List authors = epubBook.AuthorList; //获取图片封面 // byte[] coverImageContent = epubBook.CoverImage; // if (coverImageContent != null) // { // using (MemoryStream coverImageStream = new MemoryStream(coverImageContent)) // { // Image coverImage = Image.FromStream(coverImageStream); // } // } // 目录 //列举章节 foreach (EpubNavigationItem chapter in epubBook.Navigation) { //本章标题 string chapterTitle = chapter.Title; //嵌套章节 List subChapters = chapter.NestedItems; } //阅读顺序 //按照阅读顺序枚举本书的全文内容 foreach (EpubTextContentFile textContentFile in epubBook.ReadingOrder) { //当前文本内容文件的HTML string htmlContent = textContentFile.Content; } //内容 //书籍的内容(HTML文件,手写板,图像,字体等) EpubContent bookContent = epubBook.Content; // 图片 //书中的所有图片(文件名是关键) Dictionary images = bookContent.Images; EpubByteContentFile firstImage = images.Values.First(); //内容类型(例如EpubContentType.IMAGE_JPEG,EpubContentType.IMAGE_PNG) EpubContentType contentType = firstImage.ContentType; // MIME类型(例如“ image / jpeg”,“ image / png”) string mimeType = firstImage.ContentMimeType; // 从内容创建Image类实例 using (MemoryStream imageStream = new MemoryStream(firstImage.Content)) { Image image = Image.FromStream(imageStream); } } } }