Go to file
Marek Goc 1204d75717 compilation 2023-10-18 10:35:35 +02:00
include/mupdf first commit 2023-10-17 17:51:53 +02:00
libs compilation 2023-10-18 10:35:35 +02:00
testdata first commit 2023-10-17 17:51:53 +02:00
.gitattributes first commit 2023-10-17 17:51:53 +02:00
AUTHORS first commit 2023-10-17 17:51:53 +02:00
COPYING first commit 2023-10-17 17:51:53 +02:00
README.md readme update 2023-10-17 21:56:58 +02:00
example_test.go correct version 2023-10-18 09:43:34 +02:00
fitz.go first commit 2023-10-17 17:51:53 +02:00
fitz_cgo.go first commit 2023-10-17 17:51:53 +02:00
fitz_cgo_extlib.go first commit 2023-10-17 17:51:53 +02:00
fitz_cgo_extlib_pkgconfig.go first commit 2023-10-17 17:51:53 +02:00
fitz_content_types.go first commit 2023-10-17 17:51:53 +02:00
fitz_content_types_test.go first commit 2023-10-17 17:51:53 +02:00
fitz_test.go correct version 2023-10-18 09:43:34 +02:00
go.mod correct version 2023-10-18 09:43:34 +02:00
go.sum first commit 2023-10-17 17:51:53 +02:00

README.md

go-fitz

Maal Disclaimer

This is just fork from github repository. Forked in order to recompile with new glibc version.

Whenever you have problem with compability you can download source package from Mupdf source after simply run make to compile on your platform. When this is completed just simply copy following files:

  • libmupdf.a ==> libs/libmupdfthird_linux_amd64.a
  • libmupdf-third.a ==> libs/libmupdf_linux_amd64.a

Part of file name 'linux_amd64' maens OS and platform.

Musl Compilation

To compile for linux musl you can use docker and just simply run following command from CLI

  • docker run --rm -v ./:/mupdf -it alpine:latest sh -c "apk update; apk add alpine-sdk; cd /mupdf;apk add freeglut-dev libxrandr-dev; make clean ;make; chown -R 1000:1000 ./build; mkdir ./musl; cp ./build/release/libmupdf.a ./musl/libmupdf_linux_amd64_musl.a; cp ./build/release/libmupdf-third.a ./musl/libmupdfthird_linux_amd64_musl.a"
Notice that you need to compile MuPdf source for OS and platform you want to use

---------------------------------------------------------------------------------------

Go wrapper for MuPDF fitz library that can extract pages from PDF and EPUB documents as images, text, 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

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()
	}
}