25.09.2022 Views

How to Create an EPUB File From HTML and XML

How to Create an EPUB File From HTML and XML

How to Create an EPUB File From HTML and XML

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Science, Tech, Math › Computer Science<br />

<strong>How</strong> <strong>to</strong> <strong>Create</strong> <strong>an</strong> <strong>EPUB</strong><br />

<strong>File</strong> <strong>From</strong> <strong>HTML</strong> <strong>an</strong>d <strong>XML</strong><br />

<strong>Create</strong> <strong>an</strong> <strong>EPUB</strong><br />

steps<br />

le from <strong>HTML</strong> <strong>an</strong>d <strong>XML</strong> in a few easy<br />

SHARE FLIP EMAIL<br />

ByJennifer Kyrnin<br />

Updated on February 28, 2021<br />

What <strong>to</strong> Know<br />

Build <strong>HTML</strong> > create a MIME file > cover<br />

image > title page <strong>an</strong>d table of contents ><br />

container <strong>XML</strong> file > contents list.<br />

Test your book <strong>to</strong> check for issues.<br />

This article explains how <strong>to</strong> create <strong>an</strong> <strong>EPUB</strong> file from<br />

<strong>HTML</strong> <strong>an</strong>d <strong>XML</strong>.


Pho<strong>to</strong> © Letizia Le Fur / Getty Images<br />

<strong>How</strong> <strong>to</strong> <strong>Create</strong> <strong>an</strong> <strong>EPUB</strong> <strong>File</strong> <strong>From</strong> <strong>HTML</strong> <strong>an</strong>d<br />

<strong>XML</strong><br />

An <strong>EPUB</strong> file is the other type of ebook file that is popular.<br />

If you are pl<strong>an</strong>ning on writing or publishing <strong>an</strong> ebook, you<br />

should save your <strong>HTML</strong> as a Mobipocket file, <strong>an</strong>d also as<br />

<strong>an</strong> <strong>EPUB</strong>. In some ways, <strong>an</strong> epub file is a lot easier <strong>to</strong> build<br />

th<strong>an</strong> a Mobi file. Since <strong>EPUB</strong> is based on <strong>XML</strong>, you simply<br />

need <strong>to</strong> create your <strong>XML</strong> files, collect them <strong>to</strong>gether, <strong>an</strong>d<br />

call it <strong>an</strong> epub.<br />

These are the steps you should take <strong>to</strong> create <strong>an</strong> epub file:


These are the steps you should take <strong>to</strong> create <strong>an</strong> epub file:<br />

1. Build your <strong>HTML</strong>. Your book is written in<br />

<strong>HTML</strong>, with CSS for styling. But, it's not just<br />

<strong>HTML</strong>, it's X<strong>HTML</strong>. So, if you don't normally write<br />

in X<strong>HTML</strong> (closing your elements, using quotes<br />

around all attributes, <strong>an</strong>d so on) you will need <strong>to</strong><br />

convert your <strong>HTML</strong> <strong>to</strong> X<strong>HTML</strong>. You c<strong>an</strong> use one or<br />

more X<strong>HTML</strong> files for your books. Most people<br />

separate the chapters in<strong>to</strong> separate X<strong>HTML</strong> files.<br />

Once you have all the X<strong>HTML</strong> files, put them in a<br />

folder all <strong>to</strong>gether.<br />

2. <strong>Create</strong> a MIME Type <strong>File</strong>. In your text edi<strong>to</strong>r,<br />

open a new document <strong>an</strong>d type:<br />

application/epub+zip<br />

Save the file as “mimetype” without <strong>an</strong>y extension.<br />

Place that file in the folder with your X<strong>HTML</strong> files.<br />

3. Add your style sheets. You should create two<br />

style sheets for your book one for the pages called<br />

page_styles.css<br />

:<br />

@page {


4.<br />

5.<br />

margin-bot<strong>to</strong>m: 5pt;<br />

margin-<strong>to</strong>p: 5pt<br />

6.<br />

}<br />

7. <strong>Create</strong> one for the book styles called<br />

stylesheet.css<br />

