Read epub file in ASP.Net using C#

mukesh1
 
on Jun 17, 2022 12:02 AM
Sample_128024.zip
929 Views

i want to read epub file in webform

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jun 18, 2022 06:47 AM
on Jun 18, 2022 06:48 AM

Hi mukesh1,

Use the library EpubReader for reading EPUB files.

Refer below link for more details.

https://github.com/vers-one/EpubReader

First you need to install the library from nuget in your project.

Then use the code for reading the file.

Note: Here i am reading the Title, Author and the Cover Image.

HTML

<asp:Button Text="Read" runat="server" OnClick="OnRead" />
<hr />
<table>
    <tr>
        <th>Title</th>
        <th>Author</th>
        <th>Cover Photo</th>
    </tr>
    <tr>
        <td>
            <asp:Label ID="lblTitle" runat="server" /></td>
        <td>
            <asp:Label ID="lblAuthor" runat="server" /></td>
        <td>
            <asp:Image ID="imgCover" runat="server" Height="200" Width="200" /></td>
    </tr>
</table>

Namespaces

using System.Drawing;
using System.IO;
using VersOne.Epub;

Code

protected void OnRead(object sender, EventArgs e)
{
    // Opens a book and reads all of its content into memory.
    EpubBook epubBook = EpubReader.ReadBook(Server.MapPath("~/Files/Test.epub"));

    // Book's title.
    string title = epubBook.Title;
    lblTitle.Text = title;

    // Book's authors.
    string author = epubBook.Author;
    lblAuthor.Text = title;

    // Book's cover image.
    byte[] coverImageContent = epubBook.CoverImage;
    if (coverImageContent != null)
    {
        using (MemoryStream coverImageStream = new MemoryStream(coverImageContent))
        {
            System.Drawing.Image coverImage = System.Drawing.Image.FromStream(coverImageStream);
            byte[] bytes = (byte[])(new ImageConverter()).ConvertTo(coverImage, typeof(byte[]));
            imgCover.ImageUrl = string.Format("data:image/jpg;base64,{0}", Convert.ToBase64String(bytes));
        }
    }
}

Screenshot