// pdf-go: a PDF library in pure Go
Read, validate and sign PDFs, in pure Go
PDF Go reads PDF files byte by byte, checks their structure, repairs only when you ask it to and writes them back. Signatures, encryption, text extraction and rendering are included. All it needs is the Go standard library, with no CGo and no third-party modules.
- licenseAGPL-3.0
- commercialavailable
- depsgo stdlib only
- releasev0.1.0-alpha.1
$ pdfgo validate -repair invoice.pdf
status: failed
checks_passed: false
PDF.REPAIR.STARTXREF: startxref did not identify the current cross-reference section
PDF.XREF.START_OFFSET: startxref 309 does not point to an xref section or stream
$ pdfgo repair invoice.pdf invoice-repaired.pdf; echo $?
4
$ pdfgo info invoice-repaired.pdf
PDF 1.7
pages: 1
diagnostics: 0
$
Why PDF Go
Invoices, contracts and delivery notes arrive as PDFs. If you process them automatically, you need a library that swallows nothing. It has to spot damaged files, report every repair openly and keep earlier versions of a file readable. And it should drop into a Go service without C dependencies. That is exactly why we wrote PDF Go.
What’s in the library
pdf.OpenFile(ctx, path, opts)Reading without guessing
Exact values, cross-reference tables and streams, object streams and incremental revisions.
Strictmode rejects malformed input. You switch onRepairexplicitly, and every repair then appears in the diagnostics.document.ResolveRevision(…)Reading earlier versions
Older revisions of a file can be resolved on purpose, including objects that a later change replaced or deleted. So you can see what the file contained before a change or a signature.
pdfgo validate --jsonChecking the structure
Headers from PDF 1.0 to 2.0, cross-references, trailers, stream lengths and linearised files. The report gives every finding a code, as text or JSON, and clear exit codes for your pipeline.
pdfgo sign · pdfgo verifySigning and verifying
Detached CMS signatures are written incrementally into named form fields, and multiple signatures are preserved. When verifying, PDF Go checks the ByteRange and the trust chain against your X.509 roots.
pdfgo encrypt · pdfgo decryptEncryption
The Standard Security Handler R2 to R6 with RC4, AES-128 and AES-256. New files are encrypted with R6 and AES-256.
pdfgo extract · pdfgo renderText and images
Text comes out in content order via ToUnicode, without guesswork. Pages with vectors, images, TrueType and Type3 fonts are rendered to PNG.
document.BeginEdit()Editing and writing
Changes run in isolated transactions. Then you rewrite the file deterministically or append the change incrementally.
Quickstart
- Add the library to your module with
go get. You need Go 1.26 or newer. - Open a file in
Strictmode and read the catalogue, pages and objects. - Install the
pdfgocommand-line tool for validation, repair, signing and rendering. - Use the exit codes in your pipeline: 3 means failed checks, 4 a repaired file.
$ go get gitlab.schukai.com/oss/libraries/go/documents/pdf@v0.1.0-alpha.1
$ go install gitlab.schukai.com/oss/libraries/go/documents/pdf/cmd/pdfgo@v0.1.0-alpha.1
document, err := pdf.OpenFile(ctx, "contract.pdf", pdf.OpenOptions{
Mode: pdf.Strict,
})
// …
fmt.Printf("PDF %s, %d pages\n", document.Version(), len(pages))
What you can rely on
- Only the Go standard library.No CGo and no third-party modules.
go list -m allshows exactly one module. - Written by us, with a clear provenance.Code, rule tables and test files are our own. Nothing is taken from other PDF implementations; the ISO standards serve as the specification.
- A report that says what was checked.The validation report separates passed checks (
checks_passed) from complete profile coverage (complete). So you know exactly what a result is based on. - Limits instead of surprises.Configurable limits, cancellation via
context, safe concurrent access and no network access of its own. - Tested the way a parser needs to be.Release checks include tests with the race detector and
go vet, plus fuzzing with damaged input.
Licences
- Open source under AGPL-3.0.For open-source projects, you use PDF Go under the GNU Affero General Public License, version 3.
- A commercial licence for your software.Want to use PDF Go in a product or service without disclosing your code under the AGPL? We offer a commercial licence for that. Write to us and we’ll send you an offer.
FAQ
Which release is current?
The current release is v0.1.0-alpha.1 from 28 October 2026. The API may still change before version 1.0. Every change is listed in the repository’s changelog.
Do I need C libraries or third-party Go modules?
No. PDF Go builds with CGO_ENABLED=0 and uses only the Go standard library. Your binary stays static and easy to audit.
What do the pdfgo exit codes mean?
0 for success, 1 for usage or file errors, 2 for processing errors, 3 for failed checks and 4 for a repaired file. 5 and 6 report that a validation is not yet complete or needs a manual review.
Where can I get a commercial licence or support?
From us. Write to us about what you want to use PDF Go for, and we’ll send you an offer for licence and support.
PDF processing in your software?
We are the developers behind PDF Go. Incoming documents, archive or signing workflow: we license the library for your product or build the PDF processing into it together with you.