Help us shape the future of Go! Take the 2026 Go Developer Survey

openpdf

package module
v0.0.0-...-1e50ac0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 0 Imported by: 0

README

OpenPDF - create, read and process PDFs in Go

CI Go Reference Go Report Card Go version MIT licence GitHub stars Open issues

OpenPDF - PDF for Go

OpenPDF is an MIT-licensed PDF library for Go (golang) for creating, reading and processing PDF files.

Contents

Installation

Requires Go 1.27 or later.

go get github.com/OpenMellon/openpdf

Quick start

Create a PDF
package main

import (
	"log"

	"github.com/OpenMellon/openpdf/creator"
)

func main() {
	c := creator.New()
	c.NewPage()

	p := c.NewStyledParagraph()
	p.SetText("Hello, OpenPDF")
	p.SetFontSize(20)
	if err := c.Draw(p); err != nil {
		log.Fatal(err)
	}

	if err := c.WriteToFile("hello.pdf"); err != nil {
		log.Fatal(err)
	}
}
Extract text
reader, f, err := model.NewPdfReaderFromFile("in.pdf", nil)
if err != nil {
	log.Fatal(err)
}
defer f.Close()

page, err := reader.GetPage(1)
if err != nil {
	log.Fatal(err)
}
ex, err := extractor.New(page)
if err != nil {
	log.Fatal(err)
}
text, err := ex.ExtractText()
Merge and split
// Merge in1.pdf and in2.pdf into out.pdf (last argument: merge form fields too).
err := pdfutil.MergePdf([]string{"in1.pdf", "in2.pdf"}, "out.pdf", false)

// Keep pages 2-4 only.
err = pdfutil.ExtractPageRange("in.pdf", "pages.pdf", 2, 4, false)

Imports used above: github.com/OpenMellon/openpdf/{creator,extractor,model,pdfutil}.

Features

Each feature links to a runnable example, or to the package that provides it where there is no example yet.

Feature Example / package
Create reports, tables, invoices and styled paragraphs example, creator
Add images and watermarks to pages example, creator
Merge PDFs example, pdfutil
Split, rotate and reorder pages example, pdfutil, model
Extract text (with size, position and formatting) and images example, extractor
Compress and optimise PDF files example, model/optimize
Password protection and unlocking example, model
Create, fill and flatten forms example, annotator
FDF and JSON form data fdf, fjson
Digital signing and signature validation example, model/sighandler, timestamp
Redaction example, redactor
Sanitisation sanitize
PDF/A and PDF/UA model/pdfa, model/pdfua
Render pages to images render
OCR integration ocr
Charts, Arabic shaping and complex text layout unichart, garabic, textshaping, typesetting

Packages

Package Use it to
creator Build documents: pages, text, tables, images, headers, footers, TOC
model Read and write PDFs at page level; encryption, forms, signatures
extractor Pull text, images and fonts out of pages
pdfutil One-call merge, page-range extraction, grayscale
annotator Form fields, signature fields and annotation appearances
core Low-level PDF objects and parsing
contentstream Parse and generate page content streams

Full API reference: pkg.go.dev/github.com/OpenMellon/openpdf.

Examples

Examples are Go testable examples: Example functions in example_test.go files that appear beside the API on pkg.go.dev and are compiled and run by go test, so they cannot go stale.

go test ./... -run Example -v

Contributing

Contributions are welcome. See CONTRIBUTING.md for development setup and how to open a pull request, and SUPPORT.md for where to ask questions. Report security vulnerabilities privately as described in SECURITY.md. Everyone taking part is expected to follow the Code of Conduct.

License

MIT - see LICENSE. OpenPDF is a derivative of UniPDF, Copyright 2020 FoxyUtils ehf., which was released under the MIT licence; the original copyright notices are retained in the source files and must stay with any copy. Packages derived from other projects, now separate modules under github.com/OpenMellon/ (freetype, garabic, go-xmp, pkcs7, timestamp, typesetting, unichart, unitype) keep their own licences; see ACKNOWLEDGEMENTS.md.

Documentation

Overview

Package openpdf is a comprehensive PDF library for Go (golang). The library has advanced capabilities for generating, processing and modifying PDFs. OpenPDF is written and supported by the owners of the FoxyUtils.com website, where the library is used to power many of the PDF services offered.

