parser

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

CRC: crc-Parser.md

CRC: crc-Filter.md | Seq: seq-open.md, seq-salvage.md

CRC: crc-Parser.md

CRC: crc-Parser.md

CRC: crc-Parser.md | Seq: seq-open.md, seq-salvage.md

CRC: crc-Parser.md

CRC: crc-Parser.md

Index

Constants

This section is empty.

Variables

View Source
var ErrEncrypted = errors.New("parser: encrypted PDFs are not supported")

ErrEncrypted is returned when the PDF carries an /Encrypt entry. pdftext refuses encrypted PDFs without attempting decryption.

Functions

func Decode

func Decode(filters []Name, params []Dict, encoded []byte) ([]byte, error)

Decode applies a PDF stream's filter chain to encoded bytes.

func DecodeStream

func DecodeStream(s Stream) ([]byte, error)

DecodeStream decodes a Stream using the filter chain declared in its dictionary. Applies /Filter (may be a single Name or an Array) with /DecodeParms (matching single Dict or Array) in order.

func IntValue

func IntValue(o Object) (int64, bool)

IntValue returns an integer-valued Object as int64, plus ok.

func ReadContent

func ReadContent(src []byte, visit func(ContentOp) error) error

ReadContent parses a decoded content-stream byte slice and calls visit for every operator encountered. Errors from visit abort the walk and are returned.

Types

type Array

type Array []Object

type Bool

type Bool bool

type ContentOp

type ContentOp struct {
	Operands []Object
	Op       string
}

ContentOp is one PDF content-stream instruction: a list of operand objects followed by an operator name.

type Dict

type Dict map[Name]Object

func DictOf

func DictOf(o Object) (Dict, bool)

DictOf returns a Dict-valued Object plus ok.

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document is a parsed PDF's object graph with lazy indirect-reference resolution.

func Parse

func Parse(r io.ReaderAt, size int64) (*Document, error)

Parse reads a PDF from r into a Document. Handles traditional xref, cross-reference streams, incremental updates, and lenient recovery for malformed xref tables. Returns ErrEncrypted if the PDF is encrypted (plaintext store-out policy; see spec R9).

func (*Document) Deref

func (d *Document) Deref(o Object) (Object, error)

Deref resolves an Object that may be a Ref into a concrete object. Non-Ref objects pass through unchanged.

func (*Document) Resolve

func (d *Document) Resolve(ref Ref) (Object, error)

Resolve looks up an indirect reference and returns the target object. Returns Null{} for unknown objects (the PDF spec permits this and some malformed files rely on it).

func (*Document) Root

func (d *Document) Root() (Dict, error)

Root returns the document catalog, following /Root from the trailer.

func (*Document) Trailer

func (d *Document) Trailer() Dict

Trailer returns the PDF's trailer dictionary. May be nil when only lenient recovery produced the object table and the trailer keyword was missing.

type Integer

type Integer int64

type Name

type Name string

Name is a PDF name object. Stored without the leading '/'.

func NameOf

func NameOf(o Object) (Name, bool)

NameOf returns a Name-valued Object plus ok.

type Null

type Null struct{}

type Object

type Object interface {
	// contains filtered or unexported methods
}

Object is any PDF value. All concrete object types implement it.

type Real

type Real float64

type Ref

type Ref struct {
	Num uint32
	Gen uint16
}

Ref is an indirect reference.

type Stream

type Stream struct {
	Dict Dict
	Raw  []byte
}

Stream is a PDF stream: a dictionary plus the raw (still-encoded) bytes. Decode via Decode using Dict["Filter"] and Dict["DecodeParms"].

type String

type String struct {
	Value []byte
	Hex   bool
}

String is a PDF string. Value holds the decoded bytes (after escape processing). Hex is true when the source form was <...>.

Jump to

Keyboard shortcuts

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