Can I do this conversion with any programming language or library?
-
1Did you wind up settling on a process? Looking for a PHP solution myself. – Saiboogu Dec 24 '10 at 13:50
-
I think you are interested in this: https://github.com/Grandt/PHPePub – Jerry Jacobs May 06 '12 at 22:10
-
After try different programs, I think this is much better: http://www.juliansmart.com/ecub Though it is not open source. – Sam Liao Mar 24 '11 at 14:55
7 Answers
The short answer is yes, it can be done in any programming language.
Basic steps:
- Convert your HTML to XHTML (+ CSS). This can be done in your program or through an XSLT file.
- Copy your files (XHTML, CSS, any images and fonts) into a directory structure that follows the format.
- Zip the directory structure up and name the archive with a ".epub" extension.
Some web sites to help you get started:
- A good tutorial for what's in an epub file (and how to create one yourself) can be found here: http://www.jedisaber.com/eBooks/Introduction.shtml. I used this to get started myself.
- Specs for the .epub standard are here: http://www.idpf.org/
- A validator for .epubs can be downloaded from here: https://github.com/IDPF/epubcheck
June 2015 Note: The epubcheck validator has moved from google code to GitHub; note the new URL.

- 2,897
- 3
- 31
- 42
Calibre supports a wide variety of input formats, including HTML, and a wide variety of output formats, including EPUB, but it's not "a programming language or library". Are there specific reasons you desire a programming-based approach rather than a free-standing tool? If so, maybe Python and ebookmaker.py, for example, could help you.

- 218,210
- 55
- 464
- 476

- 854,459
- 170
- 1,222
- 1,395
-
1
-
6
-
Agree..I've used it from the command line myself, integrated with some bash scripting. Good for small-ish books. My larger pubs created by Calibre never pass validation. – Paulb Nov 09 '13 at 18:35
-
-
2
A late reply, but I found the Python 3-based ebookmaker to be of value, at least after I contributed a pull request to remove a UTF-8 BOM. One problem with it appears to be that it uses brittle regular expressions to parse HTML, but I guess I'll have to report it there.

- 1
- 1

- 4,380
- 3
- 23
- 27
I just started to implement such a tool in Java (OpenJDK compatible): html2epub. In order to get rid of manually editing the config file, I'll probably start a separate tool to generate the config file from any given directory (however, it would still be necessary to determine the order of the XHTMLs in the EPUB - for non-programmatical use, developing a GUI helper tool could be considered, for a fully flexible programmatical solution, I haven't come up with an idea yet). Before that, I implemented shell script based converters for custom XML input (hag2epub tools) - in case you're interested, I would probably port them to XHTML input (with a config file for the EPUB metadata or obtaining metadata from the topmost index.html of a directory, if existing).

- 77
- 5
-
if you would license it under Apache 2.0 it would be way to go for many people, as its under AGPL i cannot use it. its pitty :( – To Kra Oct 14 '15 at 07:00
-
Could you please tell me how the AGPL could possibly blocking you from using it? – skreutzer Oct 19 '15 at 22:58
-
-
That's simply not true. To the contrary: being usable in a commercial context or as a commercial product is an important right free software grants its users, so does the AGPL too. – skreutzer Oct 22 '15 at 20:31
Here's pdf to epub, I know that's not what you're after, but it's a start.
The calibre package may have what you want

- 1,384
- 1
- 17
- 29
I am using the following library from Aspose - http://www.aspose.com/categories/.net-components/aspose.words-for-.net/default.aspx
In just two lines of code I am able to do html to epub conversions. Using this currently in a production system.
Document doc = new Document(_sourceFilePath);
doc.Save(_destinationFilePath, SaveFormat.Epub);

- 6,686
- 4
- 25
- 22
I have the same issue previously, necause I want to read some webpage content offline on my iPad. I have no idea and I am not a computer savvy. There are calibre or stanza blabla....
But for me they are just formats converters and I need a ePub book creator which will allows me to combine many desired documents together to read. Then I found a bookish html to ePub converter, I save the html page from web then convert with it. It's a quite good tool for me now.

- 24
- 1