LIT or EPUB eBook in-a-window support?

Does anyone know how I can display LIT or EPUB eBook files within Corona, either natively or via a plugin?

I’m working on a new project that requires me to open eBook files, but I don’t want to require the user to leave my app to open another eBook reader. I’d like to keep the eBook display within a window of my app, similar to how webView works.

Any help is very much appreciated.

Hi Troy.

I’m unaware of any plugins to process these files. We certainly don’t have any internal API’s to process them. EPUB probably has a standardized format. There may be a Lua library out there that can help. I would suggest heading to Google or the search engine of your choice and see what you can find.

You could also post a job request to get a community developer to build a plugin if there are some standard C++/iOS or Android SDK’s that could be incorporated within reason.

But since I don’t know what the format is about, if it’s just text and images, it’s likely possible, but if those formats contain any interactivity, the complexity of such a plugin would be considerably more difficult.

Rob

@Rob, thank you for the response. FYI, https://en.wikipedia.org/wiki/EPUB

Do you know of ANY eBook format that Corona SDK has support for, whether or not a plugin?

A quick read through that I see couple of hiccups, but I also don’t see things as being horribly impossible.

EPUB is basically HTML and some XML. There is an XML parser in our Business App sample. It’s not perfect, but it will work in many cases. HTML is basically XML, so it should be able to parse an HTML document into a Lua table.

It seems to support several image formats. Corona will support JPEG and PNG. There is a plugin to handle GIF in the marketplace and we have the Nano SVG plugin to attempt to handle the SVG requirements. However the Nano SVG plugin only has limited support for some SVG file.

Where you will run into some potential headaches, is the HTML side. It tends to want to support CSS (and maybe JavaScript) and you can’t do HTML style text with display.newText(). But this is something where you could write the HTML, CSS and any JS files out to your local storage and have a native.newWebView() show the content.

Rob

@Rob, ah, excellent info. Thank you :slight_smile:

Hi Troy.

I’m unaware of any plugins to process these files. We certainly don’t have any internal API’s to process them. EPUB probably has a standardized format. There may be a Lua library out there that can help. I would suggest heading to Google or the search engine of your choice and see what you can find.

You could also post a job request to get a community developer to build a plugin if there are some standard C++/iOS or Android SDK’s that could be incorporated within reason.

But since I don’t know what the format is about, if it’s just text and images, it’s likely possible, but if those formats contain any interactivity, the complexity of such a plugin would be considerably more difficult.

Rob

@Rob, thank you for the response. FYI, https://en.wikipedia.org/wiki/EPUB

Do you know of ANY eBook format that Corona SDK has support for, whether or not a plugin?

A quick read through that I see couple of hiccups, but I also don’t see things as being horribly impossible.

EPUB is basically HTML and some XML. There is an XML parser in our Business App sample. It’s not perfect, but it will work in many cases. HTML is basically XML, so it should be able to parse an HTML document into a Lua table.

It seems to support several image formats. Corona will support JPEG and PNG. There is a plugin to handle GIF in the marketplace and we have the Nano SVG plugin to attempt to handle the SVG requirements. However the Nano SVG plugin only has limited support for some SVG file.

Where you will run into some potential headaches, is the HTML side. It tends to want to support CSS (and maybe JavaScript) and you can’t do HTML style text with display.newText(). But this is something where you could write the HTML, CSS and any JS files out to your local storage and have a native.newWebView() show the content.

Rob

@Rob, ah, excellent info. Thank you :slight_smile:

My code could be adapted to show ebooks. It reads XML files, and it can output HTML styled text.

2 Likes

I know it’s an old thread, but these days I’ve had the same “problem” and solved it using a webview and js library: “epub.js”:

Just a little example:
main.lua:

local function webListener( event )
    if event.url then
        print( "You are visiting: " .. event.url )
    end
  
    if event.type then
        print( "The event.type is " .. event.type ) -- print the type of request
    end
  
    if event.errorCode then
        native.showAlert( "Error!", event.errorMessage, { "OK" } )
    end
end

local webView = native.newWebView( display.contentCenterX, display.contentCenterY, 320, display.contentHeight )
webView:request( "html/hello.html", system.ResourceDirectory )
webView:addEventListener( "urlRequest", webListener )

index.html:

<!DOCTYPE html>
<html>
    <head>
        <script src="./jszip.min.js"></script>
        <script src="./epub.min.js"></script>
        <link rel="stylesheet" type="text/css" href="examples.css">
        <style type="text/css">
        .epub-container
        {
            min-width: 320px;
            margin: 0 auto;
            position: relative;
        }

        .epub-container .epub-view > iframe 
        {
            background: white;
            box-shadow: 0 0 4px #ccc;
        }
        </style>
    </head>
<body>
  <div id="viewer"></div>
  <script>
    var currentSectionIndex = 8;
    var book = ePub("./alice.epub", {});
    var rendition = book.renderTo(document.body, {
        manager: "continuous",
        flow: "scrolled",
        width: "60%"
      });
    var displayed = rendition.display();

    displayed.then(function(renderer){});

    book.loaded.navigation.then(function(toc){});
  </script>
</body>
</html>

The zip with all assets, here:

Hi michelangelog
thanks for sharing, I will try your zip!