By Jeff Friesen

My First Kindle Book: A Case Study

By Jeff Friesen
Help us help you! You'll get a... FREE 6-Month Subscription to SitePoint Premium Plus you'll go in the draw to WIN a new Macbook SitePoint 2017 Survey Yes, let's Do this It only takes 5 min

For several years, I’ve thought about creating and publishing a Kindle book. However, other projects came first and I shelved this idea until recently.

A couple of months ago, I bought my first Kindle e-reader device, which pushed me over the edge into creating my first Kindle book, which I tested on the device and subsequently published on Amazon. I learned much from this project through trial and error, and thought I’d share this experience with you. Perhaps you’ll find it helpful for when you decide to create and publish your first Kindle book.

Find out what to write about

Figuring out the book’s theme was the hardest part in writing my book. I thought about writing fiction, such as a trendy vampire romance like some of Amanda Hocking’s best-selling offerings, but disqualified myself because I don’t have the slightest idea on how vampires romance each other. Then again, perhaps a Shrek-oriented satire of such a romance might prove profitable (and be worth a few laughs).

Because I’m much more interested in technology, a tech book is right up my alley and I decided to focus on creating this kind of book. Furthermore, my experience with the Java language and platform convinced me to target Java.

What kind of Java book should I create? There are many different Java books out there and rehashing the same old “Introducing Java” formula probably wouldn’t attract much interest. I wanted something different and explored Amazon’s website, reading the descriptions and reviews of various Java ebooks.

During my exploration, I entered search keywords Java quiz and received a single search result. I’d finally found an under-developed category to exploit, and decided to write a book that quizzes the reader on Java language concepts.

Write the book

I needed to answer a few questions before I could starting writing: what would be the book’s title, how should I organize the book, and should I adopt a high-level or a low-level approach to writing it?

I decided to call my book The BIG Java Quiz. Also, I avoided the traditional chapter format, which didn’t lend itself to the book I had in mind, essentially a single-chapter book. Instead, I organized the book as follows:

  • cover image page
  • cover page
  • table of contents
  • introduction
  • quiz
  • about page

For the quiz part of the book, I chose a format where I’d present a single question on a screen and present its answer on the following screen. This format prevents distraction from seeing multiple questions on a screen, and provides immediate feedback concerning the answer.

There are two basic approaches to writing a Kindle book: high-level and low-level. The high-level approach involves using a Word processor such as Microsoft Word and a tool such as MobiPocket Creator. The low-level approach involves working directly with HTML, CSS, and using the KindleGen tool. I opted to follow the low-level approach so that I could have complete control over formatting and learn the basic structure of any Kindle book.

PDF-based books
It’s difficult (if not impossible) to create a technical Kindle book with code listings, tables, and other useful features that look great on all Kindle devices. Two reasons for the difficulty: older devices don’t support newer features, and different devices have different screen resolutions, which makes it hard to keep code from wrapping across lines (and looking horrible). Given these limitations, you might consider creating a great-looking PDF-based book, which Kindle supports. However, Amazon doesn’t let you sell PDF-based books on its website, so why bother?

Next, I obtained the Amazon Kindle Publishing Guidelines to learn more about the formatting rules for a Kindle book. I found Chapter 3 “General Formatting Guidelines” to be very helpful.

Finally, I started to write the book by creating a quiz.html file to house the quiz and populating it with questions and answers. Listing 1 presents an excerpt from this file (reformatted for readability).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
<html xmlns="">

<b>True or false:</b> The Java language was developed by Oracle.

<mbp:pagebreak />
<b>Answer:</b> false<br><br>
The Java language was developed by Dr. James Gosling at Sun Microsystems.
Oracle acquired Java as part of its acquisition of Sun Microsystems on 
January 27, 2010.

<mbp:pagebreak />

Java's original name was what?<br><br>

<b>a)</b> Java<br>
<b>b)</b> Oak<br>
<b>c)</b> Project Green<br>
<b>d)</b> Star7

