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 ¶
- type Entry
- type EntryType
- type Table
- func (t *Table) AdjustOffsets(delta int64)
- func (t *Table) Entries() iter.Seq2[int, Entry]
- func (t *Table) Get(objNum int) (Entry, bool)
- func (t *Table) Has(objNum int) bool
- func (t *Table) HasCompressed() bool
- func (t *Table) HasStreams() bool
- func (t *Table) Len() int
- func (t *Table) MaxObjectNum() int
- func (t *Table) Set(objNum int, entry Entry)
- func (t *Table) SetHasStreams(v bool)
- func (t *Table) Snapshot() map[int]Entry
- func (t *Table) SortedObjectNums() []int
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 ¶
IsCompressed returns true if this object is in an object stream.
func (Entry) StreamIndex ¶
StreamIndex returns the index within the object stream 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 (*Table) AdjustOffsets ¶
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) HasCompressed ¶
HasCompressed reports whether the table contains any compressed entries (objects stored in object streams).
func (*Table) HasStreams ¶
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) MaxObjectNum ¶
MaxObjectNum returns the highest object number in the table.
func (*Table) SetHasStreams ¶
SetHasStreams marks the table as containing xref stream sections.
func (*Table) Snapshot ¶
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 ¶
SortedObjectNums returns all object numbers in ascending order.