The mysterious opf file ("open packaging format") is a common rock upon which Kindle books may founder. But fear not: Copy and paste my version, modify only those parts you are allowed to touch, and skip home free.
The items you need to change are displayed in red (a color lost when you paste into Notepad++). Keep the blog version open on your browser for guidance as you work.
Make no unauthorized changes!
The opf file is extremely touchy. If modified incorrectly, it will not serve. Kindle will deliver WARNINGS. Soufflés will fall.
THE DREADED FILE
<?xml version="1.0"?>
<package version="2.0" xmlns="http://www.idpf.org/2007/opf" unique-identifier="BookId">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
<dc:title>Your Title</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="BookId" opf:scheme="uuid">268a4670-ca8a-11e2-8b8b-0800200c9a66>
<dc:creator opf:file-as="Lastname, Firstname" opf:role="aut">Your Name</dc:creator>
<dc:publisher>Fake-out Publications</dc:publisher>
<dc:date>YYYY-MM-DD</dc:date>
<dc:subject>Type of book</dc:subject>
<dc:description>Say a few words about your book.</dc:description>
<meta name="cover" content="cover" />
</metadata>
<manifest>
<item id="toc" href="toc.html" media-type="application/xhtml+xml" />
<item id="book" href="book.html" media-type="application/xhtml+xml" />
<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml" />
<item id="cover" href="cover.jpg" media-type="image/jpeg" />
</manifest>
<spine toc="ncx">
<itemref idref="toc" />
<itemref idref="book" />
</spine>
<guide>
<reference type="toc" title="Table of Contents" href="toc.html" />
<reference type="text" title="Beginning" href="book.html" />
</guide>
</package>
DISCUSSION
After the boilerplate opening, we get to the <metadata> section. Most of this stuff is the so-called Dublin Core, each part of which begins with the "dc:" tag.
The first six items are mandatory: title, language, identifier, creator, publisher, date.
For language, you could also use "en-US" for American English, or "en-GB" for British English. Or something else even more appropriate.
The identifier number must match the one given in the ncx file. Here you also have to identify a "scheme." In this case it's "uuid." You can get your very own bizarre number at this site.
The creator's name goes in backwards (says "file-as"), but the author's name ("aut") runs front to back.
In the publisher slot you could put your name, or the name of a fake publisher. But some folks have a problem with that. See THE MISSING IMPRINT.
I've found that <dc:date> does not go nuts in Kindle if you use only one digit for month and day, but you'll need two for ePub. You could also just use the year and month. Or just the year. But you have to put something here.
The last two Dublin Core items are optional.
For <dc:subject>, consider: Romance, Thriller, Western, Mystery, etc. You can also use codes generated by the Book Industry Study Group here (up to three, I'm told). Go to their Website for more information.
You are now allowed to say a few words about your book. In his tutorial, Australian writer Rhys Tate says you can put up to three entries here, though none can exceed 255 characters in length.
Or you could say nothing at all.
At the end of the <metadata> section is one of the two lines in the opf file that refers to the cover of your book. One term there:
name="cover"
must be shown exactly as it is here.
The second part of that line:
content="cover"
can be changed (though one might question your motives) to virtually anything (i.e.: content="monkey-boy"). Just make sure the second reference to the cover (in the <manifest> section) uses the exact same name:
item id="monkey-boy" href="cover.jpg"
Use can also change the name of the actual image file, so long as it matches the name in the folder where the opf file resides. Just remember: Every single change you make is fraught with existential danger. The tiniest typo, the least speck of error can ruin everything.
After the <metadata> section comes the <manifest>. This is where the HTML content of your book is listed: your HTML Table of Contents, the book's file itself (if it's in chunks, list each chunk separately), as well as the ncx version of your TOC.
Images also go here.
I only list the cover image, but some folks will tell you every single image in your book (title page, chapter-start, etc.) must be listed in the manifest. My experience with Kindle assures me otherwise. But other versions of ebook may be less forgiving. (Like ePub.)
Finally, as I mentioned before, the "item id" name for the cover must agree with the one given it in the previous section (content="[blah-blah]").
Note the third part of that cover listing:
media-type="image/jpeg"
and focus on the fact the reference here is to "jpeg" not 'jpg" as indicated by the cover file's actual name. Pay attention to this crucial difference: jpg is the file name extension; jpeg is the name of this type of images.
Other file types are possible: gif or png, for instance. In these cases, the file extension is the same as the media type notation.
Some versions of the opf file you might come across on the Internet contain an additional line in the manifest section:
<item id="stylesheet" href="style.css" media-type="text/css"/>
This is a reference to a separate style sheet. But if you keep your book in one HTML file, one which already contains a <style> section in the <head> that specifies paragraph and header styles, you don't need a separate style sheet – at least, not for Kindle. In fact, Kindle does not support the use of a separate style sheet. (Other ebook versions, such as ePub, pretty much require a style sheet.)
If you are perverse, and desire to create your very own style sheet, simply copy the style section from the HTML file of your book and paste it into a new Notepad++ window. Don't include the <style> or </style> tags, just the actual definitions. Save the file as "All files" and give it this name (you have to type in the "css" extension):
style.css
CSS stands for Cascading Style Sheets. It's mainly used for Web page design, to insure multiple HTML files will have the same styling (font, background color, layout, etc).
Having a separate style sheet is probably harmless, as long as you retain the <style> section in your book. Remove that section, and a separate style sheet is useless in Kindle. Your artfully designed paragraphs will revert to standard Web page display: non-indented blocks of text with blank lines in between.
Now a section called the <spine>. Inside the opening tag is a place to name the "toc." They're referring here to the ncx version of the toc. Use the same name you gave it in the manifest section. I call it "ncx" in the manifest so I can use "toc" for the HTML version.
In the spine you should list the HTML Table of Contents and the HTML file of your book.
The final section is called the <guide>. Here you again reference the HTML Table of Contents and the "Beginning" of your book. I just put "book.html" there. Usually the Kindle edition opens on the title page, which is the first anchor in the book. Some folks recommend using the HTML Table of Contents in the href for the last line:
<reference type="text" title="Beginning" href="toc.html" />
Try it and see if you like it. But I have to say, my title pages look a lot better than a generic table of contents that doesn't even mention the book's name.
When you've made your (authorized) modifications, save the file in your book's dedicated folder. Select "All files" as the type and write the extension (.opf) after the name of the file, like this:
content.opf
Earlier, when you tested your preliminary versions in Kindle Previewer, you double-clicked the HTML file. This time, be sure to point Previewer at the opf file instead. Otherwise, clicking the buttons at the top of the page will just give you error messages: no cover, no table of contents, no navigation file.
Roam all over the various Kindle versions and apps. See if you can live with the compromises you will undoubtedly have to make. You may want to go back to the HTML file to fiddle a bit. But when it works, you're just about ready to go to the final step.
No comments:
Post a Comment
Comments are welcome -- and moderated by me. Please be patient.