Here's one way to convert your Kindle book into an ePub. This is mostly just busy work, filling out templates, copying stuff from one place to another, and making the final assembly.
Start off by creating a new folder on your computer. It can run right alongside “Kindle Books” and could be called “ePub Books.” Inside that folder create another called “ePub Making Kit” or the equivalent.
In many ways, the ePub version resembles a Kindle book: HTML files of your text, an opf file to direct traffic, an ncx file to create your Table of Contents, a style sheet to boss folks around, tell ’em how to do their jobs. All of these guys are packed into a folder traditionally called OEBPS (Open EBook Publication Structure).
Sitting next to the OEBPS folder is another one called META-INF. Inside that folder is a single file, called the “container.” The container tells the ebook reader where to find the opf file—even though everybody expects to find the opf file in the same place: the folder called OEBPS.
Here’s the text of the container:
<?xml version="1.0"?>
<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>
Once you’ve assembled your first META-INF folder, you can use it for every ePub book you make.
Sitting beside these two folders (OEBPS and META-INF) is a file called the “mimetype.” This file contains one short line of text:
application/epub+zip
And it’s the same for every ePub book you’ll ever create.
As you approach the final assembly, you’ll have a folder dedicated to your new book with just those three items:
META-INF
OEBPS
mimetype
You will then zip these items into a single file. I’ll get into the details in a future post.
The main work of putting together an ePub is tearing your HTML file apart, dropping the parts into separate XHTML templates, and lining everything up in the OEBPS folder.
Here's the template for the standard chunk:
<?xml version="1.0" encoding="utf-8"?>
<!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>EPub Template</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
[New content goes here...]
</body>
</html>
First, prepare your ePub Making Kit. Load copies of the mimetype. Create a META-INF folder and put the “container” file inside. Paste a copy of the “book chunk” template into Notepad++ and clone it repeatedly, naming the copies for: title page, copyright page, chapters one through whatever, the “about the author” page, and the cover page. Save the files like this in your ePub Making Kit folder:
title_page.xhtml
copyright.xhtml
chap_1.xhtml
chap_2.xhtml
chap_3.xhtml (etc.)
about.xhtml
cover_page.xhtml
Open your ePub Books folder and create the assembly folder named for this book. Working from your ePub Making Kit, put a copy of the mimetype file there, as well as a copy of the META-INF folder (with the “container” file inside). Finally, make a new folder for everything else called OEBPS.
Open the HTML file of your book in Notepad++. If you’re at all worried the file might be damaged, create a backup copy and open that instead.
Make sure it says “ANSI as UTF-8” in the bottom right of the screen. If it says something else, click “Encoding” and select “Convert to UTF-8 without BOM.” Save the file, then check Encoding again: It should be set to Encode in UTF-8 without BOM.
Open a new document in Notepad++. This is going to be your style sheet template. Start by adding this code (it's also found in the ePub Making Template on the right-hand sidebar):
body
{margin-left:3%;
margin-right:3%;
margin-top:3%;
margin-bottom:3%;
text-align:justify;}
This code begins by creating a border margin for everything. There's also a fascinating little item called “text-align.” Leave that guy set to “justify” and you’re going to have the same problems with your ePub book as you did with the Kindle edition.
Delete that line and you get a ragged right margin. You could even run your completed ePub file through KindleGen and create a mobi that would allow Kindle Fire apps to follow suit. (Mobi apps stay justified, however.)
Below this starting portion, add the contents of the <style> section of your HTML file. Leave off the top and bottom tags.
IMPORTANT: Don’t click the “save” icon, which may be your habit by now after making changes to a file.
Instead, click File and select “Save a Copy As”; drop the item in the OEBPS folder you just created for your new ePub book. Name it:
style.css
Undo the latest changes to the template (but keep the first chunk) and save it in the ePub Making Kit folder, ready for use on your next book.
Open the title_page.xhtml template and copy either the title page image tag or the header code from your book. Don’t include the ID code unless you also plan to add an XHTML Table of Contents. It would probably be best to remove any width and height specs that call the size in pixels. Rely on your 98% spec for width, either by writing it into the tag or using the wide class. (You do have a wide class copied to your CSS style sheet, right?) Save a copy in the OEBPS folder; undo changes and close the template.
(Actually, if you use an image file for your title page—and you always call the image “title_page.jpg,” you could keep the changes to the completed template file. Saving it now will update the template for use in your next book.)
Open the copyright.xhtml template. Copy the copyright chunk out of your book into the template. Save a copy in the OEBPS folder; undo changes and close the template.
(Again, you could save the populated template; it would be good for the rest of the year, at least.)
Open up the chap_1.xhtml template. Highlight the contents of chapter one in your book—everything from the beginning of its chapter-start (image tag or header code) to just before the page-break code at the end—and drop it into the template. Save a copy in the OEBPS folder; undo changes in the template and close.
Repeat for the rest of your chapters. If you need more templates, copy one and name it appropriately. When you’re done saving the new chapter, empty out the template and save it for the next book.
Open the about.xhtml template and drop in your “About the Author” section. Save a copy in your OEBPS folder; undo the changes and close the template.
(Or keep the changes and update the file with every new book—especially if you end your profile with a list of available books.)
Open the cover_page.xhtml template. This is where you put the image tag that points to your cover. You’ll have to write one just for the ePub version of your book. Following the pattern, save a copy in the OEBPS folder; undo the changes and close the template. (Or save it just the way it is, as long as the names of all your cover images stay “cover.jpg.”)
Close the HTML file of your book, you’re done with it.
Next time, the special files—the ncx file, the opf file, an XHTML Table of Contents; plus: how to assemble and test your ePub book.
No comments:
Post a Comment
Comments are welcome -- and moderated by me. Please be patient.