. You c<strong>an</strong> give them other names, you'll just need <strong>to</strong><br />

remember what they are. Save these files in the<br />

same direc<strong>to</strong>ry with your X<strong>HTML</strong> <strong>an</strong>d mimetype<br />

files.<br />

8. Add your cover image. Your cover image should<br />

be a JPG file no more th<strong>an</strong> 64KB. The smaller you<br />

c<strong>an</strong> make it the better, but keep it good looking.<br />

Small images c<strong>an</strong> be very hard <strong>to</strong> read, <strong>an</strong>d the<br />

cover is where you do your marketing of your book.<br />

9. Build your title page. You don't have <strong>to</strong> use the<br />

cover image as your title page, but most people do.<br />

To add your title page, create <strong>an</strong> X<strong>HTML</strong> file called<br />

titlepage.xhtml<br />

Here is <strong>an</strong> example of a title page using SVG for the


image. Ch<strong>an</strong>ge the highlighted part <strong>to</strong> point <strong>to</strong> your<br />

cover image:<br />

10.<br />

Cover<br />

11. Build your "Table of Contents." <strong>Create</strong> a file<br />

called<br />

<strong>to</strong>c.ncx<br />

in your text edi<strong>to</strong>r. This is <strong>an</strong> <strong>XML</strong> file, <strong>an</strong>d it<br />

should point <strong>to</strong> all your <strong>HTML</strong> files in your book.<br />

Here is a sample with two elements in the table of<br />

contents. Ch<strong>an</strong>ge the highlighted parts <strong>to</strong> your<br />

book, <strong>an</strong>d add additional<br />

navPoint<br />

elements for additional sections:<br />

12.<br />

<strong>How</strong> <strong>to</strong> Build a Website<br />

13.<br />

Hosting<br />

14.<br />

Do You Need a Domain Name?<br />

15. Add a container <strong>XML</strong> file. In your text edi<strong>to</strong>r,<br />

fil ll d


create a file called<br />

container.xml<br />

<strong>an</strong>d save it in a sub-direc<strong>to</strong>ry below your <strong>HTML</strong><br />

files. The file should read:<br />

16. <strong>Create</strong> the contents list (<br />

content.opf<br />

). This is the file that explains what your epub book<br />

is. It includes metadata about the book (like the<br />

author, publish date, <strong>an</strong>d genre). Here is a sample,<br />

you should ch<strong>an</strong>ge the parts in yellow <strong>to</strong> reflect<br />

your book:<br />

17.<br />

en<br />

18.<br />

<strong>How</strong> <strong>to</strong> Build a Website<br />

19. Jennifer Kyrnin<br />

20. 0101-01-01T00:00:00+00:00<br />

21. 0c159d12-f5fe-4323-8194-f5c652b89f5c<br />

22. That's all the files you need, they should all be in a<br />

direc<strong>to</strong>ry <strong>to</strong>gether (except for<br />

container.xml


, which goes in a sub-direc<strong>to</strong>ry<br />

META-INF<br />

). We like <strong>to</strong> then go <strong>to</strong> the container direc<strong>to</strong>ry <strong>an</strong>d<br />

make sure it has a name that reflects the title <strong>an</strong>d<br />

author names.<br />

23. Once you have the direc<strong>to</strong>ry of files named how you<br />

w<strong>an</strong>t it you should use a zip file archive program <strong>to</strong><br />

zip the direc<strong>to</strong>ry. My sample direc<strong>to</strong>ry ends up as a<br />

zip file named “<strong>How</strong> <strong>to</strong> Build a Website — Jennifer<br />

Kyrnin.zip”<br />

24. Finally, ch<strong>an</strong>ge the file name extension from<br />

.zip<br />

<strong>to</strong><br />

.epub<br />

. Your operating system may protest, but go ahead<br />

with it. You w<strong>an</strong>t this <strong>to</strong> have <strong>an</strong> epub extension.<br />

25. Lastly, test your book. It's hard <strong>to</strong> get the epub<br />

format correct on the first try, so you should always<br />

test your file. Open it in <strong>an</strong> epub reader like<br />

