forked from psiegman/epublib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
50 lines (34 loc) · 2.03 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Epublib is a java library for creating epub files.
Its focus is on creating epubs from existing html files using the command line or a java program.
Another intended use is to generate documentation as part of a build process.
text added for git testing
Writing epubs works pretty well, reading them has recently started to work.
a small change
Right now it's useful in 2 cases:
Creating an epub programmatically or converting a bunch of html's to an epub from the command-line.
Creating an epub programmatically
=================================
// Create new Book
Book book = new Book();
// Set the title
book.getMetadata().addTitle("Epublib test book 1");
// Add an Author
book.getMetadata().addAuthor(new Author("Joe", "Tester"));
// Set cover image
book.getMetadata().setCoverImage(new InputStreamResource(Simple1.class.getResourceAsStream("/book1/test_cover.png"), "cover.png"));
// Add Chapter 1
book.addResourceAsSection("Introduction", new InputStreamResource(Simple1.class.getResourceAsStream("/book1/chapter1.html"), "chapter1.html"));
// Add css file
book.getResources().add(new InputStreamResource(Simple1.class.getResourceAsStream("/book1/book1.css"), "book1.css"));
// Add Chapter 2
Section chapter2 = book.addResourceAsSection("Second Chapter", new InputStreamResource(Simple1.class.getResourceAsStream("/book1/chapter2.html"), "chapter2.html"));
// Add image used by Chapter 2
book.getResources().add(new InputStreamResource(Simple1.class.getResourceAsStream("/book1/flowers_320x240.jpg"), "flowers.jpg"));
// Add Chapter2, Section 1
book.addResourceAsSubSection(chapter2, "Chapter 2, section 1", new InputStreamResource(Simple1.class.getResourceAsStream("/book1/chapter2_1.html"), "chapter2_1.html"));
// Add Chapter 3
book.addResourceAsSection("Conclusion", new InputStreamResource(Simple1.class.getResourceAsStream("/book1/chapter3.html"), "chapter3.html"));
// Create EpubWriter
EpubWriter epubWriter = new EpubWriter();
// Write the Book as Epub
epubWriter.write(book, new FileOutputStream("test1_book1.epub"));