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
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 ¶
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 ¶
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 ¶
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).