Calibre. And if it doesn't display correctly, you c<strong>an</strong><br />

use Calibre <strong>to</strong> correct problems


use Calibre <strong>to</strong> correct problems.<br />

Cite this Article<br />

Computer Science<br />

<strong>How</strong> <strong>to</strong> Include Images in Kindle Books<br />

wom<strong>an</strong> reading on a tablet<br />

Computer Science<br />

The Pros <strong>an</strong>d Cons for E-Publishing: <strong>EPUB</strong> vs. PDF<br />

ePUB vs PDF


Computer Science<br />

Delivering Sites <strong>an</strong>d Project <strong>File</strong>s <strong>to</strong> Clients<br />

Delivery person guiding a dolly<br />

stacked with boxes<br />

Computer Science<br />

<strong>How</strong> <strong>to</strong> Build Your First Web Page<br />

Web page design on macbook pro<br />

computer screen on a desk


Computer Science<br />

Common <strong>File</strong> Types <strong>an</strong>d <strong>File</strong> Extensions<br />

<strong>File</strong> folders <strong>an</strong>d lap<strong>to</strong>p on a wooden<br />

desk<br />

Computer Science<br />

Add Images <strong>to</strong> Web Pages Using <strong>HTML</strong><br />

Workers using software <strong>to</strong> calibrate<br />

springs in of ce


Computer Science<br />

Adding Images <strong>to</strong> Your Web Pages<br />

Wom<strong>an</strong> working at computer<br />

Computer Science<br />

Adding .doc or .txt <strong>File</strong>s <strong>to</strong> Websites<br />

Illustration of h<strong>an</strong>d reaching out<br />

with a text document<br />

Computer Science<br />

Convert Your Website <strong>to</strong> <strong>HTML</strong>


<strong>HTML</strong> code for building a web form<br />

Computer Science<br />

<strong>How</strong> <strong>to</strong> Set up Mod_Rewrite<br />

Apache's mod_rewrite Takes Some<br />

Time <strong>to</strong> Learn, But the Payoff Is<br />

Worth It


Computer Science<br />

Tips on <strong>How</strong> <strong>to</strong> Install Apache on Linux<br />

Main components of LINUX<br />

operating system<br />

Computer Science<br />

<strong>Create</strong> a New Web Page Using Notepad<br />

Creating a new folder in Windows


Computer Science<br />

<strong>How</strong> <strong>to</strong> Parse <strong>XML</strong> <strong>File</strong>s in Xcode<br />

Closeup side view of mid 20's blond<br />

black wom<strong>an</strong> doing her software<br />

development project. She's sitting in<br />

front of a desk<strong>to</strong>p computer <strong>an</strong>d<br />

sipping a coffee while working on a<br />

computer.<br />

Computer Science<br />

Underst<strong>an</strong>ding the Index.html Page on a Website<br />

Person browsing the Index page of<br />

/acme


Computer Science<br />

<strong>How</strong> <strong>to</strong> Add Comments in Your <strong>HTML</strong><br />

Illustration of m<strong>an</strong> working on<br />

lap<strong>to</strong>p sitting on lap<strong>to</strong>p with CSS<br />

<strong>HTML</strong> code on screen with code tags<br />

in background<br />

Computer Science<br />

<strong>How</strong> <strong>to</strong> Include <strong>HTML</strong> in M<strong>an</strong>y Documents Using<br />

JavaScript<br />

Software developers solving a<br />

problem.


Follow Us<br />

TRUSTe<br />

Science, Tech, Math<br />

L<strong>an</strong>guages<br />

Hum<strong>an</strong>ities<br />

Resources<br />

About Us<br />

Privacy Policy<br />

Careers<br />

Contact<br />

Advertise<br />

Cookie Policy<br />

Edi<strong>to</strong>rial Guidelines<br />

Terms of Use<br />

California Privacy Notice<br />

ThoughtCo is part of the Dotdash Meredith publishing family.<br />

We've updated our Privacy Policy, which will go in <strong>to</strong> effect on September<br />

1, 2022. Review our Privacy Policy

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!