pdffixture

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package pdffixture writes small, deterministic PDF files for tests and benchmarks.

The files are hand-numbered, uncompressed and use a classic cross-reference table, so a fixture's structure is exactly what its constructor shows and does not depend on the PDF library under test. Every page carries a text marker (the tag, plus " p<N>" for multi-page documents) that independent extractors can read back.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doc

type Doc struct {
	// Version is the header version, for example "1.7" or "2.0".
	Version string
	// Info, when not empty, is the body of a document information dictionary referenced from the trailer.
	Info string
	// Objs holds the serialized object bodies.
	Objs [][]byte
}

Doc is a list of PDF object bodies. Object n is Objs[n-1]; object 1 is always the catalog.

func Attachment

func Attachment(tag string) *Doc

Attachment is a one-page document with an embedded file "note.txt".

func EmptySignatureField added in v0.2.0

func EmptySignatureField(tag string) *Doc

EmptySignatureField is an unsigned PDF with an ordinary unpopulated signature field.

func FitMarkStreams added in v0.2.0

func FitMarkStreams() *Doc

FitMarkStreams puts a color operator and its following number in separate streams without trailing/leading whitespace. A raw byte join loses the visible blue mark's color.

func FitMarks added in v0.2.0

func FitMarks(prefix string) *Doc

FitMarks places blue visible ink and red hidden ink around a 50-point square visible frame. Prefix supplies graphics-state escape controls. The source has a real font resource and text decoys.

func Form

func Form(tag string) *Doc

Form is a two-page document ("<tag> p1", "<tag> p2") with an AcroForm: a non-widget parent field "grp" whose two child widgets "a" and "b" sit on different pages, and a merged field/widget "dup". Two Form documents therefore carry the same qualified field names.

func ImageRich

func ImageRich(tag string, payload int) *Doc

ImageRich is a one-page document marked tag whose page references a DeviceGray image XObject of about payload bytes (a multiple of 1024, at least 1024) of incompressible pseudo-random data seeded from the tag, a stand-in for a scanned page: distinct tags give distinct images, so an optimizer cannot merge them.

func LegacyDests

func LegacyDests(tag string) *Doc

LegacyDests is NamedDests expressed with the legacy catalog /Dests dictionary and name objects.

func Links(tag string) *Doc

Links is a two-page document ("<tag> p1", "<tag> p2") whose link annotations point directly at the other page, through /Dest and through GoTo actions, forwards and backwards. Every annotation names its own page in /P; page 1 has a direct /Annots array and page 2 an indirect one.

func NamedDests

func NamedDests(tag string) *Doc

NamedDests is a two-page document ("<tag> p1", "<tag> p2") with name-tree destinations chap1 and chap2 that link annotations use through /Dest strings and GoTo actions.

func NestedBoxes

func NestedBoxes(tag string) *Doc

NestedBoxes is a two-page document ("<tag> p1", "<tag> p2") in a two-level page tree: the root supplies MediaBox [0 0 612 792], CropBox [50 60 500 700] and Rotate 90; an intermediate node holding page 2 overrides only CropBox with [10 10 300 400].

func Outlined

func Outlined(tag string) *Doc

Outlined is a two-page document ("<tag> p1", "<tag> p2") with an outline, page mode and language.

func PageActions

func PageActions(tag string) *Doc

PageActions is a two-page document ("<tag> p1", "<tag> p2") whose pages carry /AA page-open actions that jump to the other page, and no /Annots.

func Pages

func Pages(tag string, count int) *Doc

Pages is an annotation-free document of count pages marked "<tag> p<N>".

func Plain

func Plain(tag string) *Doc

Plain is a one-page document marked tag with a US Letter MediaBox.

func Resource

func Resource(pages int, label func(index int) string) *Doc

Resource is a generated-pages document: page i shows label(i) on an A4 page when i is even and on a US Letter page when i is odd, all sharing one font object.

func SignatureValue added in v0.2.0

func SignatureValue(tag string) *Doc

SignatureValue is a PDF with a populated signature field. Its placeholder value is intentionally not a cryptographically valid signature; it tests refusal of reachable signature state.

func Tagged

func Tagged(tag string) *Doc

Tagged is a one-page document with a structure tree, /MarkInfo and a page /StructParents entry.

func Titled

func Titled(tag string) *Doc

Titled is Plain with a document information dictionary carrying a title and author.

func URILink(tag, target, base string, isMap bool) *Doc

URILink has one unpainted URI link and an optional catalog URI/Base. Target and base are PDF literal-string contents, allowing tests to exercise escapes without a library serializer.

func Versioned

func Versioned(tag, header, catalog string) *Doc

Versioned is Plain with the given header version and, when catalog is not empty, a catalog /Version.

func WithBoxes

func WithBoxes(tag string, inherited PageBoxes, own ...PageBoxes) *Doc

WithBoxes is a document with one page per entry of own ("<tag> p<N>"; a single page when own is empty). The marker sits near the lower-left corner of the MediaBox. Entries of inherited go on the root page-tree node, where pages without their own entry inherit them; UserUnit is not inheritable and is ignored there.

func (*Doc) Bytes

func (d *Doc) Bytes() []byte

Bytes serializes the document.

func (*Doc) WriteFile

func (d *Doc) WriteFile(path string) error

WriteFile writes the document to path with owner-only permissions.

type PageBoxes

type PageBoxes struct {
	// Media, Crop are arrays such as "[0 0 612 792]".
	Media, Crop string
	// Rotate and UserUnit are numbers such as "90" and "2.5".
	Rotate, UserUnit string
}

PageBoxes lists page-dictionary entries as PDF source text, so malformed values can be expressed. An empty field omits the entry.

Jump to

Keyboard shortcuts

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