object

package
v1.116.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package object is the PDF object syntax (ISO 32000-2 §7.3): the values a PDF file is made of, read from and written to their textual form.

Index

Constants

This section is empty.

Variables

View Source
var ErrSyntax = fmt.Errorf("pdf syntax error: %w", altshiftErrors.ErrParseError)

ErrSyntax is text that is not PDF object syntax; it is a parse error, so an endpoint answers it as bad input.

Functions

func Append

func Append(dst []byte, value Object) ([]byte, error)

Append writes the object in PDF syntax; a stream, which can only be an indirect object, is refused here.

func AppendBody

func AppendBody(dst []byte, value Object) ([]byte, error)

AppendBody writes what goes between "N G obj" and "endobj"; a stream's /Length is set to its data's.

Types

type Array

type Array []Object

type Boolean

type Boolean bool

type Dictionary

type Dictionary map[Name]Object

func (Dictionary) Clone

func (d Dictionary) Clone() Dictionary

Clone copies the dictionary itself, not the values in it; the copy of a nil dictionary is an empty one, ready to be written to.

func (Dictionary) Integer

func (d Dictionary) Integer(key Name) (Integer, bool)

Integer returns the entry as an integer, if it is one.

func (Dictionary) Name

func (d Dictionary) Name(key Name) (Name, bool)

Name returns the entry as a name, if it is one.

func (Dictionary) Reference

func (d Dictionary) Reference(key Name) (*Reference, bool)

Reference returns the entry as a reference, if it is one.

type Indirect

type Indirect struct {
	Number     int
	Generation int
	Value      Object
}

Indirect is a numbered object as it stands in a file between "obj" and "endobj".

func ParseIndirect

func ParseIndirect(data []byte, offset int, resolveLength LengthResolver) (*Indirect, error)

ParseIndirect reads "N G obj ... endobj" at offset, its stream data included.

type Integer

type Integer int64

type LengthResolver

type LengthResolver func(length Object) (int, error)

LengthResolver turns a stream's /Length, which may be a reference, into a number of bytes.

type Name

type Name string

type Object

type Object any

Object is one of nil (null), Boolean, Integer, Real, Name, *String, Array, Dictionary, *Reference or *Stream.

func Parse

func Parse(data []byte) (Object, int, error)

Parse reads one object from the start of data and returns it with the number of bytes it took.

type Real

type Real float64

type Reference

type Reference struct {
	Number     int
	Generation int
}

Reference points at an indirect object.

type Stream

type Stream struct {
	Dictionary Dictionary
	Data       []byte
}

Stream is a dictionary and its data as stored, still encoded by whatever filters the dictionary names.

type String

type String struct {
	Value []byte
	Hex   bool
}

String is a string object; Hex records whether it was written in hexadecimal, so it is written back the same way.

Jump to

Keyboard shortcuts

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