modern-pdf-lib / PDFOperator
Class: PDFOperator
Defined in: src/core/operators/index.ts:171
A first-class representation of a single PDF content-stream operator.
In pdf-lib, operators are typed objects rather than raw strings. This class provides the same capability while remaining interoperable with the string-based operator functions above.
const op = PDFOperator.of('m', 100, 200); // moveTo(100, 200)
page.pushOperators(op.toString());Properties
name
readonlyname:string
Defined in: src/core/operators/index.ts:184
The PDF operator name.
operands
readonlyoperands: readonly (string|number)[]
Defined in: src/core/operators/index.ts:186
The operands for this operator.
Methods
toString()
toString():
string
Defined in: src/core/operators/index.ts:194
Serialize this operator to its PDF content-stream representation.
Returns
string
A string like "100 200 m\n".
of()
staticof(name, ...operands):PDFOperator
Defined in: src/core/operators/index.ts:178
Create a new operator.
Parameters
name
string
The PDF operator name (e.g. 'm', 'l', 're', 'Tj').
operands
...(string | number)[]
Numeric, string, or name operands.
Returns
PDFOperator