Last Modified 2019.10.9

How to make EPUB ebook

Getting Started

Create a directory for the EPUB.

EPUB Directory
MyFirstBook (ROOT Directory)
├── mimetype
├── META-INF
│    └── container.xml 
└── OEBPS 
    ├── content.opf
    ├── toc.ncx
    ├── css
    |    └── epub.css
    ├── images
    |    └── cover.jpg
    └── xhtml
         ├── cover.xhtml
         ├── preface.xhtml
         ├── ch01.xhtml
         └── ch02.xhtml

Create files in the directory above.

mimetype
application/epub+zip
container.xml
<?xml version="1.0" encoding="UTF-8"?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
    <rootfiles>
        <rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>
   </rootfiles>
</container>

Run the following Java program:

MakeUUID.java
import java.util.UUID;
public class MakeUUID {
	public static void main(String[] args) {
		UUID uuid = UUID.randomUUID();
		System.out.println(uuid);
	}
}
C:\ Command Prompt
C:\Users> javac MakeUUID.java

C:\Users> java MakeUUID
b5fc6c97-5eeb-44c5-af36-87843d9db1fc
content.opf
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId" version="2.0">
	<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
		<dc:identifier id="BookId" opf:scheme="UUID">urn:uuid:b5fc6c97-5eeb-44c5-af36-87843d9db1fc</dc:identifier>
		<dc:title>My First Book</dc:title>
		<dc:creator opf:role="aut">John Doe</dc:creator>
		<dc:language>en</dc:language>
		<dc:date opf:event="modification">2019-10-09</dc:date>
		<dc:publisher>ZZ Books</dc:publisher>
		<meta name="cover" content="cover-img" />
	</metadata>
	<manifest>
		<item href="toc.ncx" id="ncx" media-type="application/x-dtbncx+xml" />
		<item href="css/epub.css" id="epub.css" media-type="text/css"/>
		<item href="images/cover.jpg" id="cover-img" media-type="image/jpeg"/>
		<item href="xhtml/cover.xhtml" id="cover.xhtml" media-type="application/xhtml+xml"/>
		<item href="xhtml/preface.xhtml" id="preface.xhtml" media-type="application/xhtml+xml"/>
  		<item href="xhtml/ch01.xhtml" id="ch01.xhtml" media-type="application/xhtml+xml"/>
  		<item href="xhtml/ch02.xhtml" id="ch02.xhtml" media-type="application/xhtml+xml"/>
	</manifest>
	<spine toc="ncx">
		<itemref idref="cover.xhtml" linear="no"/>
		<itemref idref="preface.xhtml"/>
		<itemref idref="ch01.xhtml"/>
		<itemref idref="ch02.xhtml"/>
	</spine>
</package>
toc.ncx
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
 "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
	<head>
		<meta content="urn:uuid:b5fc6c97-5eeb-44c5-af36-87843d9db1fc" name="dtb:uid" />
	</head>
	<docTitle>
		<text>My First Book</text>
	</docTitle>
	<navMap>
		<navPoint id="navPoint-1" playOrder="1">
			<navLabel>
				<text>Chapter 1</text>
			</navLabel>
			<content src="xhtml/ch01.xhtml"/>
		</navPoint>
		<navPoint id="navPoint-2" playOrder="2">
			<navLabel>
				<text>Chapter 2</text>
			</navLabel>
			<content src="xhtml/ch02.xhtml"/>
		</navPoint>
	</navMap>
</ncx>
epub.css
@charset "UTF-8";
html, body {
    font-family: sans-serif;
    font-size: 1em;
    margin: 0;
    padding: 0;
}
h1 {
    font-size: 2em;
}
p {
    line-height: 1.4;
    font-size: 0.9em;
}
cover.jpg

cover.jpg 1524 x 2339

cover.xhtml
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Cover</title>
</head>

<body>
  <div style="text-align: center; padding: 0pt; margin: 0pt;">
    <img src="../images/cover.jpg" alt="Cover" />
  </div>
</body>
</html>
preface.xhtml
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" 
    xml:lang="en" xmlns:xml="http://www.w3.org/XML/1998/namespace">
<head>
  <title>Preface</title>
</head>

<body>
  <p><strong>My First Book</strong></p>
  <p>Author : John Doe</p>
  <p>Publisher : ZZ Books</p>
  <p>Address : NYC</p>
  <p>Telephone : 000-0000-0000</p>
  <p>Registration Number : 0000-000000</p>
  <p>Published Date : 10/9/2019</p>
  <p>Price : 9.9</p>
  <p>ISBN : 000-00-000000-0-0</p>
  <p>E-mail : john@doe.org</p>
</body>
</html>
ch01.xhtml
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" 
    xml:lang="en" xmlns:xml="http://www.w3.org/XML/1998/namespace">
<head>
<title>Chapter 1</title>
<link href="../css/epub.css" rel="stylesheet" type="text/css" />
</head>

<body>

<h1>Chapter 1</h1>

<p>
A B C D...
</p>

</body>
</html>
ch02.xhtml
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" 
    xml:lang="en" xmlns:xml="http://www.w3.org/XML/1998/namespace">
<head>
<title>Chapter 2</title>
<link href="../css/epub.css" rel="stylesheet" type="text/css" />
</head>

<body>

<h1>Chapter 2</h1>

<p>
E F G H...
</p>

</body>
</html>

Create EPUB file

You need to install Info-ZIP's zip.exe in your windows.
Download zip.exe from http://stahlworks.com/dev/index.php?tool=zipunzip. and copy it to C:\Windows.

info-zip's zip.exe

Move to root directory and run the followings:

C:\ Command Prompt
zip -0Xq MyFirstBook.epub mimetype

zip -Xr9Dq MyFirstBook.epub META-INF OEBPS

Check EPUB file

Download epubcheck-4.1.1.zip from https://github.com/w3c/epubcheck/releases/tag/v4.1.1.
Unzip and move the directory to where you want.

Check for errors by running the following at the command prompt:

C:\ Command Prompt
java -jar C:/epubcheck-4.1.1/epubcheck.jar C:/Users/john/MyFirstBook/MyFirstBook.epub

Test

When MyFirstBook.epub is moved to iPad via iTunes, it is registered with the iPad's iBooks.
iTunes - Books
iBooks