incremental

package
v2.9.0 Latest Latest
Warning

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

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

Documentation

Overview

Package incremental writes PDF incremental updates: new and replacement objects appended after the original bytes, followed by a fresh xref section and trailer that chains to the previous one via /Prev.

It centralises the trailer/xref/encryption invariants that every incremental writer in this module must uphold — most importantly carrying the document /ID forward and encrypting appended strings and streams when the source PDF is encrypted. Hand-rolling these per call site previously caused encrypted attachments to be written in the clear with a dropped /ID.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UsesXRefStream added in v2.7.0

func UsesXRefStream(pdfBytes []byte) bool

UsesXRefStream reports whether the PDF's active cross-reference section is a cross-reference stream (PDF 1.5+) rather than a classical xref table. Returns false when no startxref can be located.

Types

type Update

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

Update accumulates an incremental update against an original PDF.

Object numbers are reserved with Reserve, bodies are appended with AddObject (dictionaries) or AddStream (stream objects), and the finished PDF is produced by Bytes. When the source document is encrypted (enc != nil) all appended strings and stream data are encrypted with the document's per-object keys.

func New

func New(original []byte, trailer *parse.TrailerInfo, enc *types.PDFEncryption) (*Update, error)

New starts an incremental update against original using the parsed trailer. If enc is non-nil, appended content is encrypted for the document.

func (*Update) AddObject

func (u *Update) AddObject(num, gen int, body []byte) error

AddObject appends a dictionary (non-stream) object. body must be the full object body including the surrounding << >>. Any string values it contains are encrypted when the document is encrypted.

func (*Update) AddStream

func (u *Update) AddStream(num, gen int, dict, data []byte) error

AddStream appends a stream object. dict is the stream dictionary including the surrounding << >> but WITHOUT a /Length entry (it is computed and injected here). When the document is encrypted, data and any strings in dict are encrypted, and /Length reflects the encrypted byte count.

func (*Update) Bytes

func (u *Update) Bytes() ([]byte, error)

Bytes finalises the update: xref section, trailer (preserving Root/Info/ Encrypt/ID, chaining via /Prev) and startxref.

The cross-reference form mirrors the source: a classical xref table + trailer when the previous section is a table, a cross-reference stream when the previous section is a stream (ISO 32000-1 §7.5.8.4 requires updates to a pure xref-stream file to also use xref streams).

func (*Update) Encrypted

func (u *Update) Encrypted() bool

Encrypted reports whether appended content will be encrypted.

func (*Update) Reserve

func (u *Update) Reserve() int

Reserve allocates and returns the next free object number. Callers reserve all numbers they need before adding bodies so forward references resolve.

Jump to

Keyboard shortcuts

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