gen2brain
go-fitz
C

Golang wrapper for the MuPDF Fitz library

Last updated Jul 8, 2026
634
Stars
132
Forks
5
Issues
+3
Stars/day
Attention Score
68
Language breakdown
No language data available.
Files click to expand
README

go-fitz

Build Status GoDoc Go Report Card

Go wrapper for MuPDF fitz library that can extract pages from PDF, EPUB, MOBI, DOCX, XLSX and PPTX documents as IMG, TXT, HTML or SVG.

Build tags

  • extlib - use external MuPDF library
  • static - build with static external MuPDF library (used with extlib)
  • pkgconfig - enable pkg-config (used with extlib)
  • musl - use musl compiled library
  • nocgo - experimental purego implementation (can also be used with CGOENABLED=0)

Notes

The bundled libraries are built without CJK fonts, if you need them you must use the external library.

Concurrent rendering is supported when each goroutine uses its own Document (a separate MuPDF context). Concurrency on a single Document, including racing with Close, is not supported.

The purego implementation loads the libmupdf shared library at runtime. Its version is detected automatically; set the FZ_VERSION environment variable (or fitz.FzVersion) to override it.

Example

package main

import ( "fmt" "image/jpeg" "os" "path/filepath"

"github.com/gen2brain/go-fitz" )

func main() { doc, err := fitz.New("test.pdf") if err != nil { panic(err) }

defer doc.Close()

tmpDir, err := os.MkdirTemp(os.TempDir(), "fitz") if err != nil { panic(err) }

// Extract pages as images for n := 0; n < doc.NumPage(); n++ { img, err := doc.Image(n) if err != nil { panic(err) }

f, err := os.Create(filepath.Join(tmpDir, fmt.Sprintf("test%03d.jpg", n))) if err != nil { panic(err) }

err = jpeg.Encode(f, img, &jpeg.Options{jpeg.DefaultQuality}) if err != nil { panic(err) }

f.Close() } }

🔗 More in this category

© 2026 GitRepoTrend · gen2brain/go-fitz · Updated daily from GitHub