阅读类网站增加对epub格式的支持

来源:互联网 发布:傲剑丹田升级数据一游 编辑:程序博客网 时间:2024/05/01 03:58

  现在的阅读类网站越来越多,如何添加对一个格式的解析和显示呢?

  本文以epub格式做一个具体的例子。

  1. 安装nodejs环境,详见http://blog.csdn.net/demoshow/article/details/40341363

  2. 下载(https://github.com/futurepress/epub.js/) epub.js,解压到epub.js-master。

     install the project dependences with npm
     npm install

  3.  在目录epub.js-master下运行

    node server.js

  4. 测试结果localhost:8080/reader/dev.html

Getting Started

Get the minified code from the build folder:

<script src="../build/epub.min.js"></script>

If you plan on using compressed (zipped) epubs (any .epub file) include the minified version of zip.js

Also make sure to set EPUBJS.filePath to the directory containing inflate.js

<!-- Zip JS --><script src="/build/libs/zip.min.js"></script>  <script>    EPUBJS.filePath = "../build/libs/";</script>

Setup a element to render to:

<div onclick="Book.prevPage();"></div><div id="area"></div><div onclick="Book.nextPage();"></div>

Create the new ePub, and then render it to that element:

<script>    var Book = ePub("url/to/book/");    Book.renderTo("area");</script>

0 0