Skip to content
/ mobi Public

Golang package containing Writer/Reader for MOBI format

License

Notifications You must be signed in to change notification settings

766b/mobi

Repository files navigation

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 by image/jpeg package.
  • 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.

About

Golang package containing Writer/Reader for MOBI format

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages