Mobi
Writer/Reader for Mobi format.
Note: All testing were done on Kindle Previewer
(Windows) and Kindle Paperwhite (6th Gen)
Before You Start
- This is more or less WIP. Use at your own risk.
- This package was written for a specific task, thus there are certain limitations, such as:
img
tags are ignored and not embedded.- TOC depth does not go beyond 1. Meaning for now you can only have chapters and sub-chapters. But sub-chaper can not have it's own sub-chapters.
- HTML formatting is supported, but rendering is dependant on your eBook reader. (For Kindle see Supported HTML Tags in Book Content)
- Cover images should be in JPG (I have not tested GIF, which sould be supported).
- IMPORTANT: Images resized using
image/jpeg
package will not display (in Kindle) because JFIF APP0 marker segment is not generated byimage/jpeg
package.
- IMPORTANT: Images resized using
- Table of Content is automaticaly generated.
Usage
Writer
m, err := mobi.NewWriter("output.mobi")
if err != nil {
panic(err)
}
m.Title("Book Title")
m.Compression(mobi.CompressionNone) // LZ77 compression is also possible using mobi.CompressionPalmDoc
// Add cover image
m.AddCover("data/cover.jpg", "data/thumbnail.jpg")
// Meta data
m.NewExthRecord(mobi.EXTH_DOCTYPE, "EBOK")
m.NewExthRecord(mobi.EXTH_AUTHOR, "Book Author Name")
// See exth.go for additional EXTH record IDs
// Add chapters and subchapters
ch1 := m.NewChapter("Chapter 1", []byte("Some text here"))
ch1.AddSubChapter("Chapter 1-1", []byte("Some text here"))
ch1.AddSubChapter("Chapter 1-2", []byte("Some text here"))
m.NewChapter("Chapter 2", []byte("Some text here")).AddSubChapter("Chapter 2-1", []byte("Some text here")).AddSubChapter("Chapter 2-2", []byte("Some text here"))
m.NewChapter("Chapter 3", []byte("Some text here")).AddSubChapter("Chapter 3-1", []byte("Some text here"))
m.NewChapter("Chapter 4", []byte("Some text here")).AddSubChapter("Chapter 4-1", []byte("Some text here"))
// Output MOBI File
m.Write()
Reader
For now, Reader does not give any useful information.