<mbp:pagebreak />
<b>Answer:</b> b

<mbp:pagebreak />

<b>True or false:</b> Java is partly patterned after the C and C++ languages.

<mbp:pagebreak />
<b>Answer:</b> true

<mbp:pagebreak />

<!-- ... -->

<mbp:pagebreak />

Listing 1: Excerpted content from quiz.html.

Listing 1 reveals a very basic format, which I adopted after studying the Guide sample in the file associated with the KindleGen tool.

I left the <head></head> section empty, although I could have inserted a <title> element (whose absence doesn’t seem to have affected the book). If I had planned to use CSS, I probably would have also inserted a <link> element to a stylesheet file.

I decided to code the quiz as an ordered list of alternating true/false and multiple-choice question list items placed in a <div></div> section. I probably could have ignored the division, but might need it in a future version of the quiz.

Each question and answer needs to appear on its own screen. To force the needed page breaks, I used <mbp:pagebreak />, which is a custom HTML tag supported by Amazon.

Create additional book files

The quiz.html file is only one of several files that I needed to create for my book. For example, I also needed to create the book’s cover images and a cover page.

Covering the book

Amazon requires that every book have two cover images: an image to be displayed on Amazon’s website and an image that appears as the first page of the book. Although not mandatory, I also created a cover page that follows the cover image page.

Amazon’s Creating a Catalog/Cover Image page states that a cover image should “have an ideal height/width ratio of 1.6.” Furthermore, the image that appears on the website should “be 1563 pixels on the shortest side and 2500 pixels on the longest side” (for best quality).

I created a cover_big.jpg file with dimensions of 1563 (width) by 2500 (height) for the website. I also created a smaller version (stored in cover.jpg) with dimensions of 500 (width) by 800 (height) to appear inside the book. Figure 1 shows the image.

For best quality, a cover image should have a height-to-width ratio of 1.6.
Figure 1: For best quality, a cover image should have a height-to-width ratio of 1.6.

Although following the cover image with a cover page isn’t mandatory, it’s a good idea to include one. On this page, you present the book title and your name as its author. You can also include a copyright message or any other information that you feel is important. Listing 2 presents the contents of coverpg.html, which describes my book’s cover page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
<html xmlns="">

The <b style="font-size: x-large">BIG</b> Java Quiz<br><br>
Jeff Friesen<br><br><br><br><br><br><br><br><br><br>

Listing 2: A cover page’s content is typically centered.

Including a table of contents

Following the cover page is the table of contents. This HTML file includes links to the various sections in the book. It doesn’t include page numbers because Kindle books are reflowable: changing the font size can cause text to flow over the current screen and onto the next screen. Listing 3 presents my book’s table of contents.

<html xmlns="" xml:lang="en">

p {margin-bottom: 1em; text-align: left}
p.ind {margin-left: 2em;}

<p><a href="intro.html">Introduction</a></p>
<p><a href="quiz.html">Quiz</a></p>
<p><a href="aboutjf.html">About Jeff Friesen</a></p>

Listing 3: The table of contents doesn’t include page numbers.

Listing 3 reveals some basic CSS styling, which I picked up while exploring various Kindle book samples. Essentially, the text is left-aligned, some spacing appears between successive lines, and the text is indented from the left-hand side. I think the result looks nice — I’ll show it to you later in this article.

Crafting an introduction

An introduction typically follows the table of contents and provides the reader with an overview of the book. Because it appears near the book’s beginning, the introduction is likely to appear in Amazon’s “look inside” preview, which potential readers can read to learn more about the book and whether to purchase it. Listing 4 presents my book’s introduction, which is stored in intro.html.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
<html xmlns="">

<i>Java</i> is a language and a platform based on a 
virtual machine and execution environment. The Java 
language offers many language features; the Java 
platform offers a wealth of APIs. There's much to 
learn and the list of language features/APIs grows 
with each new Java release.<br><br>

