cyrilis / epub-gen Goto Github PK
View Code? Open in Web Editor NEWGenerate EPUB books from HTML with simple API in Node.js.
Generate EPUB books from HTML with simple API in Node.js.
Hi Guys,
Thanks for producing this package.
I'm trying to run this under Grunt, as part of an automated publication platform, but getting no output generated. Specifically:
If I step into the node-modules/epub-gen folder and run npm test, I get all the console messages (right through to 'Done') and good output generated.
I have logged cwd, option.output and the archive and output (fs) objects all the way through good (npm) and bad (grunt) runs, and there is no difference. :(
I have tried it on Windows and Ubuntu with exactly the same results.
Have to say, I'm stumped.
Any ideas?
Right now, the img mimetype is being looked up using the url. It would be best to look at the contentType header if it set.
Options such as allowing input of baseURL would be great too.
I am trying to make a comic epub out of scanned pages. A chapter consists of many images acting as one page. I have tried to display them like so:
<img src="file:///path/to.file1" /><img src="file:///path/to.file2" /><img src=...
or:
<img src="file:///path/to.file1" /><br />
<img src="file:///path/to.file2" /><br />
<img src=...
But somehow only the code until and including the first image makes it into the epub file.
Hi all!
Just firing up this issue, as a note to improve the guide
part of OPF template for EPUB 2, and to use landmarks
for EPUB 3, as the previous is deprecated. 😉
More info about OPF guide
section here http://www.idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.6 and here http://www.idpf.org/epub/30/spec/epub30-publications.html#sec-guide-elem.
The cheerio version you are using throws some Warns about how CSSselect and CSSwhat are deprecated and to use css-select and css-what. This is an issue in the cheerio version in the package.json file. You should update the version of cheerio being used.
Hi all,
So something has been crossing my mind over and over... at the time the work on this lib began (2015) the JS ecosystem was quite different from nowadays, and within that context I understand the benefits that CoffeeScript brought, namely, class syntax, arrow functions of sorts, and many others.
But given the latest advances of JS, namely with ES6, Promises and all, and I ponder if it wasn't beneficial from a maintenance standpoint to consider to migrate to ES6 or TypeScript?
I focus on the maintenance standpoint for two main reasons:
Personally, I find the usage of CoffeeScript at this point to be more cumbersome (and make the code harder to read) than not, and between the two proposals above I'm still leaning to ES6 at this point, basically for the sake of simplicity. (We can always move on to TypeScript if we strongly feel that need later on.)
Thoughts? @cyrilis?
The process randomly stop when downloading lots of images.
Reproduction steps:
CSS was a bit off and content seems to be missing from one of the reader. Showing different pub. version on different reader. Any way to make this consistent on all readers.
Hey, thank you for this neat library. While it works perfectly locally, I seem to have trouble generating epub file when my application is deployed to Heroku.
It seems to always generate the following error code:
Generating Template Files.....
Downloading Images...
Making Cover...
Generating Epub Files...
Zipping temp dir to archive/test.epub
events.js:183
throw er; // Unhandled 'error' event
^
Here's the little snippet that I used:
app.post("/epub", (req, res) => {
let epubURL = req.body.url;
let epubTitle = req.body.title;
let epubAuthor = req.body.author;
let epubSummary = req.body.summary;
let epubContent = req.body.content;
const fileName = `archive/${epubTitle}.epub`;
const option = {
title: epubTitle,
author: epubAuthor,
content: [{ data: epubSummary }, { data: epubContent }]
};
new Epub(option, fileName).promise
.then(() => {
console.log("[#] Success => Id: ", epubURL, "\n");
const file = __dirname + `/${fileName}`;
res.download(file);
})
.catch(err => {
console.log(err);
});
});
Any help would be appreciated.
Thanks to author, I made a daemon thanks to the epub-gen, but it could hangs forever frequently when downloading images with pool network connection condition by await (new Epub(option, path).promise).
With quick browsing to related code, epub-gen seems missing hard timeout when piping streams, could you please solving it author?
So, bumped into this issue, when you have a book with no images, it throws a warning complaining about the images directory being empty, as such:
We need to make this directory creation dependent of having images or not - perhaps move the create dir code to the download images method or so.
Anyway, putting this in as a note.
Hi @cyrilis,
I've been using epub-gen
to generate EPUBs for a project and I ran into some issues. I wanted to support EPUB 2 (to support a broader range of eBook readers) but for that standard it needs valid XHTML files. The issues I was getting was that, custom fonts weren't rendered in some eBook readers (such iBooks) when I used HTML. Changing that o XHTML, worked flawlessly.
What do you think about updating the lib to use XHTML?
Cheers.
If you pass something that is not a string as a cover option, the epub generation process will hang on the "Making Cover..." step.
{}
as options.cover
.Process returns an error saying that options.cover
must be a string.
Process hangs.
Check the type of the cover
option.
if (!(cover instanceof String) && (typeof cover !== 'string')) {
// handle error
}
When epub-gen
is provided an img
with a src
with a query string, then the image's extension is incorrectly changed to .bin
.
For example:
<img src="http://example.com/image.jpg?w=400">
I believe the bit of the code to blame is here, where the mime
package returns:
mime.lookup("http://example.com/image.jpg") // => "image/jpeg"
mime.lookup("http://example.com/image.jpg?w=400") // => "application/octet-stream"
mime.extension("image/jpeg") // => "jpeg"
mime.extension("application/octet-stream") // => "bin"
We can try to strip the query string at our end, but sometimes query strings are used to contain options for how the image is rendered (a common example being Gravatar).
It would be best if epub-gen
stripped the query string when trying to determine the mediaType
and extension
.
It seems that the verbose flag is not working for some logs or that some logs should depend on this flag. The output below is always showing:
(node:56119) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
[Success] cover image downloaded successfully!
Zipping temp dir to /Users/jlijo/Documents/opensource/obooks/books/sql-pocket-guide,-4th-edition/sql-pocket-guide,-4th-edition.epub
Hi,
It would be nice to see the features that Nodepub has which allows content to be:
a) excluded from the TOC, and
b) also placed before the TOC
(see: https://www.npmjs.com/package/nodepub#addsection--title-content-excludefromcontents-isfrontmatter- )
This could be by flags added to the content config - e.g:
content: [
{
title: "Down the Rabbit Hole",
data: "<p>Alice was beginning to get very tired...</p>"
excludeFromContents: false,
isFrontMatter: false
},
Thx.
Hello,
ePubs generated by this script work wonderfully on iBooks for Mac OS and other e-readers, but...
...the same ePub viewed through Apple's new Books app for iOS does not display the images, instead a placeholder is shown:
The above is from the Alice in Wonderland ePub generated by epub-gen’s own test.js script. I've found the same issue with my own ePubs. The images display fine in iBooks on Mac OS, and other e-readers, but on Apple's Books app for iOS - only a placeholder is shown.
Also, any custom fonts you specify do not work. Again, they work perfectly elsewhere.
I've ran the script to generate an ePub version 2 and 3 - and both have the same issue. My iPhone is fully updated.
Any ideas?
It's possible that this is a stupid question, but I'm getting this error:
zip -q -X -0 book.epub.zip mimetype "zip" not recognized internal or external command
How can I install ZIP for node.js?
Thanks!
Hi..
Thank you for the epub-gen you provided.
Is it possible to not insert video or audio into epub through epub-gen?
Hello,
I am trying to use the EPUB3 provision for footnote popups by adding epub:type="noteref"
to my footnote declarations.
In ibooks this results in the error in the title (screenshot attached).
I can see in your lib that you declare xmlns:epub=”http://www.idpf.org/2007/ops”
which should make iBooks respect the epub namespace. I've inspected the epub itself and found the markup to indeed include xmlns:epub=http://www.idpf.org/2007/ops
.
I did notice that http://www.idpf.org/2007/ops
gives a 404. If this is an issue the link in your code should be update to whatever is the current live link.
I am using version 0.0.17 with { version: 3 }
.
If you have any idea how to debug this it would be most welcome.
I have chapter number. So I wanna remove the index number. Tks
Whenever an EPUB is generated, the zip command spits out a lot of information to the console.
For example:
adding: mimetype (stored 0%)
adding: META-INF/ (stored 0%)
adding: META-INF/container.xml (deflated 30%)
adding: OEBPS/ (stored 0%)
adding: OEBPS/<each chapter>.html (deflated 62%)
When generating multiple EPUB files, it would be beneficial if this output was suppressed.
I noticed that while apps like iBooks respect the cover in the meta, many eReaders (kobo) show the first page of the epub as the title page.
What this results in is the table of contents showing as the book thumbnail.
Is this a known issue?
I'm happy to do a PR for this functionality.
Hi guys,
From your documentation I can see that it is possible to specify a template to use when generating the OPF and TOC files. Any reason why it can't be made possible, please, to do the same for the main xhtml content?
Thx.
I am trying to make a comic epub out of scanned pages. To make sure the image covers the whole page i tested the following code as chapter data:
<div style="
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-repeat: no-repeat;
background-position: center;
background-size: contain;
background-image: url(file://inserting/my/file.here);
">
</div>
This however does only work since the file is fetched from the same location by the eBook reader, a quick look into the code reveals that the URL has not been changed and the file was not added.
Hello,
I'm creating a desktop app that is built on Electron with AngularJS. Before building as a production app, this module works as intended, amazing work. But after packaging it into a release build, it gives the following error: Error: ENOTDIR, not a directory
.
This is probably some incompatibility with angular or something and I'd like some help fixing this bug.
The download path provided is:
let option = {
title: novel.info.name,
author: novel.info.author,
cover: novel.info.cover,
content: chapters
};
new epubGen(option, "A:\Downloads\My new book.epub");
The issue seems to originate at EPub.generateTempFile (C:\resources\app.asar\node_modules\epub-gen\lib\index.js:234)
:
generateTempFile() {
var base, generateDefer, htmlTocPath, ncxTocPath, opfPath, self;
generateDefer = new Q.defer();
self = this;
if (!fs.existsSync(this.options.tempDir)) {
fs.mkdirSync(this.options.tempDir);
}
fs.mkdirSync(this.uuid); <=========================== ERROR HERE
fs.mkdirSync(path.resolve(this.uuid, "./OEBPS"));
...
I was wondering what uuid is for and if it could lead to fixing the bug.
Kind Regards,
dr-nyt.
Hello,
So, another topic for discussion.
For some time now, I have felt the need to have more robust tests, a more robust test coverage and test workflow for this lib, because I think this will also help this lib to become more robust, reliable.
I don't have a strong opinion on the test stack – so I'm open to comments –, perhaps we could start setting up some groundwork using Mocha, and take it from there, or so.
Thoughts? @cyrilis?
PS: Perhaps we could bundle this improvement with #49 and #56, and, with a more robust lib, start discussing future 0.1/0.x/1.0(?) release roadmaps? Does that makes sense?
I find that the epub book works fine in ibooks osx.
But if I transfer this book to ipad by Airdrop and open it with ibooks App, the images all gone.
I try unzip the epub, there are nothing image files.
This is a nice lib, and most options cam be easily defined in a command line.
epub-gen
could be a nice CLI tool for epub users.
I noticed that there is a tempDir
option that you can use to specify a place to put temporary files used by the script.
Line 73 in 1a14d7b
It would be useful to refer to it in the README.
I'm currently using this to rapidly generate ePub files and I've noticed that the metadata somehow becomes polluted.
If I open a generated ePub in Calibre (or any ePub reader/editor), and look at the metadata, the IDs field shows something like this:
urn:urn:uuid:<PROJECT DIRECTORY>/node_modules/epub-gen/tempDir/246c4f08-e94f-4377-a197-a3fcca958615
Having the folder structure of the project exposed isn't desirable, it would be nice if it showed only the UUID.
Is it possible for the module to return a stream, in addition to a promise?
I'm trying to add custom hyperlinks by ids, but my hyperlinks to ids don't work. I converted the epub file to html and I see that all ids are converted incrementally to calibre_link0, calibre_link1 how do I prevent this and keep my own ids?
I want to do this because, I want to create a table of contents page and set links to specific parts of the book.
Hi all!
That's a good practice to (at least) tag the release we do on npmjs.org here on Github (https://help.github.com/articles/about-releases). If we want to go further we can document it here too (with a changelog, breaking changes, etc). And perhaps try to stick to semver.
What do you think @cyrilis?
Cheers!
Hi,
How about the ability to specify a filename for each content item, e.g.:
content: [
{
title: "Down the Rabbit Hole",
data: "<p>Alice was beginning to get very tired...</p>",
filename: "chapter2"
}
Why? Because its very hard to construct links in the markup that point to other content if you do not know the relevant filename.
(I know, I can work it out from counting the place in the content array and concatenating the title, but that doesn't seem very robust)
Thx.
Hey, I was wondering if it is possible to make a table of contents with multiple levels. I want to make something like:
Could not find any information on this in the docs so it would be appreciated if someone could point me to the right direction.
Thanks
Is it possible to convert generated epub file into html?
If so, Please tell me the way to convert it back into the html.
A common practices for tech people and also very easy for non tech, can help who wants to build an e-book.
if the html's image src attribute is relative path.(the image file exists relative to html file). in this case, the image won't be included by fs copy
If I understand correctly EPUB3 has js support in the spec. Do you plan to allow custom js the same way you have css?
Should be relatively straightforward.
I'm happy to do a pull request if you don't have the time.
Love the project, would be great if this would work in Meteorjs
what format of epub will this create ? fixed layout or reflowable layout ?
thank you
Hello,
Following up on @jamesporter #38, I had this question for a while: should it really be responsibility of the lib to be concerned with the data the lib users add on each content, namely on cleaning up/encoding content.data
?
In the past there was an effort to make the lib produce valid version 2 and 3 EPUBs, but I feel that concern should only be present in the parts directly to do with the lib, and should be the responsibility of the lib user to provide valid EPUB 2/3 XHTML for their added contents.
This way the issue @jamesporter raised on #38 would not occur too.
So, I would vote to remove this verification/cleanup/encoding from the lib all together. I can still admit the warning about unsupported tags, but even so, I think it should warn but not alter the content user added to its EPUB.
@cyrilis @jamesporter thoughts?
epub-gen
fails to render an ePub with an arbitrarily long chapter title. This is because the chapter titles gets turned into a slug, and this slug exceeds the system's maximum for path length.
A simple fix for this would be to truncate titles to a shorter length. If this is done, it would be nice to feed back to the consumer what these slugs are (ie as the resolution of the Promise
). This is especially useful when - for example - trying to construct your own custom table of contents.
Mimetype file is always empty for the generated epub. Excatly this means the file is there in the epub archive but the file is 0 bytes in size and does not have the application/epub+zip string in it.
Even the verbose
option is set to false
it still logs to console.
According to the documentation any local image with file:// appended should be loaded into the epub. Likewise remote http and https links should be included.
The module does not do this but leaves the original img src=""
intact. This means that images are either 1) loaded through the internet or 2) not portable.
Is this expected behaviour (in which case the readme should be modified) or is this a bug (in which case the images need to be imported and added to the manifest)?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.