1. Products
  2.   eBook
  3.   GO
  4.   Go-EPUB
 
  

Free Go Library for EPUB Documents Creation

Open Source Go Library to create EPUB files. It includes support for adding CSS, images, and fonts.

Go-EPUB is a very useful open source Go library that enables software developers to create EPUB files inside their own Go application with ease. The library is very well documented and all the error messages are self-explanatory. The library has included very useful functions for handling media files such as fetches a media from a URL, get the media from the local FR or fetch the media from a RFC 2397 encoded scheme.

The Go-EPUB library is very simple to handle and has included several important features for handling with EPUB documents, such as Creates valid EPUB 3.0 files, add image to EPUB files, support for custom CSS, add video inside EPUB file, add fonts and use EPUB 2.0 table of contents addition for maximum compatibility.

The Go-EPUB library supported EPUBCheck tool that allows users to check an EPUB for validation errors. If If EPUBCheck is installed locally, it will be run alongside the Go tests. To use to EPUBCheck make sure you have Java installed on your system. If users don’t like to install EPUBCheck locally, it is also possible to manually validate the EPUB documents.

Previous Next

Getting Started with Go-EPUB

To install the Go-EPUB library on your system, please run the following command.

Install PDF via GitHub

 go get https://github.com/iditectweb/pdf.git

You can also install it manually; download the latest release files directly from GitHub repository.

Generate EPUB File using Go API

The open source Go-EPUB library has included complete functionality for creating EPUB documents inside their own Go application with just a couple of lines of Go commands. The library has provided several important features related to documents creation, such as set author, add new section to the document, insert images inside the document, apply text formatting and style, add fonts of choice, and many more.

Create New EPUB File via Go Library

// Create a new EPUB
e := epub.NewEpub("My title")

// Set the author
e.SetAuthor("Hingle McCringleberry")

// Add a section
section1Body := `

Section 1

This is a paragraph.

` e.AddSection(section1Body, "Section 1", "", "") // Write the EPUB err = e.Write("My EPUB.epub") if err != nil { // handle error }

Add image to EPUB Files via Go API

The open source Go-EPUB library allows programmers to add images to their EPUB documents inside their Go applications. The library has include numerous method for inserting images inside a EPUB file, such as by using a URL or a complete path to a local image file or by embedded data URL. In either case the image file will be retrieved and stored in the EPUB document. The inner filename will be used when storing the image file in the EPUB and must be unique among all image files.

How to Add Image to EPUB File via Go API

  e := epub.NewEpub("My title")

// Add an image from a local file
img1Path, err := e.AddImage("testdata/gophercolor16x16.png", "go-gopher.png")
if err != nil {
	log.Fatal(err)
}

// Add an image from a URL. The filename is optional
img2Path, err := e.AddImage("https://golang.org/doc/gopher/gophercolor16x16.png", "")
if err != nil {
	log.Fatal(err)
}

fmt.Println(img1Path)
fmt.Println(img2Path)

Add CSS & Fonts to EPUB Files via Go API

The Go-EPUB library gives software developers the capability to add custom CSS as well as fonts of their choice inside their EPUB documents. Same like images the library allows to either use a URL, a path to a local file, or an embedded data URL to insert CSS or font inside a EPUB file. Please remember that the internal filename will be used when storing the font file in the EPUB.

Add CSS to EPUB Documents using Go API

// Add CSS
css1Path, err := e.AddCSS("testdata/cover.css", "epub.css")
if err != nil {
	log.Fatal(err)
}

// The filename is optional
css2Path, err := e.AddCSS("testdata/cover.css", "")
if err != nil {
	log.Fatal(err)
}

// Use the CSS in a section
sectionBody := `    

Section 1

This is a paragraph.

` e.AddSection(sectionBody, "Section 1", "", css1Path) fmt.Println(css1Path) fmt.Println(css2Path)