Perhaps you've been working with Java for some time 
and would like to assess your Java knowledge level. 
To help you with this task, I've developed a 
150-question Java quiz that challenges you on many 
aspects of Java Platform, Standard Edition. This 
quiz focuses on Java SE 1 through Java SE 7.<br><br>

I've organized this Java quiz into interleaved 
true/false and multiple choice categories. To help 
you quickly determine if you've answered a question 
correctly, I've listed the question's answer on the 
page immediately following the question page. I 
hope you find this quiz helpful.

Listing 4: Introducing a book to its readers.

The intro.html file is linked to from the table of contents — see Listing 3.

Creating an about page

I followed the introduction with the quiz (discussed earlier) and followed the quiz with an about page that provides information about me (including contact information). I felt this page would provide proper closure to the book — kind of a conclusion. Listing 5 presents my book’s about page, which is stored in aboutjf.html.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
<html xmlns="">

<center><img src="jeff.png" alt="Jeff Friesen" 
             width="161" height="155"></center><br>

<b>Jeff Friesen</b> is a freelance tutor and software 
developer with an emphasis on Java. Check out my <a 
website to learn more about me.<br><br>

If you have any comments/questions about this quiz or 
would like to see it expanded, let me know by sending 
an email to <a 

Listing 5: Giving the reader some author information.

The aboutjf.html file is linked to from the table of contents — see Listing 3. Also, it references an image file named jeff.png.

Specifying the book’s OPF file

Kindle books are typically created as EPUB (Electronic Publication) documents, which are subsequently converted to Amazon’s own format when uploaded to its self-publishing platform (discussed later). EPUB documents must include an OPF file.

The Open Packaging Format (OPF) file stores the EPUB document’s metadata, file manifest, and linear reading order. Listing 6 presents the contents of my book’s tbjq.opf file — it’s conventional to specify .opf as the file extension.

<?xml version="1.0" ?>

<package version="2.0" xmlns="" unique-identifier="tbjq">

<metadata xmlns:dc="" xmlns:opf="">
<dc:title>The BIG Java Quiz</dc:title>
<dc:identifier id="tbjq" opf:scheme="uuid">urn:uuid:e9d31c40-0cfe-11e3-8ffd-0800200c9a66</dc:identifier>
<dc:creator>Friesen, Jeff</dc:creator>
<dc:publisher>Friesen, Jeff</dc:publisher>
<dc:description>A quiz on the Java language, various APIs, and other aspects of this 
<meta name="cover" content="BookCover" />

<item id="BookCover" media-type="image/jpg" href="cover.jpg"></item>
<item id="cp" media-type="application/xhtml+xml" href="coverpg.html"></item>
<item id="tc" media-type="application/xhtml+xml" href="toc.html"></item>
<item id="intro" media-type="application/xhtml+xml" href="intro.html"></item>
<item id="quiz" media-type="application/xhtml+xml" href="quiz.html"></item>
<item id="aboutjf" media-type="application/xhtml+xml" href="aboutjf.html"></item>
<item id="MyNcx" media-type="application/x-dtbncx+xml" href="toc.ncx"></item>

<spine toc="MyNcx">
<itemref idref="cp"/>
<itemref idref="tc"/>
<itemref idref="intro"/>
<itemref idref="quiz"/>
<itemref idref="aboutjf"/>

<reference type="cover" title="Cover" href="coverpg.html"></reference>
<reference type="toc" title="Table of Contents" href="toc.html"></reference>
<reference type="text" title="Beginning" href="intro.html"></reference>


Listing 6: Providing a book’s metadata, manifest, spine, and guide.

An OPF file’s root element is <package>. This element requires a version attribute that identifies the OPF version to which the document conforms (e.g., 2.0), and a unique-identifier attribute whose value identifies the metadata element providing the book’s identification number.

Nested within <package> are <metadata>, <manifest>, <spine>, and <guide> elements. The first three elements are mandatory; <guide> is optional.

Exploring <metadata>

The <metadata> element provides information about the publication as a whole. It provides this information via a set of elements standardized by the Dublin Core Metadata Initiative (DCMI), which are commonly referred to as Dublin Core.

Of the various Dublin Core metadata elements, EPUB only requires that <title>, <language>, and <identifier> be specified:

  • <title> provides the book’s title (e.g., The BIG Java Quiz).
  • <language> provides the language of the book’s contents in RFC 3066 format or its successors, such as the newer RFC 4646. For example, en identifies English as my book’s language.
  • <identifier> provides a unique identifier for the book, such as its ISBN or a URL. The value of this element’s id attribute should match the value of the <package> element’s unique-identifier attribute. The scheme attribute specifies the unique identifier. I decided to use a universally unique identifier and obtained one via an online tool.

I also specified the <creator>, <publisher>, <date>, <subject>, and <description> Dublin Core metadata elements. Check out Using Dublin Core – The Elements to learn more about them.

The <metadata> element can contain <meta> elements that provide arbitrary data items beyond the data described by Dublin Core (the elements belonging to the dc: XML namespace). Only one such element is needed, to identify the book’s cover image (not the cover image on the Amazon website). Its name attribute must be set to cover; its content attribute must be set to the value of the id attribute for one of the <manifest> element’s nested <item> elements.

Exploring <manifest>

The <manifest> element provides a list of all files that are part of the publication (e.g., HTML files, image files, and style sheets) via its nested <item> elements. I’ve identified every file except for the jeff.png file that’s linked to the about page — I forgot to include jeff.png (whose omission hasn’t caused any problems).

The final <item> element is interesting in that it refers to a file named toc.ncx. You’ll learn more about the NCX file later. For now, note that MyNCX, which is the value of the <item> element’s id attribute, is also the value of the subsequent <spine> element’s toc attribute.

Exploring <spine>

The <spine> element specifies the linear reading order of the document. It accomplishes this task via a sequence of nested <itemref> elements whose idref attributes refer to the document items (e.g., table of contents or introduction) described by the manifest.

I’ve specified that the cover page is to appear first. This page is followed by the table of contents page, which is followed by the introduction, then quiz, and finally about page. If I omitted any of these items from the spine, the missing item would appear (at least in the Kindle Previewer tool, discussed later) at the very end of the book.

Exploring <guide>

The optional <guide> element provides the fundamental structural components of the book via its nested <reference> elements. Examples include cover image and table of contents. Its presence allows Kindles and other e-reading devices to navigate directly to these items (without having to traverse intermediate items).

For example, the Kindle Previewer tool contains a Go to menu for navigating to various parts of the book. Three of the menu items are Table of Contents, Beginning, and Cover. Selecting these menu items should take you to the book’s table of contents page, beginning, and cover.

You can identify an HTML file for the table of contents by specifying a <reference> element whose type attribute is set to toc and whose href attribute identifies the file. Similarly, you can identify an HTML file for the beginning page by specifying a <reference> element whose type attribute is set to text and whose href attribute identifies the file. Kindle Previewer (and the Kindle device on which I tested) appears to ignore the cover <reference> element.

Kindle Previewer and the beginning page
When you open a book in Kindle Previewer, it displays the contents of the HTML file identified as the value of the beginning page <reference> element.

Specifying the book’s NCX file

Although not part of the EPUB specification, an EPUB document typically includes a Navigation Control file for XML (NCX) file, which contains an EPUB document’s hierarchical table of contents, and which was traditionally named toc.ncx (and I’ve adhered to that tradition).

Older Kindles with keyboards process the NCX file to obtain its set of predefined bookmarks (typically for chapters or major sections within chapters). These devices can jump between these presets by using the left and right arrows on the device’s five-way controller. Kindle Touch and Kindle Fire don’t appear to use the NCX file, but it still pays to provide one to support older Kindles.

Listing 7 presents my book’s toc.ncx file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "">
<ncx xmlns="" version="2005-1" xml:lang="en">
<meta name="dtb:uid" content="urn:uuid:e9d31c40-0cfe-11e3-8ffd-0800200c9a66"/>
<meta name="dtb:depth" content="1"/>
<meta name="dtb:totalPageCount" content="0"/>
<meta name="dtb:maxPageNumber" content="0"/>

