Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compress to .epub format in java

i have 2 folders(meta-inf,oebpf) and 1 file(mimetype) i wish to convert it to epub format. I am using java.util.zip.ZipEntry, java.util.zip.ZipOutputStream to compress to .epub but i am unable to read the files. But whin i compress it using 7zip and rename it i can use it.

my mimetype file only contains "application/epub+zip". but in wiki it says to add some more text http://en.wikipedia.org/wiki/EPub#Open_Container_Format_2.0.1

is there a jar file for compressing to epub? or else is there something i should do.

like image 932
user3111030 Avatar asked Dec 06 '25 05:12

user3111030


1 Answers

You can try this library : https://github.com/psiegman/epublib

It is specially designed for manipulating epub files.

epublib screenshot

Sample code :

// Create new Book
Book book = new Book();

// In metadata, set the title and author
Metadata metadata = book.getMetadata();
metadata.addTitle("Epublib test book 1");
metadata.addAuthor(new Author("Joe", "Tester"));

// Add chapter 1
book.addSection(
     "Chapter 1", //
     getResource("/book1/chapter1.html", "chapter1.html") //
);

// Add chapter N
// ...

// Write the Book as Epub
EpubWriter epubWriter = new EpubWriter();
epubWriter.write(book, new FileOutputStream("my_first_book1.epub"));

Source : Creating an ebook programmatically

like image 113
Stephan Avatar answered Dec 08 '25 18:12

Stephan