Coder Social home page Coder Social logo

epub-to-text's Introduction

EPUBToText

EPUBToText is a node.js module to convert EPUB files to plain text chapters.

Usage

Processing content

To get the chapters as strings:

var epubToText = new EPUBToText;
epubToText.extract('epub_file.epub', (err, txt, n) => {
  // txt is the plain text version of chapter number n
})

If you need to know how many chapters are in the EPUB file, you can do:

var epubToText = new EPUBToText;
epubToText.extract('epub_file.epub', (err, txt, n) => {
  // txt is the plain text version of chapter number n
}, (err, N) => {
  // N is the number of chapters
})

You can also get some metadata about each chapter. The title information may or may not be available, depending on the EPUB structure (the parser looks for the title in EPUB navMap if there is one, otherwise tries to get it directly form the HTML, looking for the first <title> or <h1> tag).

var epubToText = new EPUBToText;
epubToText.extract('epub_file.epub', (err, txt, n, meta) => {
  // meta.id is the chapter internal id
  // meta.title contains a string that hopefully is the title name, or is empty
  // meta.excerpt contains a 250 characters string from the chapter content
  // meta.size is the size of the chapter, in number of characters
  // meta.sequence_number is the position of the chapter in the book sequence
}, (err, N) => {
  // N is the number of chapters
})

Writing to disk

To write the chapters to disk:

var epubToText = new EPUBToText;
epubToText.extractTo('epub_file.epub', 'full_path_to_dest_folder', (err) => {
  // files are in folder, name according to the following convention:
  //   sequence number + original epub file name + .txt
})

epub-to-text's People

Contributors

christianroy avatar

Stargazers

 avatar  avatar  avatar Maltin.R avatar  avatar  avatar Haoye Wang avatar raffaele messuti avatar Daniel Weck avatar Danny Avila avatar Mark Bruckert avatar Ryan avatar Astrydax avatar  avatar Seth Miller avatar Slava Lavrov avatar  avatar Sam Alloing avatar

Watchers

Sam Alloing avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.