pdf

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 2 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pdf holds the rules about PDF bytes. It is the lowest stratum: it imports only the standard library, so the engine boundary and every embedding application can ask the same question and get the same answer.

Index

Constants

View Source
const TrailerWindow = 1024

TrailerWindow is how far from the end %%EOF may sit. The PDF specification allows at most 1024 bytes after it.

Variables

This section is empty.

Functions

func Check

func Check(path string, content []byte) error

Check returns an *IncompleteError when content has a defect, else nil. Pure.

Types

type Defect

type Defect string

Defect names why a byte sequence is not a finished PDF. The set is closed.

const (
	// DefectNone means the bytes are a finished PDF.
	DefectNone Defect = ""
	// DefectEmpty means there are no bytes at all.
	DefectEmpty Defect = "empty"
	// DefectMissingHeader means the bytes do not start with %PDF-.
	DefectMissingHeader Defect = "missing %PDF- header"
	// DefectMissingTrailer means the writer stopped before %%EOF: a compiler
	// that died, or a file read while it was still being written.
	DefectMissingTrailer Defect = "missing %%EOF trailer"
)

func Inspect

func Inspect(content []byte) Defect

Inspect returns the first defect of content, or DefectNone. Pure.

type IncompleteError

type IncompleteError struct {
	Path   string
	Size   int
	Defect Defect
}

IncompleteError refuses a PDF that has a defect. Callers match it with errors.As to tell an unfinished document from other failures.

func (*IncompleteError) Error

func (e *IncompleteError) Error() string

Jump to

Keyboard shortcuts

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