gomupdf
The fast, idiomatic way to read, render, and write PDFs in Go.
A Go library for reading, rendering, and writing PDF files (and EPUB/SVG), wrapping the MuPDF C library to extract text, detect tables, render pages as images, and create or merge documents.
gomupdf is a Go library for working with PDF files and several other document formats. It provides a Go interface to MuPDF, a well-established C library that handles the actual file parsing and rendering. Developers using Go can add gomupdf to their projects to read text from PDFs, render pages as images, detect tables, and build or modify documents.
Opening a file is a single function call. Once open, you can pull out all the text at once, or work page by page. The library preserves the position of each word and text fragment on the page, which matters when you need to reconstruct layout or identify columns. Table detection is built in and offers two approaches: one that infers table structure from word alignment, and one that follows drawn grid lines in the PDF.
Rendering a page to an image is straightforward. You pass in a zoom level and get back a pixel buffer that you can save as PNG or use directly as a standard Go image type. Search works similarly, returning the coordinates of matching text so you can highlight or crop around results.
On the writing side, you can create new PDFs from scratch, insert text and images into pages, merge documents, set metadata, and save with optional encryption. The API handles conversions too: you can open an EPUB or SVG file and convert it to a writable PDF.
Installation requires the MuPDF C library and development headers to be present on your system, because the Go code calls into C. The README includes package manager commands for macOS, Debian, Fedora, and Arch Linux, and explains how to point the build at a custom installation location.
Where it fits
- Extract all text from a PDF in Go with a single function call, preserving word positions for layout reconstruction.
- Render any PDF page to a PNG image at a custom zoom level for thumbnail generation or document preview features.
- Detect tables inside a PDF using either word-alignment inference or drawn grid lines, then process the data in Go.
- Merge multiple PDF files, add metadata, and save the result with optional encryption in a Go backend service.