go-fitz/README.md

72 lines
1.8 KiB
Markdown
Raw Normal View History

2023-10-17 15:51:53 +00:00
## 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](https://mupdf.com/downloads/archive/mupdf-1.23.0-source.tar.gz) after simply run ``` make``` to compile on your platform. When this is completed just simply copy following files:
2023-10-17 15:54:03 +00:00
- ```libmupdf.a``` ==> ```libs/libmupdfthird_linux_amd64.a```
- ```libmupdf-third.a``` ==> ```libs/libmupdf_linux_amd64.a```
2023-10-17 15:51:53 +00:00
Part of file name 'linux_amd64' maens OS and platform.
##### Notice that you need to compile MuPdf source for OS and platform you want to use
### ---------------------------------------------------------------------------------------
Go wrapper for [MuPDF](http://mupdf.com/) 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
```go
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()
}
}
```