Getting More Information

Check out the Getting Started and Example sections, which showcase how to install openpdf and provide numerous examples of using openpdf to generate, process or modify PDF files. https://github.com/OpenMellon/openpdf

The GoDoc for openpdf provides a detailed breakdown of the API and documentation for packages, types and methods. https://godoc.org/github.com/OpenMellon/openpdf

Overview of Major Packages

The API is composed of a few major packages:

  • common: Provides common shared types such as Logger and utilities to check license validity.

  • core: The core package defines the primitive PDF object types and handles the file reading I/O and parsing the primitive objects.

  • model: The model package builds on the core package, to represent the PDF as a structured model of the PDF primitive types. It has a reader and a writer to read and process a PDF file based on the structured model. This serves as a basis to perform a number of numerous tasks and can be used to work with a PDF in a medium to high level interface, although it does require an understanding of the PDF format and structure.

  • creator: The PDF creator makes it easy to create new PDFs or modify existing PDFs. It can also enable loading a template PDF, adding text/images and generating an output PDF. It can be used to add text, images, and generate text and graphical reports. It is designed with simplicity in mind, with the goal of making it easy to create reports without needing any knowledge about the PDF format or specifications.

  • extractor: Package extractor is used for quickly extracting PDF content through a simple interface. Currently offers functionality for extracting textual content.

Directories

Path Synopsis
Package annotator provides an interface for creating annotations with appearance streams.
Package annotator provides an interface for creating annotations with appearance streams.
Package common contains common properties used by the subpackages.
Package common contains common properties used by the subpackages.
Package contentstream provides functionality for parsing and creating content streams for PDF files.
Package contentstream provides functionality for parsing and creating content streams for PDF files.
draw
Package draw has handy features for defining paths which can be used to draw content on a PDF page.
Package draw has handy features for defining paths which can be used to draw content on a PDF page.
Package core defines and implements the primitive PDF object types in golang, and provides functionality for parsing those from a PDF file stream.
Package core defines and implements the primitive PDF object types in golang, and provides functionality for parsing those from a PDF file stream.
Package creator is used for quickly generating pages and content with a simple interface.
Package creator is used for quickly generating pages and content with a simple interface.
Package extractor is used for quickly extracting PDF content through a simple interface.
Package extractor is used for quickly extracting PDF content through a simple interface.
Package fdf provides support for loading form field data from Forms Data Format (FDF) files and for exporting the field data of a PDF form to an FDF file.
Package fdf provides support for loading form field data from Forms Data Format (FDF) files and for exporting the field data of a PDF form to an FDF file.
Package fjson provides support for loading PDF form field data from JSON data/files.
Package fjson provides support for loading PDF form field data from JSON data/files.
internal
license
Package license is a no-op stand-in for the former licence-key system.
Package license is a no-op stand-in for the former licence-key system.
tools/checklog command
Package model provides an interface for working with high-level objects (models) in PDF files, including reading and writing documents.
Package model provides an interface for working with high-level objects (models) in PDF files, including reading and writing documents.
mdp
optimize/tests
Package tests provides integration tests for the OpenPDF optimizer.
Package tests provides integration tests for the OpenPDF optimizer.
pdfa
Package pdfa provides abstraction to optimize and verify documents with respect to the PDF/A standards.
Package pdfa provides abstraction to optimize and verify documents with respect to the PDF/A standards.
pdfua
Package pdfua provides PDF/UA (ISO 14289) standard profiles for validating and applying accessibility requirements to PDF documents.
Package pdfua provides PDF/UA (ISO 14289) standard profiles for validating and applying accessibility requirements to PDF documents.
sighandler
Package sighandler implements digital signature handlers for PDF signature validation and signing.
Package sighandler implements digital signature handlers for PDF signature validation and signing.
xmputil
Package xmputil provides abstraction used by the pdf document XMP Metadata.
Package xmputil provides abstraction used by the pdf document XMP Metadata.
Package ps implements various functionalities needed for handling Postscript for PDF uses, in particular for PDF function type 4.
Package ps implements various functionalities needed for handling Postscript for PDF uses, in particular for PDF function type 4.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL