@peculiar/pdf-core
Version:
Core functionality library for PDF document processing and manipulation
1,429 lines (1,380 loc) • 256 kB
TypeScript
import { BufferSource as BufferSource$1 } from 'pvtsutils';
import { EventEmitter } from 'events';
import * as pkijs from 'pkijs';
import { X509Certificate } from '@peculiar/x509';
/**
* Defines commonly used character codes and sets in PDF document processing
*/
declare class CharSet {
/** Line feed character (0x0a, \n) */
static readonly newLineChar = 10;
/** Common whitespace characters including NUL, tab, LF, FF, CR, and space */
static readonly whiteSpaceChars: Uint8Array<ArrayBuffer>;
/** Less than symbol '<' (0x3c) */
static readonly lessThanChar = 60;
/** Greater than symbol '>' (0x3e) */
static readonly greaterThanChar = 62;
/** Valid hexadecimal characters (0-9, a-f, A-F) */
static readonly hexadecimalChars: Uint8Array<ArrayBuffer>;
/** Percent symbol '%' (0x25) */
static readonly percentChar = 37;
/** Space character (0x20) */
static readonly whiteSpaceChar = 32;
/** ASCII representation of 'trailer' keyword */
static readonly trailerChars: Uint8Array<ArrayBuffer>;
/** ASCII representation of 'xref' keyword */
static readonly xrefChars: Uint8Array<ArrayBuffer>;
}
type ViewReaderFindCallback = (value: number, index: number, array: Uint8Array, reader: ViewReader) => boolean;
declare class ViewReader {
view: Uint8Array;
position: number;
backward: boolean;
get isEOF(): boolean;
constructor(view: BufferSource$1);
/**
* Finds index of the first element that satisfies the callback function. If not found, returns -1.
* @param param Callback function, view or text to find
* @returns Returns index of the first element that satisfies the callback function. If not found, returns -1.
*/
findIndex(cb: ViewReaderFindCallback): number;
/**
* Finds index of the first element that satisfies the view. If not found, returns -1.
* @param view View to find
* @returns Returns index of the first element that satisfies the view. If not found, returns -1.
*/
findIndex(view: Uint8Array): number;
/**
* Finds index of the first element that satisfies the text. If not found, returns -1.
* @param text Text to find
* @returns Returns index of the first element that satisfies the text. If not found, returns -1.
*/
findIndex(text: string): number;
findIndex(param: ViewReaderFindCallback | Uint8Array | string): number;
/**
* Finds index of the first element that satisfies the callback function. If not found, returns -1.
* @param cb Callback function
* @returns Returns index of the first element that satisfies the callback function. If not found, returns -1.
*/
protected findIndexByCallback(cb: ViewReaderFindCallback): number;
/**
* Finds index of the first element that satisfies the callback function. If not found, returns -1.
* @param text Text to find
* @returns Returns index of the first element that satisfies the text. If not found, returns -1.
*/
protected findIndexByString(text: string): number;
/**
* Finds index of the first element that satisfies the callback function. If not found, returns -1.
* @param view View to find
* @returns Returns index of the first element that satisfies the view. If not found, returns -1.
*/
protected findIndexByView(view: Uint8Array): number;
readByte(): number;
readUint8(): number;
readUint16(littleEndian?: boolean): number;
readUint32(littleEndian?: boolean): number;
readString(size: number): string;
read(): Uint8Array;
read(length: number): Uint8Array;
read(text: string): Uint8Array;
read(view: Uint8Array): Uint8Array;
read(length: number): Uint8Array;
read(cb: ViewReaderFindCallback): Uint8Array;
read(param?: ViewReaderFindCallback | number | string | Uint8Array): Uint8Array;
/**
* Returns byte value at the current position, without cursor changing
* @returns Byte value
*/
get current(): number | undefined;
/**
* Moves cursor to the end of the view
*/
end(): void;
/**
* Moves cursor to the beginning of the view
*/
start(): void;
}
type ViewWriterCallback = (subarray: Uint8Array) => void;
declare class ViewWriter {
private buffer;
private totalLength;
get length(): number;
private addToLength;
write(data: BufferSource$1, cb?: ViewWriterCallback): void;
writeLine(data?: BufferSource$1): void;
writeByte(char: number): void;
writeByteLine(char: number): void;
writeString(text: string): void;
writeStringLine(text: string): void;
toArrayBuffer(): ArrayBuffer;
toUint8Array(): Uint8Array;
toString(): string;
}
declare const staticDataFF: Uint8Array<ArrayBuffer>;
declare const staticData: Uint8Array<ArrayBuffer>;
declare const algorithms: {
md5: {
name: string;
};
rc4: {
name: string;
};
sha256: {
name: string;
};
sha384: {
name: string;
};
sha512: {
name: string;
};
AesCBC: {
name: string;
};
AesECB: {
name: string;
};
};
interface globalParametersCryptFilter {
stm: {
key: ArrayBuffer;
keyType: string;
};
str: {
key: ArrayBuffer;
keyType: string;
};
}
interface clientSideParametersPublicKey {
keys: CryptoKey[];
certificates: unknown[];
algorithm: string;
encrypt?: {
seed: ArrayBuffer;
recipientsBuffer: ArrayBuffer;
};
}
declare class ActionDictionary extends PDFDictionary {
static readonly TYPE = "Action";
/**
* The type of PDF object that this dictionary describes; if
* present, shall be `Action` for an action dictionary.
*/
type: "Action" | null;
/**
* The type of action that this dictionary describes
*/
s: string;
/**
* The next action or sequence of actions that shall be performed after
* the action represented by this dictionary. The value is either a single
* action dictionary or an array of action dictionaries that shall be performed
* in order; see Note 1 for further discussion.
* @remarks PDF 1.2
*/
next: PDFDictionary | PDFArray | null;
onCreate(): void;
}
declare class AdditionalActionsDictionary extends PDFDictionary {
/**
* An action that shall be performed when the cursor enters the
* annotation’s active area.
* @remarks PDF 1.2
*/
e: PDFDictionary | null;
/**
* An action that shall be performed when the cursor exits the
* annotation’s active area.
* @remarks PDF 1.2
*/
x: PDFDictionary | null;
/**
* An action that shall be performed when the mouse button is
* pressed inside the annotation’s active area.
* @remarks PDF 1.2
*/
d: PDFDictionary | null;
/**
* An action that shall be performed when the mouse button is
* released inside the annotation’s active area.
* @remarks PDF 1.2
*/
u: PDFDictionary | null;
/**
* An action that shall be performed when the annotation receives the input focus.
* @remarks PDF 1.2
*/
fo: PDFDictionary | null;
/**
* An action that shall be performed when the annotation loses the input focus
* @remarks
* - PDF 1.2
* - widget annotations only)
*/
bl: PDFDictionary | null;
/**
* An action that shall be performed when the page containing the annotation is opened.
* @remarks PDF 1.5
*/
po: PDFDictionary | null;
/**
* An action that shall be performed when the page containing the annotation is closed.
* @remarks PDF 1.5
*/
pc: PDFDictionary | null;
/**
* An action that shall be performed when the page containing the annotation becomes visible.
* @remarks PDF 1.5
*/
pv: PDFDictionary | null;
/**
* An action that shall be performed when the page containing the annotation is no longer visible
* in the interactive PDF processor’s user interface.
* @remarks PDF 1.5
*/
pi: PDFDictionary | null;
}
interface EncryptionObject {
encrypted?: boolean;
encryptAsync(): Promise<ArrayBuffer>;
decryptAsync(): Promise<ArrayBuffer>;
}
declare abstract class PDFString extends PDFObject {
static DEFAULT_TEXT: string;
text: string;
constructor();
constructor(view: BufferSource$1);
constructor(string: PDFString);
constructor(text: string);
constructor(param?: PDFString | string | BufferSource$1);
protected onCopy(copy: PDFString): void;
protected onEqual(target: PDFObject): boolean;
}
declare abstract class PDFTextString extends PDFString implements EncryptionObject {
encrypted?: boolean;
encryptAsync(): Promise<ArrayBuffer>;
decryptAsync(): Promise<ArrayBuffer>;
encode(): Promise<string>;
decode(): Promise<string>;
toArrayBuffer(): ArrayBuffer;
toUint8Array(): Uint8Array;
protected onCreate(): void;
protected onCopy(copy: PDFTextString): void;
}
declare class DocumentSecurityStoreDictionary extends PDFDictionary {
static readonly TYPE = "DSS";
/**
* If present, shall be DSS for a document security store dictionary
*/
Type: typeof DocumentSecurityStoreDictionary.TYPE | null;
/**
* This dictionary contains Signature VRI dictionaries
*/
VRI: Maybe<PDFDictionary>;
/**
* An array of indirect reference to streams, each containing one DER encoded X.509 certificate (see RFC 5280).
* This array contains certificates that may be used in the validation of any signatures in the document.
*/
Certs: Maybe<PDFArray>;
/**
* An array of indirect references to streams, each containing a DER encoded
* Online Certificate Status Protocol (OCSP) response (see RFC 6960). This
* array contains OCSPs that may be used in the validation of the signatures
* in the document
*/
OCSPs: Maybe<PDFArray>;
/**
* An array of indirect references to streams, each containing a DER encoded
* Certificate Revocation List (CRL) (see RFC 5280). This array contains
* CRLs that may be used in the validation of the signatures in the document
*/
CRLs: Maybe<PDFArray>;
protected onCreate(): void;
}
declare class DeveloperExtensionsDictionary extends PDFDictionary {
static readonly TYPE = "DeveloperExtensions";
/**
* The type of PDF object that this dictionary describes; if present, shall
* be DeveloperExtensions.
* @remarks
* - Optional
*/
Type: typeof DeveloperExtensionsDictionary.TYPE;
/**
* The name of the PDF version to which this extension applies. The name
* shall be consistent with the syntax used for the Version entry of the catalog
* dictionary (see 7.7.2, "Document catalog dictionary").
* @remarks
* - Required
*/
BaseVersion: string;
/**
* An integer defined by the developer to denote the extension being
* used. If the developer introduces more than one extension to a
* given BaseVersion the extension level numbers assigned by that developer shall
* increase over time.
* @remarks
* - Required
*/
ExtensionLevel: number;
/**
* A URL that refers to the documentation for this extension (see Annex E,
* "PDF Name Registry").
* @remarks
* - Optional
*/
URL: PDFTextString | null;
protected onCreate(): void;
}
declare class ExtensionsDictionary extends PDFDictionary {
static readonly TYPE = "Extensions";
/**
* The type of PDF object that this dictionary describes; if present, shall
* be Extensions.
* @remarks
* - Optional
*/
Type: typeof ExtensionsDictionary.TYPE;
/**
* Developer extensions dictionary
*/
ADBE: Maybe<DeveloperExtensionsDictionary>;
}
declare class IconFitDictionary extends PDFDictionary {
/**
* The circumstances under which the icon shall be scaled inside the
* annotation rectangle:
* - A Always scale.
* - B Scale only when the icon is bigger than the annotation rectangle.
* - S Scale only when the icon is smaller than the annotation rectangle.
* - N Never scale.
*
* Default value: A.
*/
sw: "A" | "B" | "S" | "N";
/**
* The type of scaling that shall be used:
* - A Anamorphic scaling: Scale the icon to fill the annotation rectangle exactly,
* without regard to its original aspect ratio (ratio of width to height).
* - P Proportional scaling: Scale the icon to fit the width or height of the annotation
* rectangle while maintaining the icon’s original aspect ratio. If the required
* horizontal and vertical scaling factors are different, use the smaller of the two,
* centring the icon within the annotation rectangle in the other dimension.
*
* Default value: P.
*/
s: "A" | "P";
/**
* An array of two numbers that shall be between 0.0 and 1.0 indicating the
* fraction of leftover space to allocate at the left and bottom of the icon. A value of [0.0
* 0.0] shall position the icon at the bottom-left corner of the annotation rectangle. A
* value of [0.5 0.5] shall centre it within the rectangle. This entry shall be used only if
* the icon is scaled proportionally.
*
* Default value: [0.5 0.5].
*/
a: PDFArray | null;
/**
* If true, indicates that the button appearance shall be scaled to fit
* fully within the bounds of the annotation without taking into consideration the line
* width of the border. Default value: false.
* @remarks PDF 1.5
*/
fb: boolean;
}
declare enum CaptionPosition {
/**
* No icon; caption only
*/
noIcon = 0,
/**
* No caption; icon only
*/
noCaption = 1,
/**
* Caption below the icon
*/
captionBelow = 2,
/**
* Caption above the icon
*/
captionAbove = 3,
/**
* Caption to the right of the icon
*/
captionRight = 4,
/**
* Caption to the left of the icon
*/
captionLeft = 5,
/**
* Caption overlaid directly on the icon
*/
captionOverlaid = 6
}
declare class AppearanceCharacteristicsDictionary extends PDFDictionary {
/**
* The number of degrees by which the widget annotation shall be
* rotated counterclockwise relative to the page. The value shall be a multiple of
* 90. Default value: 0
*/
r: number | null;
/**
* An array of numbers that shall be in the range 0.0 to 1.0 specifying
* the colour of the widget annotation’s border. The number of array elements
* determines the colour space in which the colour shall be defined:
* - 0 No colour; transparent
* - 1 DeviceGray
* - 3 DeviceRGB
* - 4 DeviceCMYK
*/
BC: PDFArray | null;
/**
* An array of numbers that shall be in the range 0.0 to 1.0 specifying
* the colour of the widget annotation’s background. The number of array
* elements shall determine the colour space, as described for BC.
*/
BG: PDFArray | null;
/**
* The widget annotation’s normal caption, which
* shall be displayed when it is not interacting with the user.
*
* Unlike the remaining entries listed in this Table, which apply only to widget
* annotations associated with push-button fields (see 12.7.5.2.2, "Pushbuttons"),
* he CA entry may be used with any type of button field, including
* check boxes (see 12.7.5.2.3, "Check boxes") and radio buttons (12.7.5.2.4,
* "Radio buttons").
* @remarks Button fields only
*/
ca: PDFTextString | null;
/**
* The widget annotation’s rollover caption, which shall be displayed
* when the user rolls the cursor into its active area
* without pressing the mouse button.
* @remarks Push-button fields only
*/
rc: PDFTextString | null;
/**
* The widget annotation’s alternate (down) caption, which shall be displayed
* when the mouse button is pressed within its active area.
* @remarks Push-button fields only
*/
ac: PDFTextString | null;
/**
* A form XObject defining the widget annotation’s normal icon, which shall be
* displayed when it is not interacting with the user.
* @remarks
* - push-button fields only
* - shall be an indirect reference
*/
I: PDFStream | null;
/**
* A form XObject defining the widget annotation’s rollover icon, which shall be
* displayed when the user rolls the cursor into its active area without pressing
* the mouse button.
* @remarks Push-button fields only
*/
ri: PDFStream | null;
/**
* A form XObject defining the widget annotation’s alternate (down) icon, which shall
* be displayed when the mouse button is pressed within its active area.
* @remarks Push-button fields only
*/
ix: PDFStream | null;
/**
* An icon fit dictionary specifying how the widget annotation’s icon
* shall be displayed within its annotation rectangle. If present, the icon fit
* dictionary shall apply to all of the annotation’s icons (normal, rollover, and
* alternate).
* @remarks Push-button fields only
*/
if: IconFitDictionary | null;
/**
* A code indicating where to position the
* text of the widget annotation’s caption relative to its icon:
* - 0 No icon; caption only
* - 1 No caption; icon only
* - 2 Caption below the icon
* - 3 Caption above the icon
* - 4 Caption to the right of the icon
* - 5 Caption to the left of the icon
* - 6 Caption overlaid directly on the icon
*
* Default value: 0.
* @remarks Push-button fields only
*/
tp: CaptionPosition;
}
declare enum BorderStyle {
/**
* A solid rectangle surrounding the annotation
*/
solid = "S",
/**
* A dashed rectangle surrounding the annotation. The dash pattern
* may be specified by the D entry
*/
dashed = "D",
/**
* A simulated embossed rectangle that appears to be raised above
* the surface of the page
*/
beveled = "B",
/**
* A simulated engraved rectangle that appears to be recessed below
* the surface of the page
*/
insert = "I",
/**
* A single line along the bottom of the annotation rectangle
*/
underline = "U"
}
declare class BorderStyleDictionary extends PDFDictionary {
static readonly TYPE = "Border";
/**
* The type of PDF object that this dictionary describes; if present, shall
* be `Border` for a border style dictionary.
*/
type: typeof BorderStyleDictionary.TYPE | null;
/**
* The border width in points. If this value is 0, no border shall drawn.
* Default value: 1
*/
W: number;
/**
* The border style
*/
S: BorderStyle | null;
/**
* A dash array defining a pattern of dashes and gaps that shall be used in
* drawing a dashed border (border style D in the S entry). The dash array shall be
* specified in the same format as in the line dash pattern parameter of the graphics
* state (see 8.4.3.6, "Line dash pattern"). The dash phase shall not be specified and
* shall be assumed to be 0.
*/
D: PDFArray | null;
protected onCreate(): void;
}
interface WidgetOptions {
coordinate: {
x: number;
y: number;
};
}
declare enum WidgetHighlightingMode {
/**
* No highlighting.
*/
none = "N",
/**
* Invert the colours used to display the contents of the annotation rectangle.
*/
invert = "I",
/**
* Stroke the colours used to display the annotation border. That
* is, for each colour channel in the colour space used for display of the
* annotation value, colour values shall be transformed by the function
* `𝑓(𝑥) = 1 – 𝑥` for display.
*/
outline = "O",
/**
* Display the annotation’s down appearance, if any (see 12.5.5,
* "Appearance streams"). If no down appearance is defined, the contents
* of the annotation rectangle shall be offset to appear as if it were being
* pushed below the surface of the page.
*/
push = "P",
/**
* Same as P (which is preferred).
*/
toggle = "T"
}
declare class WidgetDictionary extends AnnotationDictionary {
static readonly SUBTYPE = "Widget";
/**
* The type of annotation that this dictionary describes. Shall be
* `Widget` for a widget annotation.
*/
subtype: typeof WidgetDictionary.SUBTYPE;
/**
* The annotation’s highlighting mode, the visual effect that shall be
* used when the mouse button is pressed or held down inside its active area.
*
* A highlighting mode other than P shall override any down appearance
* defined for the annotation. Default value: I
*/
h: WidgetHighlightingMode;
/**
* An appearance characteristics dictionary (see {@link AppearanceCharacteristicsDictionary}) that shall be used in
* constructing a dynamic appearance stream specifying the annotation’s visual
* presentation on the page.
*
* The name MK for this entry is of historical significance only and has no direct
* meaning
*/
MK: Maybe<AppearanceCharacteristicsDictionary>;
/**
* An action that shall be performed when the annotation is activated
* @remarks PDF 1.1
*/
A: Maybe<ActionDictionary>;
/**
* An additional-actions dictionary defining the annotation’s behavior in response
* to various trigger events (see {@link AdditionalActionsDictionary}).
* @remarks PDF 1.2
*/
aa: AdditionalActionsDictionary | null;
/**
* A border style dictionary (see {@link BorderStyleDictionary}")
* specifying the width and dash pattern that shall be used in drawing the annotation’s border.
* The annotation dictionary’s AP entry, if present, shall take precedence over the BS entry.
* @remarks PDF 1.2
*/
BS: Maybe<BorderStyleDictionary>;
/**
* An indirect reference to the widget annotation’s parent field.
* A widget annotation may have at most one parent; that is, it can be included
* in the Kids array of at most one field
* @remarks Required if this widget annotation is one of multiple children in a field; optional otherwise
*/
Parent: PDFField | null;
protected onCreate(): void;
}
declare class SingleWidgetDictionary extends WidgetDictionary implements IFieldDictionary {
ft: string;
Kids: Maybe<PDFArray>;
t: PDFTextString;
TU: PDFLiteralString | null;
tm: PDFLiteralString | null;
ff: FieldFlags | number;
V: PDFObjectTypes | null;
dv: PDFObjectTypes | null;
}
declare enum FieldFlags {
/**
* If set, an interactive PDF processor shall not allow a user to change the
* value of the field. Additionally, any associated widget annotations should
* not interact with the user; that is, they should not respond to mouse clicks
* nor change their appearance in response to mouse motions.
*/
readOnly = 1,
/**
* If set, the field shall have a value at the time it is exported by a submit-form action
*/
required = 2,
/**
* If set, the field shall not be exported by a submit-form action
*/
noExport = 4
}
interface IFieldDictionary extends PDFDictionary {
/**
* The type of field that this dictionary describes
*/
ft: string;
/**
* The field that is the immediate parent of this one
*/
Parent: PDFDictionary | null;
/**
* An array of indirect references to the immediate children of this field
*/
Kids: Maybe<PDFArray>;
/**
* The partial field name
*/
t: PDFTextString;
/**
* An alternate field name that shall be used in place
* of the actual field name wherever the field shall be identified in the
* user interface (such as in error or status messages referring to the
* field). This text is also useful when extracting the document’s contents
* in support of accessibility to users with disabilities or for other
* purposes
*/
TU: PDFLiteralString | null;
/**
* The mapping name that shall be used when
* exporting interactive form field data from the document
*/
tm: PDFLiteralString | null;
/**
* A set of flags specifying various characteristics
* of the field
*/
ff: FieldFlags | number;
/**
* The field’s value, whose format varies depending on the field type
*/
V: PDFObjectTypes | null;
/**
* The default value to which the field reverts when
* a reset-form action is executed
*/
dv: PDFObjectTypes | null;
/**
* An additional-actions dictionary defining the field’s
* behavior in response to various trigger events
*/
aa: AdditionalActionsDictionary | null;
}
declare class PDFField extends PDFDictionary implements IFieldDictionary {
/**
* The type of field that this dictionary describes
*
* - Btn Button (see 12.7.5.2, "Button fields")
* - Tx Text (see 12.7.5.3, "Text fields")
* - Ch Choice (see 12.7.5.4, "Choice fields")
* - Sig (PDF 1.3) Signature (see 12.7.5.5, "Signature fields")
*/
ft: string;
/**
* The field that is the immediate parent of this one
*
* Required if this field is the child of another in the field hierarchy; absent otherwise
*/
Parent: PDFField | null;
/**
* An array of indirect references to the immediate children of this field
*/
Kids: Maybe<PDFArray>;
/**
* The partial field name
*/
t: PDFTextString;
/**
* An alternative field name that shall be used in place of the actual field name wherever the field shall be identified in the user interface
*/
TU: PDFLiteralString | null;
/**
* The mapping name that shall be used when exporting interactive form field data from the document
*/
tm: PDFLiteralString | null;
/**
* A set of flags specifying various characteristics of the field. Default is 0
*/
ff: FieldFlags | number;
/**
* The field’s value, whose format varies depending on the field type
*/
V: PDFObjectTypes | null;
/**
* The default value to which the field reverts when a reset-form action is executed
*/
dv: PDFObjectTypes | null;
/**
* An additional-actions dictionary defining the field’s behavior in response to various trigger events
*/
aa: AdditionalActionsDictionary | null;
protected onCreate(): void;
/**
* Adds a new kid to this field. This operation can only be performed if this
* field is a non-terminal node in the field hierarchy (e.g. a non-terminal
* widget annotation).
* @param kid
*/
addKid(kid: IFieldDictionary | WidgetDictionary): boolean;
removeKid(kid: IFieldDictionary | WidgetDictionary): boolean;
/**
* Returns the full name of this field.
* @returns The full name of this field.
*/
getFullName(): string;
/**
* Remove this field from its parent. This operation can only be performed if
* this field has a parent.
*/
removeFromParent(): boolean;
}
declare enum ButtonFlags {
/**
* If set, exactly one radio button shall be selected at all times;
* selecting the currently selected button has no effect. If clear,
* clicking the selected button deselects it, leaving no button selected
*/
noToggleToOff = 16384,
/**
* If set, the field is a set of radio buttons; if clear, the field is a check box.
* This flag may be set only if the Pushbutton flag is clear.
*/
radio = 32768,
/**
* If set, the field is a push-button that does not retain a permanent value.
*/
pushbutton = 65536,
/**
* If set, a group of radio buttons within a radio button field that
* use the same value for the on state will turn on and off in unison; that
* is if one is checked, they are all checked. If clear, the buttons are
* mutually exclusive (the same behavior as HTML radio buttons).
* @remarks PDF 1.5
*/
radiosInUnison = 33554432
}
declare class ButtonDictionary extends PDFField {
ff: FieldFlags | ButtonFlags;
opt: PDFArray | null;
}
declare enum CertificateSeedValueFlags {
subject = 1,
issuer = 2,
oid = 4,
subjectDN = 8,
reserved = 16,
keyUsage = 32,
url = 64
}
declare enum KeyUsageState {
notShallBe = 0,
shallBe = 1,
notMatter = 2
}
interface CertificateSeedValueKeyUsages {
digitalSignature: KeyUsageState;
nonRepudiation: KeyUsageState;
keyEncipherment: KeyUsageState;
dataEncipherment: KeyUsageState;
keyAgreement: KeyUsageState;
keyCertSign: KeyUsageState;
cRLSign: KeyUsageState;
encipherOnly: KeyUsageState;
decipherOnly: KeyUsageState;
}
declare class CertificateSeedValueDictionary extends PDFDictionary {
/**
* The type of PDF object that this dictionary describes
*
* if present, shall be SVCert for a certificate seed value dictionary
*/
type: PDFName | null;
/**
* A set of bit flags specifying the interpretation of specific
* entries in this dictionary.
*
* A value of 1 for the flag means that a signer shall be required
* to use only the specified values for the entry.
* A value of 0 means that other values are permissible.
*/
ff: CertificateSeedValueFlags;
/**
* An array of byte strings containing DER-encoded X.509v3
* certificates that are acceptable for signing
*/
subject: PDFArray | null;
/**
* An array of dictionaries, each specifying a Subject Distinguished Name (DN)
* that shall be present within the certificate for it to be acceptable for signing
*/
subjectDN: PDFArray | null;
/**
* An array of ASCII strings, where each string specifies an acceptable
* key-usage extension that shall be present in the signing certificate
*/
keyUsage: CertificateSeedValueKeyUsages[] | null;
/**
* An array of byte strings containing DER-encoded X.509v3 certificates
* of acceptable issuers
*/
issuer: PDFArray | null;
oid: PDFLiteralString[] | null;
/**
* A URL, the use for which shall be defined by the URLType entry
*/
url: PDFLiteralString | null;
/**
* A name indicating the usage of the URL entry
*/
urlType: string | null;
}
declare class PDFBoolean extends PDFObject {
value: boolean;
static readonly NAME = ObjectTypeEnum.Boolean;
constructor();
constructor(value: boolean);
protected onWritePDF(writer: ViewWriter): void;
protected onFromPDF(reader: ViewReader): void;
protected onCopy(copy: PDFBoolean): void;
toString(): string;
protected onEqual(target: PDFObject): boolean;
}
declare class PDFName extends PDFString {
static readonly NAME = ObjectTypeEnum.Name;
static isNameChar(char: number): boolean;
protected onWritePDF(writer: ViewWriter): void;
protected onFromPDF(reader: ViewReader): void;
toString(): string;
}
type PDFDictionaryKey = PDFName | string;
declare class PDFDictionary extends PDFObject {
static readonly NAME: string;
static readonly FORMAT_SPACE = " ";
static getName(name: string | PDFName): string;
items: Map<string, PDFObjectTypes>;
constructor();
constructor(dictionary: PDFDictionary);
constructor(items: [PDFDictionaryKey, PDFObjectTypes][]);
protected onWritePDF(writer: ViewWriter): void;
protected onFromPDF(reader: ViewReader): void;
get size(): number;
/**
* Get dictionary value by name
* @param name Name to search for
*/
get(name: PDFDictionaryKey): PDFObjectTypes;
/**
* Get dictionary value by name
* @param name Name to search for
* @param type Expected type of returning value
* @param replace Replace the original item
*/
get<T extends PDFObject>(name: PDFDictionaryKey, type: abstract new () => T, replace?: boolean): T;
has(name: PDFDictionaryKey): boolean;
/**
* Set dictionary value by name
* @param name Name to search for
* @param value Value to set
*/
set(name: PDFDictionaryKey, value: PDFObjectTypes): this;
/**
* Remove dictionary value by name
* @param name Name to search for
*/
delete(name: PDFDictionaryKey): boolean;
clear(): void;
protected onCopy(copy: PDFDictionary): void;
toString(depth?: number): string;
protected onEqual(target: PDFObject): boolean;
to<T extends PDFDictionary>(type: new () => T, replace?: boolean): T;
}
declare class PDFHexString extends PDFTextString {
static readonly NAME = ObjectTypeEnum.HexString;
protected onWritePDF(writer: ViewWriter): void;
protected onFromPDF(reader: ViewReader): void;
get data(): Uint8Array;
toString(): string;
}
declare abstract class PDFIndirect extends PDFObject implements IPDFIndirect {
id: number;
generation: number;
constructor();
constructor(id: number, generation?: number);
protected onFromPDF(reader: ViewReader): void;
protected onCopy(copy: PDFIndirect): void;
protected onEqual(target: PDFObject): boolean;
}
declare class PDFIndirectReference extends PDFIndirect {
static readonly NAME = ObjectTypeEnum.IndirectReference;
protected onWritePDF(writer: ViewWriter): void;
protected onFromPDF(reader: ViewReader): void;
getValue(): PDFObjectTypes;
getValue<T extends PDFObject>(type: abstract new () => T): T;
toString(): string;
}
declare class PDFNull extends PDFObject {
static readonly NAME = ObjectTypeEnum.Null;
protected onWritePDF(writer: ViewWriter): void;
protected onFromPDF(reader: ViewReader): void;
toString(): string;
protected onEqual(target: PDFObject): boolean;
}
/**
* Represents a numeric object in a PDF document.
* Numeric objects are used to represent integers or real numbers.
*/
declare class PDFNumeric extends PDFObject {
static readonly NAME = ObjectTypeEnum.Numeric;
static assertPositiveInteger(number: PDFNumeric): asserts number is PDFNumeric;
/** The value of the numeric object */
value: number;
constructor(value?: number);
protected onWritePDF(writer: ViewWriter): void;
protected onFromPDF(reader: ViewReader): void;
toString(): string;
protected onCopy(copy: PDFNumeric): void;
protected onEqual(target: PDFObject): boolean;
}
type PDFObjectTypes = PDFNull | PDFBoolean | PDFNumeric | PDFLiteralString | PDFHexString | PDFName | PDFDictionary | PDFArray | PDFIndirectReference | PDFTextString;
declare class PDFArray extends PDFObject implements Iterable<PDFObject> {
static readonly NAME = ObjectTypeEnum.Array;
[Symbol.iterator](): Iterator<PDFObject, unknown, undefined>;
items: PDFObjectTypes[];
constructor(array: PDFArray);
constructor(...items: PDFObjectTypes[]);
/**
* The number of items in the array.
*/
get length(): number;
/**
* Retrieves an item from the array at the specified index.
* @param index - The index of the item to retrieve.
* @returns The item at the specified index, or `null` if the index is out of bounds.
*/
find(index: number): PDFObjectTypes | null;
/**
* Retrieves an item from the array at the specified index.
*
* @param index - The index of the item to retrieve.
* @param type - An optional constructor for the expected type of the item.
* @param replace - An optional flag indicating whether to convert and replace the item
* if it is not of the expected type.
* @returns The item at the specified index, or `null` if the index is out of bounds.
*/
find<T extends PDFObject>(index: number, type: abstract new () => T, replace?: boolean): T | null;
/**
* Retrieves an item from the array at the specified index.
* @param index - The index of the item to retrieve.
* @returns The item at the specified index.
* @throws RangeError - If the index is out of bounds.
*/
get(index: number): PDFObjectTypes;
/**
* Retrieves an item from the array at the specified index.
*
* @param index - The index of the item to retrieve.
* @param type - An optional constructor for the expected type of the item.
* @param replace - An optional flag indicating whether to replace the item if it is not found.
* @returns The item at the specified index.
* @throws RangeError - If the index is out of bounds.
*/
get<T extends PDFObject>(index: number, type: abstract new () => T, replace?: boolean): T;
/**
* Adds one or more items to the end of the array.
*
* @param items - The items to be added to the array. Each item must be of type `PDFObjectTypes`.
*
* @remarks
* - If an item is of type `Stream`, it will be made indirect.
* - If an item is not indirect, its `ownerElement` will be set to this array.
* - If the array has a `documentUpdate` and the item does not, the item's `documentUpdate`
* will be set to the array's `documentUpdate`.
*
* @returns void
*/
push(...items: PDFObjectTypes[]): void;
/**
* Returns the index of the specified item in the array.
*
* @param item - The item to locate in the array.
* @returns The index of the item if found; otherwise, -1.
*/
indexOf(item: PDFObjectTypes): number;
/**
* Checks if the specified item is present in the array.
*
* @param item - The item to search for in the array.
* @returns `true` if the item is found in the array, otherwise `false`.
*/
includes(item: PDFObjectTypes): boolean;
/**
* Removes elements from an array and, if necessary, inserts new elements in their place,
* returning the deleted elements.
* This method modifies the array and triggers the `modify` method if any elements are removed.
*
* @param start - The zero-based index at which to start changing the array.
* @param deleteCount - The number of elements to remove from the array. If not specified,
* all elements from the start index to the end of the array will be removed.
* @returns An array containing the deleted elements.
*/
splice(start: number, deleteCount?: number): PDFObjectTypes[];
protected onWritePDF(writer: ViewWriter): void;
protected onFromPDF(reader: ViewReader): void;
protected onCopy(copy: PDFArray): void;
toString(): string;
protected onEqual(target: PDFObject): boolean;
clear(): this;
}
declare class PDFComment extends PDFString {
static readonly NAME = ObjectTypeEnum.Comment;
protected onWritePDF(writer: ViewWriter): void;
protected onFromPDF(reader: ViewReader): void;
toString(): string;
}
declare abstract class Filter {
decodeParams: PDFDictionary | null;
abstract name: string;
constructor(decodeParams?: PDFDictionary | null);
/**
* Decode data using current filter
* @param stream The stream to work on
* @param typeString String representation of the primary type for input stream
*/
abstract decode(stream: Uint8Array): Promise<ArrayBuffer>;
/**
* Encode data using current filter
* @param stream The stream to work on
* @param typeString String representation of the primary type for input stream
*/
abstract encode(stream: Uint8Array): Promise<ArrayBuffer>;
/**
* Decode data using current filter
* @param stream The stream to work on
* @param typeString String representation of the primary type for input stream
*/
abstract decodeSync(stream: Uint8Array): ArrayBuffer;
/**
* Encode data using current filter
* @param stream The stream to work on
* @param typeString String representation of the primary type for input stream
*/
abstract encodeSync(stream: Uint8Array): ArrayBuffer;
}
interface FilterConstructor {
new (decodeParams?: PDFDictionary | null): Filter;
NAME: string;
}
declare class FilterFactory {
static filters: Map<string, FilterConstructor>;
static register(filter: FilterConstructor): void;
static get(type: string): FilterConstructor;
}
declare class ASCII85Filter extends Filter {
static readonly NAME = "ASCII85Decode";
name: string;
static get className(): string;
decode(view: Uint8Array): Promise<ArrayBuffer>;
encode(view: Uint8Array): Promise<ArrayBuffer>;
decodeSync(view: Uint8Array): ArrayBuffer;
encodeSync(view: Uint8Array): ArrayBuffer;
}
declare class ASCIIHexFilter extends Filter {
static readonly NAME = "ASCIIHexDecode";
name: string;
static get className(): string;
decode(view: Uint8Array): Promise<ArrayBuffer>;
encode(view: Uint8Array): Promise<ArrayBuffer>;
decodeSync(stream: Uint8Array): ArrayBuffer;
encodeSync(stream: Uint8Array): ArrayBuffer;
}
declare class CCITTFaxFilter extends Filter {
static readonly NAME = "CCITTFaxDecode";
name: string;
static get className(): string;
decode(view: Uint8Array): Promise<ArrayBuffer>;
encode(view: Uint8Array): Promise<ArrayBuffer>;
decodeSync(stream: Uint8Array): ArrayBuffer;
encodeSync(stream: Uint8Array): ArrayBuffer;
}
declare class CryptFilter extends Filter {
static readonly NAME = "Crypt";
name: string;
static get className(): string;
decode(view: Uint8Array): Promise<ArrayBuffer>;
encode(view: Uint8Array): Promise<ArrayBuffer>;
decodeSync(stream: BufferSource$1): ArrayBuffer;
encodeSync(stream: Uint8Array): ArrayBuffer;
}
declare class DCTFilter extends Filter {
static readonly NAME = "DCTDecode";
name: string;
static get className(): string;
decode(view: Uint8Array): Promise<ArrayBuffer>;
encode(view: Uint8Array): Promise<ArrayBuffer>;
decodeSync(stream: Uint8Array): ArrayBuffer;
encodeSync(stream: Uint8Array): ArrayBuffer;
}
interface FlateFilterBuildHuffmanCodesResult {
codes: Record<number, string>;
maximumLength: number;
}
declare class FlateFilter extends Filter {
static readonly PREDICTOR = 1;
static readonly COLUMNS = 1;
static readonly COLORS = 1;
static readonly BITS_PER_COMPONENT = 8;
static readonly FIELD_PREDICTOR = "Predictor";
static readonly FIELD_COLUMNS = "Columns";
static readonly FIELD_COLORS = "Colors";
static readonly FIELD_BITS_PER_COMPONENT = "BitsPerComponent";
static readonly NAME = "FlateDecode";
name: string;
decode(view: Uint8Array): Promise<ArrayBuffer>;
encode(view: Uint8Array): Promise<ArrayBuffer>;
decodeSync(stream: Uint8Array): ArrayBuffer;
encodeSync(stream: Uint8Array): ArrayBuffer;
}
declare class JBIG2Filter extends Filter {
static readonly NAME = "JBIG2Decode";
name: string;
static get className(): string;
decode(view: Uint8Array): Promise<ArrayBuffer>;
encode(view: Uint8Array): Promise<ArrayBuffer>;
decodeSync(stream: Uint8Array): ArrayBuffer;
encodeSync(stream: Uint8Array): ArrayBuffer;
}
declare class JPXFilter extends Filter {
static readonly NAME = "JPXDecode";
name: string;
static get className(): string;
decode(view: Uint8Array): Promise<ArrayBuffer>;
encode(view: Uint8Array): Promise<ArrayBuffer>;
decodeSync(stream: Uint8Array): ArrayBuffer;
encodeSync(stream: Uint8Array): ArrayBuffer;
}
declare class LZWFilter extends Filter {
static readonly NAME = "LZWDecode";
name: string;
static get className(): string;
decode(view: Uint8Array): Promise<ArrayBuffer>;
encode(view: Uint8Array): Promise<ArrayBuffer>;
decodeSync(stream: Uint8Array): ArrayBuffer;
encodeSync(stream: Uint8Array): ArrayBuffer;
}
interface PredictorParameters {
prevData?: Uint8Array;
colors?: number;
bitsPerComponent?: number;
columns?: number;
parameters?: PDFDictionary;
}
declare abstract class Predictor {
prevData: Uint8Array;
colors: number;
bitsPerComponent: number;
columns: number;
constructor(parameters?: PredictorParameters);
abstract decode(view: Uint8Array): Uint8Array;
abstract encode(view: Uint8Array): Uint8Array;
}
declare class PNGPredictor extends Predictor {
static readonly className = "PNGPredictor";
decode(view: Uint8Array): Uint8Array;
encode(view: Uint8Array): Uint8Array;
}
declare class RunLengthFilter extends Filter {
static readonly NAME = "RunLengthDecode";
name: string;
static get className(): string;
decode(view: Uint8Array): Promise<ArrayBuffer>;
encode(view: Uint8Array): Promise<ArrayBuffer>;
decodeSync(stream: Uint8Array): ArrayBuffer;
encodeSync(_stream: Uint8Array): ArrayBuffer;
}
declare class PDFStream extends PDFDictionary implements EncryptionObject {
static readonly NAME = ObjectTypeEnum.Stream;
protected static skipEndOfLine(reader: ViewReader): void;
length: PDFNumeric;
filter: PDFArray | PDFName | null;
decodeParams: Array<PDFDictionary | null> | null;
static readonly DEFAULT_STREAM: Uint8Array<ArrayBuffer>;
static createAsync(data: BufferSource$1, filters?: Filter[], parameters?: {
[key: string]: PDFObjectTypes;
}): Promise<PDFStream>;
private _stream;
get stream(): Uint8Array;
set stream(value: Uint8Array);
encrypted?: boolean;
constructor(stream?: BufferSource$1 | PDFStream);
protected onWritePDF(writer: ViewWriter): void;
protected onFromPDF(reader: ViewReader): void;
protected getFilters(): Filter[];
encodeSync(): ArrayBuffer;
decodeSync(): ArrayBuffer;
encode(): Promise<ArrayBuffer>;
decode(): Promise<ArrayBuffer>;
encryptAsync(): Promise<ArrayBuffer>;
decryptAsync(): Promise<ArrayBuffer>;
protected onCopy(copy: PDFStream): void;
protected onCreate(): void;
toString(): string;
protected onToStringStream(): string;
/**
* Adds the name of the filter to the Field entry
* @param name The name of the filter
* @returns
*/
addFilter(name: string): void;
to<T extends PDFDictionary>(type: new () => T, replace?: boolean): T;
clear(streamOnly?: boolean): void;
}
declare enum ObjectTypeEnum {
Null = "PDFNull",
Boolean = "PDFBoolean",
Numeric = "PDFNumeric",
Name = "PDFName",
LiteralString = "PDFLiteralString",
HexString = "PDFHexString",
IndirectReference = "PDFIndirectReference",
Array = "PDFArray",
Dictionary = "PDFDictionary",
Stream = "PDFStream",
Comment = "PDFComment"
}
declare class PDFLiteralString extends PDFTextString {
static readonly NAME = ObjectTypeEnum.LiteralString;
private static readonly ESCAPE_PATTERN;
private static readonly OCTAL_PATTERN;
private static readonly PARSE_PATTERN;
private static readonly WRITE_ESCAPE_MAP;
private static readonly READ_ESCAPE_MAP;
protected onWritePDF(writer: ViewWriter): void;
/**
* Returns the highest Unicode code point value found in the given string.
*
* @param text - The string to search for the highest Unicode code point.
* @returns The highest Unicode code point value found in the string.
*/
static getMaxUnicode(text: string): number;
protected onFromPDF(reader: ViewReader): void;
/**
* Reads string data from the provided `ViewReader` instance.
*
* This method processes the input data to handle nested parentheses and escape sequences.
* It reads until it finds a matching closing parenthesis for the initial opening parenthesis.
*
* @param reader - The `ViewReader` instance to read data from.
* @returns An object containing the read data as a `Uint8Array` and the final depth of nested parentheses.
*
* @remarks
* - The method keeps track of the depth of nested parentheses.
* - It handles escape sequences denoted by the backslash (`\`) character.
* - The method stops reading when the depth of nested parentheses reaches zero.
*/
private readStringData;
toString(): string;
}
declare class PDFDate extends PDFLiteralString {
getDateAsync(): Promise<Date>;
getDate(): Date;
setDate(date: Date): void;
constructor(param?: Date | PDFString | string | BufferSource);
static createDate(update: PDFDocument | PDFDocumentUpdate, date?: Date): PDFDate;
}
declare enum TransformMethod {
/**
* Used to detect modifications to a document relative
* to a signature field that is signed by the originator
* of a document
*/
docMDP = "DocMDP",
/**
* Used to detect modifications to a document that would
* invalidate a signature in a right-enabled document
*/
ur = "UR",
/**
* Used to detect modifications to a list of form fields
* specified in TransformParams
*/
fieldMDP = "FieldMDP"
}
declare class SignatureReferenceDictionary extends PDFDictionary {
/**
* The type of PDF object that this dictionary describes
*/
type: string;
/**
* The name of the transform method that shall guide the
* modification analysis that takes place when the signature is
* validated
*/
transformMethod: TransformMethod;
/**
* A dictionary specifying transform parameters (variable data)
* for the transform method specified by TransformMethod
*/
transformParams: PDFDictionary | null;
/**
* An indirect reference to the object in the document upon which the object
* modification analysis s