xref

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package xref provides cross-reference table types shared between reader and writer.

The cross-reference table maps object numbers to their locations in the PDF file. PDF supports two formats:

  • Traditional xref tables (PDF 1.0+)
  • Xref streams (PDF 1.5+)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	// Offset is the byte offset in the file for in-use objects,
	// or the object stream number for compressed objects.
	Offset int64

	// Generation is the generation number for in-use/free objects,
	// or the index within the object stream for compressed objects.
	Generation int

	// Type indicates the entry type.
	Type EntryType
}

Entry represents a single entry in the cross-reference table.

func (Entry) IsCompressed

func (e Entry) IsCompressed() bool

IsCompressed returns true if this object is in an object stream.

func (Entry) IsFree

func (e Entry) IsFree() bool

IsFree returns true if this is a free entry.

func (Entry) IsInUse

func (e Entry) IsInUse() bool

IsInUse returns true if this is an in-use entry at a byte offset.

func (Entry) StreamIndex

func (e Entry) StreamIndex() int

StreamIndex returns the index within the object stream for compressed entries. Returns 0 for non-compressed entries.

func (Entry) StreamNum

func (e Entry) StreamNum() int

StreamNum returns the object stream number for compressed entries. Returns 0 for non-compressed entries.

type EntryType

type EntryType byte

EntryType represents the type of an xref entry.

const (
	// EntryFree indicates a free (deleted) object.
	// Offset points to the next free object number.
	EntryFree EntryType = 'f'

	// EntryInUse indicates an in-use object at the given byte offset.
	EntryInUse EntryType = 'n'

	// EntryCompressed indicates an object stored in an object stream.
	// Offset is the object stream number, Generation is the index within.
	EntryCompressed EntryType = 'c'
)

type Table

type Table struct {

	// Size is the total number of objects (from trailer /Size).
	Size int
	// contains filtered or unexported fields
}

Table represents a complete cross-reference table.

func NewTable

func NewTable() *Table

NewTable creates an empty xref table.

func (*Table) AdjustOffsets

func (t *Table) AdjustOffsets(delta int64)

AdjustOffsets adds delta to the byte offset of every in-use entry. This corrects xref tables whose offsets were calculated relative to a position other than byte 0 (e.g. files with leading junk before %PDF).

func (*Table) Entries

func (t *Table) Entries() iter.Seq2[int, Entry]

Entries returns an iterator over all entries in the table.

func (*Table) Get

func (t *Table) Get(objNum int) (Entry, bool)

Get returns the entry for the given object number.

func (*Table) Has

func (t *Table) Has(objNum int) bool

Has reports whether an entry exists for the given object number.

func (*Table) HasCompressed

func (t *Table) HasCompressed() bool

HasCompressed reports whether the table contains any compressed entries (objects stored in object streams).

func (*Table) HasStreams

func (t *Table) HasStreams() bool

HasStreams reports whether any cross-reference section used the stream format (PDF 1.5+). When true, incremental updates should also use xref streams to remain conformant.

func (*Table) Len

func (t *Table) Len() int

Len returns the number of entries in the table.

func (*Table) MaxObjectNum

func (t *Table) MaxObjectNum() int

MaxObjectNum returns the highest object number in the table.

func (*Table) Set

func (t *Table) Set(objNum int, entry Entry)

Set adds or updates an entry.

func (*Table) SetHasStreams

func (t *Table) SetHasStreams(v bool)

SetHasStreams marks the table as containing xref stream sections.

func (*Table) Snapshot

func (t *Table) Snapshot() map[int]Entry

Snapshot returns a shallow copy of all entries as a map. The caller owns the returned map and may mutate it freely.

func (*Table) SortedObjectNums

func (t *Table) SortedObjectNums() []int

SortedObjectNums returns all object numbers in ascending order.

Jump to

Keyboard shortcuts

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