gopdf documents a transparency snippet that does not compile and three examples cut off mid line
A simple library for generating PDF written in Go lang
At a glance
- What is it?
- gopdf is a small Go library for generating PDF files, built around one mutable struct with methods that each return an error. Its feature list is six bullets, its examples are short, and three of them are truncated, one in the middle of an identifier, while the transparency example is missing its package qualifier and its document variable.
- Who is it for?
- gopdf is a reasonable choice if you want to write PDF bytes directly from Go with no cgo and no external binary, and if your documents need Chinese, Japanese or Korean text you will want the subfont embedding it advertises. Two things to check before you build on it.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 2 days ago.
- What is it written in?
- Mainly Go, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 23, 2026, and from our analysis. They are not legal advice.
Star history
- signintech/gopdf2,944 ★ · +6
| Repository | 2026-09-24 | 2026-11-23 |
|---|---|---|
| signintech/gopdf | 2.9k | 2.9k |
6 Stars in the last 60 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Three documented examples stop in the middle of the code
The readme is mostly a list of short examples, and three of them are cut off mid statement. The links example ends after adding an internal link; the function is never closed and the document is never written to a file. The header and footer example is worse, ending on a single letter that is presumably the start of an identifier. The import existing PDF example stops partway through a function name, after an assignment beginning with three letters. None of these is a rendering artefact on your side, and none is marked as abbreviated. The examples that do complete, such as printing text, drawing a polygon, or drawing a rounded rectangle, are short enough to be checked at a glance, so the pattern is that the brief ones work and the longer ones are truncated. If you are evaluating the library, read the package source rather than the readme for anything non-trivial.
The transparency example does not compile as printed
The transparency snippet is the one example with a problem you would hit immediately rather than at the end. It reads:
// alpha - value of transparency, can be between `0` and `1`
// blendMode - default value is `/Normal` - read about [blendMode and kinds of its](https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf) `(page 325, section 11.3.5)`
transparency := Transparency{
Alpha: 0.5,
BlendModeType: "",
}
pdf.SetTransparency(transparency Transparency)Three problems in three lines. The type name carries no package qualifier, while every other example in the file qualifies its types. There is no document variable in scope in this snippet, since the example never constructs one. And the call passes a second argument that reads as a type rather than a value. Whatever the intended signature is, this block will not build, and transparency is one of the features a reader is most likely to reach for.
The password example ships example passwords and full permissions
The password protection example is complete and runnable, which makes it the one most likely to be copied verbatim. It enables protection, grants the print, copy and modify permissions together, and sets an owner password of six digits and a user password of nine. So a document produced by copying this example is nominally protected while permitting the reader to print it, copy its text, and modify it, with credentials that are visible in the readme. The example itself is doing what an example has to do, and the comments in the file are absent, so this is a documentation gap rather than a security flaw. It is still the section most worth reading carefully, because a reader in a hurry will run it, produce a file, and believe it is protected in a way it is not.
The only dependency is pinned to a December 2021 commit
The module file is four lines and declares one dependency, which is the library used for importing existing PDF files. That dependency is credited in the readme to a different author, with a thank-you note. What is worth noting is the version: it is a pseudoversion, which means the dependency is pinned to a specific commit rather than to a release tag. The commit is from December 2021. So the newest code in this repository, last pushed in September 2026, builds against a five-year-old snapshot of its single external dependency, pinned by commit hash. That is stable in the sense that it will not move under you, and it is a liability in the sense that there is no version number to reason about when deciding whether to take an update.
The API is one mutable struct and every call returns an error
There is no interface and no options struct for the document itself. You declare a value, start it with a configuration holding a page size, add pages, register a font, set a font, write cells, and write the file out. Every one of those steps returns an error, and the examples handle all of them the same way: assign to a variable, test for nil, print the message, return. The cell call takes a nil rectangle, which is how text gets measured from the font metrics rather than placed in a box you specify. It is a small API with a low learning curve, and the cost is that the document is mutable shared state, so two goroutines cannot safely share one. The font object is also a string key you pass repeatedly, so the same font name appears in every call that needs it.
The feature list omits the Arabic and right to left machinery in the tree
The feature list has six bullets, and the first is Unicode subfont embedding, named as covering Chinese, Japanese, Korean and similar. What the repository actually contains is a set of files whose names are about Arabic specifically: an alphabet table, a helper, and a test. Right to left shaping and bidirectional handling is a substantial piece of work that is not a by-product of subfont embedding, and it is not mentioned in the feature list or in any visible section of the documentation. The example directory backs it up, with a dedicated folder for Arabic among the six example folders present. So the documentation understates what the library does here, which is the better direction to be wrong in, and it also means the one feature list you have to judge the library by is not the whole list.
Fifty flat files named after PDF objects and two with typos
This repository has no internal package structure. The root is a long flat list of Go files named after the objects in the PDF specification itself: annotation, catalog, colour space, content, device RGB, embedded font, encoding, encryption, font, font descriptor objects, and so on. Alongside them is a family of caching files, one per content type, for line width, line type, oval, polygon, rectangle, rotation, text, and each colour model. Two of those file names contain transposed letters, one for a content curve and one for a colour cache. There is also a font maker directory, a debug directory, an examples directory, and a security policy at the root. The naming makes the library navigable if you know the PDF specification, because the file names are the specification's vocabulary, and it makes it hard to find anything else.
The install command predates modules and the floor is Go 1.13
Two version facts, both old. The readme states a minimum Go version of 1.13, and the module file agrees. That release of the language is from 2019. The install line is a single command that fetches the module and updates it, which is the form used before the module system settled, and it does not carry a version. The rest of the documentation is careful about edge cases in a way that suggests current thinking: the justification feature documents three specific behaviours, namely that a paragraph's last line stays left aligned, that a line with no spaces is left aligned unchanged, and that a line which already fills or overflows the cell is left aligned unchanged. Superscript and subscript derive their glyph size and baseline shift from the font's own metrics with fallbacks, and the logical font size keeps governing line layout. The prose is newer than the version floor.
Editorial conclusion
gopdf is a reasonable choice if you want to write PDF bytes directly from Go with no cgo and no external binary, and if your documents need Chinese, Japanese or Korean text you will want the subfont embedding it advertises. Two things to check before you build on it. The documented examples are not all complete, so plan to read the package source rather than the readme for anything beyond printing a line of text, and note in particular that the transparency example does not compile as printed. And its only dependency is pinned to a commit from 2021 in a pseudoversion rather than a clean release tag, so you are inheriting that pin without a version you can reason about.
Frequently asked questions
How can I create a PDF in Golang?
With gopdf, which is a MIT library for generating PDF documents written in Go with a minimum Go version of 1.13. The install line in the readme is a single go get with the update flag, and the library needs no cgo and no external binary. It advertises Unicode subfont embedding for Chinese, Japanese, Korean and similar, plus drawing, images with masks, kerning, text alignment and password protection.
Is gopdf's feature list the whole feature set?
No. The list has six bullets and does not mention Arabic or right to left shaping, yet the repository root contains an Arabic alphabet table, an Arabic helper and a test for them, and the examples directory has a dedicated Arabic folder. The documentation understates the library here rather than overstating it.
Can I import an existing PDF with gopdf?
Yes, through a separate package created by a different author, credited in the readme. The module file declares it as the only dependency, at a pseudoversion pinned to a commit from December 2021 rather than to a release tag. So you inherit a hash-pinned five-year-old snapshot of it.
Does gopdf support text transparency?
There is a method for it and a documented example, but the example does not compile as printed: the type name carries no package qualifier, there is no document variable in scope, and the call passes a second argument that reads as a type. The readme points to the PDF specification for the transparency and blend mode semantics.
How are the gopdf examples reliable?
The short ones are. Three longer examples are truncated: the links example never closes its function or writes the file, the header and footer example ends on a single letter, and the import example stops partway through a function name. The password example is complete and runnable, but it uses example passwords and grants print, copy and modify permissions together.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/signintech-gopdf)Star history chart for your README
[](https://hysenlabs.com/projects/signintech-gopdf)Was this useful?