-
Notifications
You must be signed in to change notification settings - Fork 2
Getting started
An ePub file is really just a ZIP file with a fancy extension. You can extract it just as you would a ZIP file.
var targetFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Dawn of Wonder - Jonathan Renshaw");
using (var stream = await ePubFile.OpenStreamForReadAsync())
{
var archive = new ZipArchive(stream);
archive.ExtractToDirectory(targetFolder.Path);
}
You'll need to create the eBook, handing it the StorageFolder
to which you extracted the ePub.
var eBook = new EBook(targetFolder);
When you initialize the eBook it will get all the properties of the ePub (e.g. the title, author, etc.)
await eBook.InitializeAsync();
You can now get HTML content from your eBook. If you want to display the content using native controls, keep reading to see Papyrus.HtmlParser
usage.
Papyrus HTML Parser allows you to get a collection of Block
elements which can be displayed in a RichTextBlock
, representing the HTML. It makes for a much cleaner layout, but could potentially misrepresent the actual layout as displayed in HTML.
The EBook.GetContentsAsync()
method has three different signatures. It can take a NavPoint
, a SpineItem
or a ManifestItem
.
var html = await eBook.GetContentsAsync(item);
Parsing the HTML is as easy as
var converter = new Converter();
converter.Convert(html, string.Empty);
You will now have access to a collection of Block
elements which represent the converted HTML.
The second parameter in the Convert
method takes CSS styles. Getting the CSS styles is optional, but will help to display the UI more closely to how it is displayed in HTML. You may use whatever method you wish to get the CSS content, now that you can parse the location of the stylesheets from the HTML. The EBook class does have an extension method which takes an absolute path to a file inside its folder and returns the file. E.g. Book.GetFileAsync("C:/Path/To/The/EBook/styles/styles.css");
I intend to build the CSS loading functionality right into Papyrus in the future. If you opt not to get the CSS, just pass an empty string to the parser.