<docTitle><text>The BIG Java Quiz</text></docTitle>
<docAuthor><text>Friesen, Jeff</text></docAuthor>

<navPoint id="navpoint-1" playOrder="1">
<navLabel><text>Cover Page</text></navLabel>
<content src="coverpg.html"/>

<navPoint id="navpoint-2" playOrder="2">
<navLabel><text>Table of Contents</text></navLabel>
<content src="toc.html"/>

<navPoint id="navpoint-3" playOrder="3">
<content src="intro.html"/>

<navPoint id="navpoint-4" playOrder="4">
<content src="quiz.html"/>

<navPoint id="navpoint-5" playOrder="5">
<navLabel><text>About Jeff Friesen</text></navLabel>
<content src="aboutjf.html"/>

Listing 7: Providing a book’s navigation control information.

An NCX file begins with a <head> element that provides assorted metadata via nested <meta> elements. Each <meta> element’s name attribute identifies a kind of
metadata and its content attribute supplies the data.

The name attribute’s value names a metadata item. This name starts with the dtb: prefix, where dtb is an acronym for Digital Talking Books. The following names are used:

  • dtb:uid: the book’s unique identifier, which must match the value of the scheme attribute in the OPF file’s <dc:identifier> element.
  • dtb:depth: the depth of the subsequent <navmap> element — the initial depth is 1.
  • dtb:totalPageCount: ignored by Kindle, which is why its content is set to 0.
  • dtb:maxPageNumber: ignored by Kindle, which is why its content is set to 0.

The NCX file continues with <docTitle> and <docAuthor> elements that specify the book’s title and author, which must match their counterparts in the OPF file.

The NCX file concludes with a <navMap> element that identifies the navigation map. This map consists of nested <navPoint> elements that identify navigation points representing significant points in the book to which the reader can navigate directly; for example, move to the beginning of a specific chapter.

Each <navPoint> element must have a unique id value — I’ve specified navpoint- prefixed values. The element must also have a playOrder attribute with a unique integer-based value starting at 1, which indicates that this is the first navigation point in the map.

The <navLabel> element contains text (via a nested <text> element) that could appear in a table of contents. The <content> element identifies the HTML file whose contents are to be displayed when the reader navigates to this point.

My NCX file makes it possible to quickly navigate from the cover page to the table of contents page, to the introduction page, to the start of the quiz page, to the about page by using the left/right arrow keys on the five-way controller supported by certain Kindle devices.


Generate and test the book

After creating the necessary files for my Kindle book, I needed to combine them into a single file and test this file. I used Amazon’s KindleGen tool to generate the book and used Amazon’s Kindle Previewer tool along with my Kindle e-reader device to test it.

Generate the book with KindleGen

KindleGen is a command-line tool that lets publishers work in an automated environment with a variety of source content, including HTML, XHTML, or EPUB. This tool converts source content to a single file that supports the Mobipocket and Amazon KF8 formats.

You can download KindleGen for the Windows XP/Vista/7, Mac OS, and Linux platforms. I downloaded KindleGen v2.9 for my Windows 7 platform, unzipped its distribution archive, and added the path to the kindlegen.exe executable to my PATH environment variable.

After making sure that the current directory contained the book’s quiz.html, cover.jpg, coverpg.html, toc.html, intro.html, aboutjf.html, jeff.png, tbjq.opf, and toc.ncx files, I executed the following command line to generate the book:

kindlegen tbjq.opf

KindleGen issued no warning messages and created a file for my book. This file is essentially a ZIP file that contains the following structure:


Test the book with Kindle Previewer and real devices

Not every aspiring Kindle author has an actual Kindle device, and many more don’t have multiple Kindle devices for testing their creations. To assist developers who don’t have Kindle devices, Amazon released a Kindle emulator that’s known as the Kindle Previewer.

