public static async Task <bool> SetCurentBookContent(string fileName) { _currentBook = await EpubReader.OpenBookAsync("fileName"); if (_currentBook != null) { return(true); } return(false); }
public async Task <IEnumerable <PropertyItem> > GetItems(IItem item, Detaillevel detail) { var book = await EpubReader.OpenBookAsync(item.Path).ConfigureAwait(false); var properties = new List <PropertyItem> { new PropertyItem("Title", book.Title), new PropertyItem("Authors", string.Join(Environment.NewLine, book.AuthorList)), }; var cover = await book.ReadCoverAsync().ConfigureAwait(false); if (cover != null) { properties.Add(new PropertyItem("Thumbnail", ImageFromBuffer(cover))); } return(properties.AsEnumerable()); }
private async void Button_Click(object sender, RoutedEventArgs e) { //Init epub object. //bool fileExist = await EpubReader.DoesFileExistAsync(Windows.ApplicationModel.Package.Current.InstalledLocation, "test.epub"); //if (!fileExist) // throw new Exception(string.Format("File test.epub not found, bitch")); progressbar.Text = "Загрузка книги"; await progressbar.ShowAsync(); //bookLoadingProgressBar.Visibility = Visibility.Visible; // Opening a book currentEpubBook = await EpubReader.OpenBookAsync("test.epub"); if (currentEpubBook != null) { loadEbookButton.Content = "Loaded"; loadEbookButton.IsEnabled = false; } //// COMMON PROPERTIES //// Book's title //string title = currentEpubBook.Title; //// Book's authors (comma separated list) //string author = currentEpubBook.Author; //// Book's authors (list of authors names) //List<string> authors = currentEpubBook.AuthorList; //// Book's cover image (null if there are no cover) //BitmapImage coverImage = currentEpubBook.CoverImage; //// ShowCoverImage(coverImage); //Only for testing purposes // CONTENT // Book's content (HTML files, style-sheets, images, fonts, etc.) EpubContent bookContent = currentEpubBook.Content; // IMAGES // All images in the book (file name is the key) //Dictionary<string, EpubByteContentFile> images = bookContent.Images; //EpubByteContentFile firstImage = images.Values.First(); //// Content type (e.g. EpubContentType.IMAGE_JPEG, EpubContentType.IMAGE_PNG) //EpubContentType contentType = firstImage.ContentType; //// MIME type (e.g. "image/jpeg", "image/png") //string mimeContentType = firstImage.ContentMimeType; // HTML & CSS // All XHTML files in the book (file name is the key) Dictionary <string, EpubTextContentFile> htmlFiles = bookContent.Html; // All CSS files in the book (file name is the key) Dictionary <string, EpubTextContentFile> cssFiles = bookContent.Css; // All CSS content in the book //foreach (EpubTextContentFile cssFile in cssFiles.Values) //{ // string cssContent = cssFile.Content; //} // OTHER CONTENT // All fonts in the book (file name is the key) // Dictionary<string, EpubByteContentFile> fonts = bookContent.Fonts; // All files in the book (including HTML, CSS, images, fonts, and other types of files) //TO-DO looks like this dictionary not working well at the moment, have to trace //Dictionary<string, EpubContentFile> allFiles = bookContent.AllFiles; //To-DO: //Определить первый файл в книге - через spine или через guide //Отслеживать клики по экрану и по краям экрана - чтобы листать вперед и назад. //Отслеживать, когда на экране последняя column из файла и нужно подгружать следующую await progressbar.HideAsync(); progressbar.Text = "Форматирование"; await progressbar.ShowAsync(); // Entire HTML content of the book should be injected in case we are showing chapter by chapter, and not pretending to load the whole set of chapters //foreach (KeyValuePair<string, EpubTextContentFile> htmlItem in htmlFiles) //{ // string injectedItem = WebViewHelpers.injectMonocle(htmlItem.Value.Content, // (int)bookReaderWebViewControl.ActualWidth, (int)bookReaderWebViewControl.ActualHeight); // htmlItem.Value.Content = injectedItem; //} IndexFileSceleton index = new IndexFileSceleton(); index.author = currentEpubBook.Author; index.title = currentEpubBook.Title; index.height = (int)bookReaderWebViewControl.ActualHeight; index.chapters = currentEpubBook.Chapters; index.xhtmlFiles = currentEpubBook.Content.Html; // --- Streaming HTML+JS content directly from the memory --- //Uri url = bookReaderWebViewControl.BuildLocalStreamUri("MemoryTag", "section4.xhtml"); CreateIndex(); Uri url = bookReaderWebViewControl.BuildLocalStreamUri("MemoryTag", "index.html"); bookReaderWebViewControl.NavigateToLocalStreamUri(url, myMemoryResolver); //Now we could have a look at the chapters list chaptersMenuButton.IsEnabled = true; await progressbar.HideAsync(); //bookLoadingProgressBar.Visibility = Visibility.Collapsed; // ACCESSING RAW SCHEMA INFORMATION //// EPUB OPF data //EpubPackage package = epubBook.Schema.Package; //// Enumerating book's contributors //foreach (EpubMetadataContributor contributor in package.Metadata.Contributors) //{ // string contributorName = contributor.Contributor; // string contributorRole = contributor.Role; //} //// EPUB NCX data //EpubNavigation navigation = epubBook.Schema.Navigation; //// Enumerating NCX metadata //foreach (EpubNavigationHeadMeta meta in navigation.Head) //{ // string metadataItemName = meta.Name; // string metadataItemContent = meta.Content; //} }