pdfium

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package pdfium adapts github.com/klippa-app/go-pdfium (MIT) over pdfium compiled to WebAssembly to the render.Rasterizer interface.

The WASM build rather than the CGO one is a requirement, not a preference: DESIGN.md §9 commits to pure Go, no CGO, single binary, cross-compiles, and rasterization is the one borrowed layer that would otherwise break that. The module runs on wazero, a pure-Go WebAssembly runtime, so `go build` for any target still produces one static binary with no toolchain on the machine.

What that costs, stated plainly:

  • **+10.0 MB of binary**, measured: cmd/pdfspec went from 10,416,128 bytes to 20,890,624 on windows/amd64. The embedded pdfium.wasm is 5,225,611 of that and wazero's compiler and the bindings are the rest, so the cost is roughly double what the module alone suggests. Nothing that imports this package can avoid it, which is why nothing else in the repo imports it — the `render` and `ocr` verbs reach it through render.Rasterizer, and a build that excluded them would drop the module.
  • **~1.4 s of one-time startup**, measured, to compile the module. Per page after that is 3–8 ms at 200 DPI. So a Rasterizer is worth reusing across pages and not worth creating per page.
  • **A second parse of the file.** pdfium brings its own parser and cannot be handed an objects.Store. A run that both extracts and renders reads the bytes twice, and the two parsers may disagree about a damaged file. That is the borrow showing through, and it is why render.Rasterizer reports its own PageCount.

Everything pdfium-specific stays in this file: no go-pdfium type appears in any signature this package exports. When the native rasterizer DESIGN.md §5 names as the flagship replacement target arrives, it is a sibling package and a one-line change in cmd, not a change to any caller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(b []byte) (render.Rasterizer, error)

New reads a PDF from b. The slice must not be modified while the Rasterizer is open; it is not copied.

func Open

func Open(path string) (render.Rasterizer, error)

Open reads the PDF at path.

The whole file is read into memory rather than streamed. pdfium's reader interface would let it seek, but crossing the WASM boundary per seek is slower than one read for any file that fits, and the files that do not fit in memory do not fit in a rasterizer's page cache either.

Types

This section is empty.

Jump to

Keyboard shortcuts

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