You can download Kindle Previewer for the Windows XP/Vista/7 and Mac OS platforms. I downloaded Kindle Previewer v9 for my Windows 7 platform and ran the installer. After installing Kindle Previewer, I ran this tool. Figure 2 shows a portion of the opening screen.

The opening screen also provides links for accessing help, the ability to change default settings, and more.
Figure 2: The opening screen also provides links for accessing help, the ability to change default settings, and more.

To test my book with Kindle Previewer, I selected the Open Book menu item from the File menu and from the resulting open dialog box. Figure 3 shows the book’s beginning page, which happens to be the introduction.

Kindle Previewer treats the introduction page as the beginning page. The page is being shown as it would appear on the basic Kindle e-ink device.
Figure 3: Kindle Previewer treats the introduction page as the beginning page. The page is being shown as it would appear on the basic Kindle e-ink device.

Kindle Previewer provides a rich menu system and navigation controls. For example, you can specify where you want to go to in the book by selecting one of the menu items from the Go to menu. Also, you can choose a group of Kindle devices from which you choose one device to emulate by selecting the group menu item from the Device menu.

Another feature is the ability to obtain an NCX view of the book by selecting the NCX View menu item from the View menu, and the ability to view book information by selecting Book Information from the same menu. Figure 4 shows you the result.

You can view a book's NCX hierarchy and additional information about the book.
Figure 4: You can view a book’s NCX hierarchy and additional information about the book.

Although Kindle Previewer is a useful tool for testing a book, it’s even more helpful to test the book on an actual Kindle device. After testing my book on Kindle Previewer, I plugged my Kindle device into the computer and transferred to the device. Figure 5 shows you the cover image screen.

A cover image of 500x800 pixels nicely fits my Kindle device's screen.
Figure 5: A cover image of 500×800 pixels nicely fits my Kindle device’s screen.

Publish and get rich and famous (or not)

After testing the book, I decided to publish it in Amazon’s Kindle Store by using Kindle Direct Publishing (KDP). If you’ve never used Amazon’s self-publishing platform, you’ll first need to create an account (which is free). Accomplish this task by pointing your browser to the main KDP page and follow the instructions to create your account.

Each time you sign in to KDP, you’ll be taken to your bookshelf, which provides a list of all books that you’ve published (with relevant details per book), which provides access to various reports so that you can see how well your books are selling, and which provides access to other features. For example, Figure 6 reveals part of my bookshelf.

The bookshelf lists all of your book entries.
Figure 6: The bookshelf lists all of your book entries.

To add my book, I clicked the Add New Title button, and then filled out the Your book and Rights & Pricing screens. Finally, I clicked the Save and Publish button.

On the Your book screen you are given the opportunity to upload or create a book cover, which appears on Amazon’s website. I uploaded my cover_big.jpg file by clicking the Browse for image... button and following the instructions.

Why are there two The BIG Java Quiz entries? After publishing the bottom entry, I changed my mind about its cover image and created a new image. I then selected Edit book details from the Actions drop-down list on the bookshelf page and uploaded the new cover image.

Unfortunately, Amazon wouldn’t update the cover image on its website, so I unpublished my book but was unable to delete it. I decided to republish the book with the new cover image and forget about the original attempt. The lesson: get the book’s cover image right the first time!

Figure 7 reveals the published The BIG Java Quiz on its own Amazon web page.

The BIG Java Quiz awaits its first review.
Figure 7: The BIG Java Quiz awaits its first review.


Creating and publishing my first Kindle book was quite an experience. I made a few mistakes but learned a lot. Hopefully, you’ll find this article’s information helpful should you decide to create your own Kindle books. In the future, I’ll probably create another book for Kindle. Perhaps this time, I’ll focus on a Shrek-oriented satire of vampires who romance each other and write Kindle books for a living!

Login or Create Account to Comment
Login Create Account
Get the most important and interesting stories in tech. Straight to your inbox, daily.Is it good?