pdf-lite 1.6.4 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acroform/appearance/pdf-button-appearance-stream.js +1 -1
- package/dist/acroform/appearance/pdf-text-appearance-stream.js +42 -25
- package/dist/acroform/fields/pdf-button-form-field.d.ts +11 -2
- package/dist/acroform/fields/pdf-button-form-field.js +76 -37
- package/dist/acroform/fields/pdf-choice-form-field.js +2 -2
- package/dist/acroform/fields/pdf-form-field.d.ts +15 -9
- package/dist/acroform/fields/pdf-form-field.js +123 -46
- package/dist/acroform/fields/pdf-text-form-field.js +2 -2
- package/dist/acroform/pdf-acro-form.d.ts +1 -0
- package/dist/acroform/pdf-acro-form.js +15 -4
- package/dist/acroform/xfa/pdf-xfa-data.d.ts +2 -1
- package/dist/acroform/xfa/pdf-xfa-data.js +36 -28
- package/dist/annotations/pdf-annotation.d.ts +1 -1
- package/dist/annotations/pdf-annotation.js +16 -2
- package/dist/core/objects/pdf-array.d.ts +6 -1
- package/dist/core/objects/pdf-array.js +3 -0
- package/dist/core/objects/pdf-boolean.d.ts +6 -2
- package/dist/core/objects/pdf-boolean.js +3 -0
- package/dist/core/objects/pdf-comment.d.ts +6 -2
- package/dist/core/objects/pdf-comment.js +3 -0
- package/dist/core/objects/pdf-date.d.ts +4 -0
- package/dist/core/objects/pdf-date.js +3 -0
- package/dist/core/objects/pdf-dictionary.d.ts +5 -0
- package/dist/core/objects/pdf-dictionary.js +16 -0
- package/dist/core/objects/pdf-hexadecimal.d.ts +6 -2
- package/dist/core/objects/pdf-hexadecimal.js +3 -0
- package/dist/core/objects/pdf-indirect-object.d.ts +8 -1
- package/dist/core/objects/pdf-indirect-object.js +14 -0
- package/dist/core/objects/pdf-name.d.ts +6 -2
- package/dist/core/objects/pdf-name.js +3 -0
- package/dist/core/objects/pdf-null.d.ts +5 -2
- package/dist/core/objects/pdf-null.js +3 -0
- package/dist/core/objects/pdf-number.d.ts +6 -1
- package/dist/core/objects/pdf-number.js +3 -0
- package/dist/core/objects/pdf-object-reference.d.ts +5 -0
- package/dist/core/objects/pdf-object-reference.js +7 -0
- package/dist/core/objects/pdf-object.d.ts +1 -0
- package/dist/core/objects/pdf-start-xref.d.ts +6 -1
- package/dist/core/objects/pdf-start-xref.js +3 -0
- package/dist/core/objects/pdf-stream.d.ts +8 -0
- package/dist/core/objects/pdf-stream.js +7 -0
- package/dist/core/objects/pdf-string.d.ts +8 -2
- package/dist/core/objects/pdf-string.js +9 -0
- package/dist/core/objects/pdf-trailer.d.ts +7 -0
- package/dist/core/objects/pdf-trailer.js +3 -0
- package/dist/core/objects/pdf-xref-table.d.ts +31 -5
- package/dist/core/objects/pdf-xref-table.js +23 -0
- package/dist/pdf/pdf-document.d.ts +7 -0
- package/dist/pdf/pdf-document.js +6 -0
- package/dist/pdf/pdf-revision.d.ts +4 -0
- package/dist/pdf/pdf-revision.js +6 -0
- package/dist/utils/iterable-readable-stream.d.ts +2 -0
- package/dist/utils/iterable-readable-stream.js +8 -1
- package/dist/utils/xml.d.ts +9 -0
- package/dist/utils/xml.js +59 -0
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PdfIndirectObject } from '../../core/objects/pdf-indirect-object.js';
|
|
2
|
+
import { Xml } from '../../utils/xml.js';
|
|
2
3
|
/**
|
|
3
4
|
* Wraps an XFA datasets stream as a typed PDF indirect object.
|
|
4
5
|
* Provides methods to read/write XML and update individual field values.
|
|
@@ -26,15 +27,10 @@ export class PdfXfaData extends PdfIndirectObject {
|
|
|
26
27
|
this.xml = xml;
|
|
27
28
|
}
|
|
28
29
|
getFieldValue(name) {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const leafSegment = segments[segments.length - 1];
|
|
32
|
-
const leafName = leafSegment.replace(/\[\d+\]$/, '');
|
|
33
|
-
if (leafName.startsWith('#'))
|
|
30
|
+
const leafName = PdfXfaData.leafName(name);
|
|
31
|
+
if (!leafName)
|
|
34
32
|
return null;
|
|
35
|
-
|
|
36
|
-
const match = xml.match(contentRegex);
|
|
37
|
-
return match ? match[1] : null;
|
|
33
|
+
return Xml.getElementContent(this.xml, leafName);
|
|
38
34
|
}
|
|
39
35
|
importData(fields) {
|
|
40
36
|
for (const field in fields) {
|
|
@@ -45,28 +41,40 @@ export class PdfXfaData extends PdfIndirectObject {
|
|
|
45
41
|
}
|
|
46
42
|
}
|
|
47
43
|
static updateFieldValue(xml, fieldName, value) {
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
const leafName = leafSegment.replace(/\[\d+\]$/, '');
|
|
51
|
-
if (leafName.startsWith('#'))
|
|
44
|
+
const leaf = PdfXfaData.leafName(fieldName);
|
|
45
|
+
if (!leaf)
|
|
52
46
|
return xml;
|
|
53
|
-
const escapedValue = value
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
return xml
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
47
|
+
const escapedValue = Xml.escapeValue(value);
|
|
48
|
+
// Try updating an existing element
|
|
49
|
+
const updated = Xml.setElementContent(xml, leaf, escapedValue);
|
|
50
|
+
if (updated !== xml)
|
|
51
|
+
return updated;
|
|
52
|
+
// Element doesn't exist — create the missing hierarchy
|
|
53
|
+
const segments = PdfXfaData.cleanSegments(fieldName);
|
|
54
|
+
if (segments.length === 0)
|
|
55
|
+
return xml;
|
|
56
|
+
// Find the deepest existing ancestor (skip the leaf itself)
|
|
57
|
+
let insertAt = -1;
|
|
58
|
+
for (let i = segments.length - 2; i >= 0; i--) {
|
|
59
|
+
if (Xml.hasElement(xml, segments[i])) {
|
|
60
|
+
insertAt = i;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
66
63
|
}
|
|
67
|
-
|
|
64
|
+
if (insertAt === -1)
|
|
65
|
+
return xml;
|
|
66
|
+
const childXml = Xml.wrapInElements(escapedValue, segments.slice(insertAt + 1));
|
|
67
|
+
return Xml.insertChild(xml, segments[insertAt], childXml);
|
|
68
|
+
}
|
|
69
|
+
static leafName(fieldName) {
|
|
70
|
+
const segments = fieldName.split('.');
|
|
71
|
+
const leaf = segments[segments.length - 1].replace(/\[\d+\]$/, '');
|
|
72
|
+
return leaf.startsWith('#') ? null : leaf;
|
|
68
73
|
}
|
|
69
|
-
static
|
|
70
|
-
return
|
|
74
|
+
static cleanSegments(fieldName) {
|
|
75
|
+
return fieldName
|
|
76
|
+
.split('.')
|
|
77
|
+
.map((s) => s.replace(/\[\d+\]$/, ''))
|
|
78
|
+
.filter((s) => !s.startsWith('#'));
|
|
71
79
|
}
|
|
72
80
|
}
|
|
@@ -31,7 +31,7 @@ export declare class PdfAnnotation extends PdfIndirectObject<PdfDictionary<{
|
|
|
31
31
|
Kids: PdfArray<PdfObjectReference>;
|
|
32
32
|
Rect: PdfArray<PdfNumber>;
|
|
33
33
|
F: PdfNumber;
|
|
34
|
-
AP?: PdfAppearanceStreamDictionary;
|
|
34
|
+
AP?: PdfAppearanceStreamDictionary | PdfObjectReference;
|
|
35
35
|
P?: PdfObjectReference;
|
|
36
36
|
Parent?: PdfObjectReference<PdfPage>;
|
|
37
37
|
A?: PdfDictionary<{
|
|
@@ -87,10 +87,24 @@ export class PdfAnnotation extends PdfIndirectObject {
|
|
|
87
87
|
this.flags_.locked = value;
|
|
88
88
|
}
|
|
89
89
|
get appearanceStreamDict() {
|
|
90
|
-
const apDict = this.content.get('AP')
|
|
90
|
+
const apDict = this.content.get('AP');
|
|
91
91
|
if (!apDict)
|
|
92
92
|
return null;
|
|
93
|
-
|
|
93
|
+
if (apDict instanceof PdfObjectReference) {
|
|
94
|
+
const resolved = apDict.resolve();
|
|
95
|
+
if (resolved.content instanceof PdfDictionary) {
|
|
96
|
+
return resolved.content;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
throw new Error('Invalid AP reference: not a dictionary');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (apDict instanceof PdfDictionary) {
|
|
103
|
+
return apDict;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
throw new Error('Invalid AP entry: must be a dictionary or reference');
|
|
107
|
+
}
|
|
94
108
|
}
|
|
95
109
|
set appearanceStreamDict(dict) {
|
|
96
110
|
if (dict === null) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PdfObjectReference } from '../index.js';
|
|
2
|
+
import { PdfToken } from '../tokens/token.js';
|
|
2
3
|
import { PdfWhitespaceToken } from '../tokens/whitespace-token.js';
|
|
3
4
|
import { PdfIndirectObject } from './pdf-indirect-object.js';
|
|
4
5
|
import { PdfObject } from './pdf-object.js';
|
|
@@ -9,8 +10,12 @@ export declare class PdfArray<T extends PdfObject = PdfObject> extends PdfObject
|
|
|
9
10
|
static refs(items: PdfIndirectObject[]): PdfArray<PdfObjectReference>;
|
|
10
11
|
get length(): number;
|
|
11
12
|
push(item: T): void;
|
|
13
|
+
toJSON(): {
|
|
14
|
+
type: string;
|
|
15
|
+
items: object[];
|
|
16
|
+
};
|
|
12
17
|
get isTrailingDelimited(): boolean;
|
|
13
|
-
protected tokenize():
|
|
18
|
+
protected tokenize(): PdfToken[];
|
|
14
19
|
cloneImpl(): this;
|
|
15
20
|
setModified(modified?: boolean): void;
|
|
16
21
|
isModified(): boolean;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PdfToken } from '../tokens/token.js';
|
|
2
2
|
import { PdfObject } from './pdf-object.js';
|
|
3
3
|
export declare class PdfBoolean extends PdfObject {
|
|
4
4
|
value: boolean;
|
|
5
5
|
constructor(value: boolean);
|
|
6
|
-
protected tokenize():
|
|
6
|
+
protected tokenize(): PdfToken[];
|
|
7
7
|
cloneImpl(): this;
|
|
8
|
+
toJSON(): {
|
|
9
|
+
type: string;
|
|
10
|
+
value: boolean;
|
|
11
|
+
};
|
|
8
12
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ByteArray } from '../../types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PdfToken } from '../tokens/token.js';
|
|
3
3
|
import { PdfObject } from './pdf-object.js';
|
|
4
4
|
export declare class PdfComment extends PdfObject {
|
|
5
5
|
static EOF: PdfComment;
|
|
@@ -13,6 +13,10 @@ export declare class PdfComment extends PdfObject {
|
|
|
13
13
|
isVersionComment(): boolean;
|
|
14
14
|
isEOFComment(): boolean;
|
|
15
15
|
static versionComment(version: string): PdfComment;
|
|
16
|
-
|
|
16
|
+
toJSON(): {
|
|
17
|
+
type: string;
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
protected tokenize(): PdfToken[];
|
|
17
21
|
cloneImpl(): this;
|
|
18
22
|
}
|
|
@@ -30,6 +30,9 @@ export class PdfComment extends PdfObject {
|
|
|
30
30
|
comment.postTokens = [PdfWhitespaceToken.NEWLINE];
|
|
31
31
|
return comment;
|
|
32
32
|
}
|
|
33
|
+
toJSON() {
|
|
34
|
+
return { type: 'comment', value: this.asString() };
|
|
35
|
+
}
|
|
33
36
|
tokenize() {
|
|
34
37
|
return [new PdfCommentToken(this.raw)];
|
|
35
38
|
}
|
|
@@ -15,6 +15,9 @@ export class PdfDate extends PdfString {
|
|
|
15
15
|
const dateString = `D:${year}${month}${day}${hours}${minutes}${seconds}${sign}${offsetHours}'${offsetMins}'`;
|
|
16
16
|
super(dateString);
|
|
17
17
|
}
|
|
18
|
+
toJSON() {
|
|
19
|
+
return { type: 'date', value: this.date.toISOString() };
|
|
20
|
+
}
|
|
18
21
|
get date() {
|
|
19
22
|
const str = new TextDecoder().decode(this.raw);
|
|
20
23
|
const match = /^D:(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})([+\-Z])?(\d{2})?'?(\d{2})?'?/.exec(str);
|
|
@@ -10,6 +10,7 @@ export declare class PdfDictionary<T extends PdfDictionaryEntries = PdfDictionar
|
|
|
10
10
|
constructor(entries?: T | PdfDictionaryMap);
|
|
11
11
|
keys(): PdfName[];
|
|
12
12
|
get<K extends Extract<keyof T, string>>(key: PdfName<K> | K): T[K] | undefined;
|
|
13
|
+
move<K extends Extract<keyof T, string>>(fromKey: PdfName<K> | K, toKey: PdfName<K> | K): void;
|
|
13
14
|
set<K extends Extract<keyof T, string>>(key: PdfName<K> | K, value: T[K]): void;
|
|
14
15
|
delete<K extends Extract<keyof T, string>>(key: PdfName<K> | K): void;
|
|
15
16
|
has<K extends Extract<keyof T, string>>(key: PdfName<K> | K): boolean;
|
|
@@ -21,6 +22,10 @@ export declare class PdfDictionary<T extends PdfDictionaryEntries = PdfDictionar
|
|
|
21
22
|
* Each entry is a tuple of [key string, value].
|
|
22
23
|
*/
|
|
23
24
|
entries(): IterableIterator<[string, PdfObject | undefined]>;
|
|
25
|
+
toJSON(): {
|
|
26
|
+
type: string;
|
|
27
|
+
entries: Record<string, object>;
|
|
28
|
+
};
|
|
24
29
|
get isTrailingDelimited(): boolean;
|
|
25
30
|
protected tokenize(): PdfToken[];
|
|
26
31
|
/** Factory-style type conversion: constructs a new instance passing `this` as the first argument */
|
|
@@ -31,6 +31,13 @@ export class PdfDictionary extends PdfObject {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
move(fromKey, toKey) {
|
|
35
|
+
const value = this.get(fromKey);
|
|
36
|
+
if (value !== undefined) {
|
|
37
|
+
this.set(toKey, value);
|
|
38
|
+
this.delete(fromKey);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
34
41
|
set(key, value) {
|
|
35
42
|
const currentValue = this.get(key);
|
|
36
43
|
if (currentValue !== value && !currentValue?.equals(value)) {
|
|
@@ -95,6 +102,15 @@ export class PdfDictionary extends PdfObject {
|
|
|
95
102
|
const entries = Array.from(this.#entries.entries()).map(([key, value]) => [key.value, value]);
|
|
96
103
|
return entries[Symbol.iterator]();
|
|
97
104
|
}
|
|
105
|
+
toJSON() {
|
|
106
|
+
const entries = {};
|
|
107
|
+
for (const [key, value] of this.entries()) {
|
|
108
|
+
if (value) {
|
|
109
|
+
entries[key] = value.toJSON();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { type: 'dictionary', entries };
|
|
113
|
+
}
|
|
98
114
|
get isTrailingDelimited() {
|
|
99
115
|
return true;
|
|
100
116
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ByteArray } from '../../types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PdfToken } from '../tokens/token.js';
|
|
3
3
|
import { PdfObject } from './pdf-object.js';
|
|
4
4
|
export declare class PdfHexadecimal extends PdfObject {
|
|
5
5
|
/**
|
|
@@ -19,7 +19,11 @@ export declare class PdfHexadecimal extends PdfObject {
|
|
|
19
19
|
get bytes(): ByteArray;
|
|
20
20
|
toHexBytes(): ByteArray;
|
|
21
21
|
toHexString(): string;
|
|
22
|
+
toJSON(): {
|
|
23
|
+
type: string;
|
|
24
|
+
value: string;
|
|
25
|
+
};
|
|
22
26
|
get isTrailingDelimited(): boolean;
|
|
23
|
-
protected tokenize():
|
|
27
|
+
protected tokenize(): PdfToken[];
|
|
24
28
|
cloneImpl(): this;
|
|
25
29
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PdfToken } from '../tokens/token.js';
|
|
1
2
|
import { PdfNull } from './pdf-null.js';
|
|
2
3
|
import { PdfObject } from './pdf-object.js';
|
|
3
4
|
import { PdfObjectReference } from './pdf-object-reference.js';
|
|
@@ -25,9 +26,15 @@ export declare class PdfIndirectObject<T extends PdfObject = PdfObject> extends
|
|
|
25
26
|
static createPlaceholder<T extends PdfObject>(objectNumber?: number, generationNumber?: number, content?: T): PdfIndirectObject<T extends unknown ? PdfNull : T>;
|
|
26
27
|
inPdf(): boolean;
|
|
27
28
|
matchesReference(ref?: PdfObjectReference): boolean;
|
|
28
|
-
protected tokenize():
|
|
29
|
+
protected tokenize(): PdfToken[];
|
|
29
30
|
copyFrom(other: PdfIndirectObject): void;
|
|
30
31
|
cloneImpl(): this;
|
|
32
|
+
toJSON(): {
|
|
33
|
+
type: string;
|
|
34
|
+
objectNumber: number;
|
|
35
|
+
generationNumber: number;
|
|
36
|
+
content: object;
|
|
37
|
+
};
|
|
31
38
|
order(): number;
|
|
32
39
|
setModified(modified?: boolean): void;
|
|
33
40
|
isModified(): boolean;
|
|
@@ -126,6 +126,14 @@ export class PdfIndirectObject extends PdfObject {
|
|
|
126
126
|
compressed: this.compressed,
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
+
toJSON() {
|
|
130
|
+
return {
|
|
131
|
+
type: 'indirect-object',
|
|
132
|
+
objectNumber: this.objectNumber,
|
|
133
|
+
generationNumber: this.generationNumber,
|
|
134
|
+
content: this.content.toJSON(),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
129
137
|
order() {
|
|
130
138
|
return this.orderIndex ?? 0;
|
|
131
139
|
}
|
|
@@ -156,6 +164,9 @@ export class PdfIndirectObject extends PdfObject {
|
|
|
156
164
|
const savedGenerationNumber = this.generationNumber;
|
|
157
165
|
const savedOffset = this.offset;
|
|
158
166
|
const savedContent = this.content;
|
|
167
|
+
const savedModified = this.modified;
|
|
168
|
+
const savedEncryptable = this.encryptable;
|
|
169
|
+
const savedCompressed = this.compressed;
|
|
159
170
|
const newObject = new cls(this);
|
|
160
171
|
Object.setPrototypeOf(this, cls.prototype);
|
|
161
172
|
Object.assign(this, newObject);
|
|
@@ -163,6 +174,9 @@ export class PdfIndirectObject extends PdfObject {
|
|
|
163
174
|
this.generationNumber = savedGenerationNumber;
|
|
164
175
|
this.offset = savedOffset;
|
|
165
176
|
this.content = savedContent;
|
|
177
|
+
this.modified = savedModified;
|
|
178
|
+
this.encryptable = savedEncryptable;
|
|
179
|
+
this.compressed = savedCompressed;
|
|
166
180
|
return this;
|
|
167
181
|
}
|
|
168
182
|
resolve(cls) {
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PdfToken } from '../tokens/token.js';
|
|
2
2
|
import { PdfObject } from './pdf-object.js';
|
|
3
3
|
export declare class PdfName<T extends string = string> extends PdfObject {
|
|
4
4
|
value: T;
|
|
5
5
|
constructor(value: T);
|
|
6
|
-
protected tokenize():
|
|
6
|
+
protected tokenize(): PdfToken[];
|
|
7
7
|
cloneImpl(): this;
|
|
8
|
+
toJSON(): {
|
|
9
|
+
type: string;
|
|
10
|
+
value: T;
|
|
11
|
+
};
|
|
8
12
|
/**
|
|
9
13
|
* Escapes a PDF name according to PDF specification.
|
|
10
14
|
* PDF names can't contain spaces or certain special chars except # for escaping.
|
|
@@ -13,6 +13,9 @@ export class PdfName extends PdfObject {
|
|
|
13
13
|
const cloned = new PdfName(this.value);
|
|
14
14
|
return cloned;
|
|
15
15
|
}
|
|
16
|
+
toJSON() {
|
|
17
|
+
return { type: 'name', value: this.value };
|
|
18
|
+
}
|
|
16
19
|
/**
|
|
17
20
|
* Escapes a PDF name according to PDF specification.
|
|
18
21
|
* PDF names can't contain spaces or certain special chars except # for escaping.
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { PdfObject } from './pdf-object.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PdfToken } from '../tokens/token.js';
|
|
3
3
|
export declare class PdfNull extends PdfObject {
|
|
4
4
|
static readonly NULL: PdfNull;
|
|
5
|
-
protected tokenize():
|
|
5
|
+
protected tokenize(): PdfToken[];
|
|
6
6
|
cloneImpl(): this;
|
|
7
|
+
toJSON(): {
|
|
8
|
+
type: string;
|
|
9
|
+
};
|
|
7
10
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Ref } from '../ref.js';
|
|
2
2
|
import { PdfNumberToken } from '../tokens/number-token.js';
|
|
3
|
+
import { PdfToken } from '../tokens/token.js';
|
|
3
4
|
import { PdfObject } from './pdf-object.js';
|
|
4
5
|
export declare class PdfNumber extends PdfObject {
|
|
5
6
|
#private;
|
|
@@ -16,8 +17,12 @@ export declare class PdfNumber extends PdfObject {
|
|
|
16
17
|
set value(value: number);
|
|
17
18
|
onChange(callback: (value: number) => void): void;
|
|
18
19
|
toToken(): PdfNumberToken;
|
|
19
|
-
protected tokenize():
|
|
20
|
+
protected tokenize(): PdfToken[];
|
|
20
21
|
cloneImpl(): this;
|
|
22
|
+
toJSON(): {
|
|
23
|
+
type: string;
|
|
24
|
+
value: number;
|
|
25
|
+
};
|
|
21
26
|
setModified(modified?: boolean): void;
|
|
22
27
|
isModified(): boolean;
|
|
23
28
|
}
|
|
@@ -11,6 +11,11 @@ export declare class PdfObjectReference<T extends PdfIndirectObject = PdfIndirec
|
|
|
11
11
|
constructor(objectNumber: number, generationNumber: number);
|
|
12
12
|
protected tokenize(): PdfToken[];
|
|
13
13
|
cloneImpl(): this;
|
|
14
|
+
toJSON(): {
|
|
15
|
+
type: string;
|
|
16
|
+
objectNumber: number;
|
|
17
|
+
generationNumber: number;
|
|
18
|
+
};
|
|
14
19
|
resolve<U extends PdfIndirectObject = T>(cls?: new (options: PdfIndirectObject) => U): U;
|
|
15
20
|
get key(): string;
|
|
16
21
|
}
|
|
@@ -18,6 +18,13 @@ export class PdfObjectReference extends PdfObject {
|
|
|
18
18
|
const cloned = new PdfObjectReference(this.objectNumber, this.generationNumber);
|
|
19
19
|
return cloned;
|
|
20
20
|
}
|
|
21
|
+
toJSON() {
|
|
22
|
+
return {
|
|
23
|
+
type: 'reference',
|
|
24
|
+
objectNumber: this.objectNumber,
|
|
25
|
+
generationNumber: this.generationNumber,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
21
28
|
resolve(cls) {
|
|
22
29
|
if (!this.resolver) {
|
|
23
30
|
throw new Error(`No resolver set for PdfObjectReference '${this.objectNumber} ${this.generationNumber}'`);
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { Ref } from '../ref.js';
|
|
2
|
+
import { PdfToken } from '../tokens/token.js';
|
|
2
3
|
import { PdfNumber } from './pdf-number.js';
|
|
3
4
|
import { PdfObject } from './pdf-object.js';
|
|
4
5
|
export declare class PdfStartXRef extends PdfObject {
|
|
5
6
|
offset: PdfNumber;
|
|
6
7
|
constructor(offset?: number | PdfNumber | Ref<number>);
|
|
7
|
-
|
|
8
|
+
toJSON(): {
|
|
9
|
+
type: string;
|
|
10
|
+
offset: number;
|
|
11
|
+
};
|
|
12
|
+
protected tokenize(): PdfToken[];
|
|
8
13
|
cloneImpl(): this;
|
|
9
14
|
setModified(modified?: boolean): void;
|
|
10
15
|
isModified(): boolean;
|
|
@@ -13,6 +13,9 @@ export class PdfStartXRef extends PdfObject {
|
|
|
13
13
|
: new PdfNumber({ value: offset });
|
|
14
14
|
this.offset.isByteOffset = true;
|
|
15
15
|
}
|
|
16
|
+
toJSON() {
|
|
17
|
+
return { type: 'start-xref', offset: this.offset.value };
|
|
18
|
+
}
|
|
16
19
|
tokenize() {
|
|
17
20
|
const whiteSpaceTokens = this.offset.preTokens
|
|
18
21
|
? []
|
|
@@ -75,6 +75,14 @@ export declare class PdfStream<T extends PdfDictionary = PdfDictionary> extends
|
|
|
75
75
|
isModified?: boolean;
|
|
76
76
|
}) => T): T;
|
|
77
77
|
protected tokenize(): PdfToken[];
|
|
78
|
+
toJSON(): {
|
|
79
|
+
type: string;
|
|
80
|
+
header: {
|
|
81
|
+
type: string;
|
|
82
|
+
entries: Record<string, object>;
|
|
83
|
+
};
|
|
84
|
+
dataLength: number;
|
|
85
|
+
};
|
|
78
86
|
isType(name: string): boolean;
|
|
79
87
|
static getFilter(name: PdfStreamFilterType): PdfFilter;
|
|
80
88
|
static getAllFilters(): {
|
|
@@ -436,6 +436,13 @@ export class PdfStream extends PdfObject {
|
|
|
436
436
|
new PdfEndStreamToken(),
|
|
437
437
|
];
|
|
438
438
|
}
|
|
439
|
+
toJSON() {
|
|
440
|
+
return {
|
|
441
|
+
type: 'stream',
|
|
442
|
+
header: this.header.toJSON(),
|
|
443
|
+
dataLength: this.raw.length,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
439
446
|
isType(name) {
|
|
440
447
|
const type = this.header.get('Type');
|
|
441
448
|
return type instanceof PdfName && type.value === name;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ByteArray } from '../../types.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PdfToken } from '../tokens/token.js';
|
|
3
3
|
import { PdfObject } from './pdf-object.js';
|
|
4
4
|
export declare class PdfString extends PdfObject {
|
|
5
5
|
/**
|
|
@@ -22,6 +22,12 @@ export declare class PdfString extends PdfObject {
|
|
|
22
22
|
set value(str: string);
|
|
23
23
|
get value(): string;
|
|
24
24
|
get isTrailingDelimited(): boolean;
|
|
25
|
-
protected tokenize():
|
|
25
|
+
protected tokenize(): PdfToken[];
|
|
26
26
|
cloneImpl(): this;
|
|
27
|
+
toJSON(): {
|
|
28
|
+
type: string;
|
|
29
|
+
value: string;
|
|
30
|
+
};
|
|
31
|
+
trim(): string;
|
|
32
|
+
get length(): number;
|
|
27
33
|
}
|
|
@@ -80,4 +80,13 @@ export class PdfString extends PdfObject {
|
|
|
80
80
|
: undefined);
|
|
81
81
|
return cloned;
|
|
82
82
|
}
|
|
83
|
+
toJSON() {
|
|
84
|
+
return { type: 'string', value: this.value };
|
|
85
|
+
}
|
|
86
|
+
trim() {
|
|
87
|
+
return this.value.trim();
|
|
88
|
+
}
|
|
89
|
+
get length() {
|
|
90
|
+
return this.value.length;
|
|
91
|
+
}
|
|
83
92
|
}
|
|
@@ -20,6 +20,13 @@ export declare class PdfTrailer extends PdfObject {
|
|
|
20
20
|
dict: PdfTrailerDictionary;
|
|
21
21
|
offset: Ref<number>;
|
|
22
22
|
constructor(entries: PdfTrailerEntries | PdfDictionary<PdfTrailerEntries>);
|
|
23
|
+
toJSON(): {
|
|
24
|
+
type: string;
|
|
25
|
+
dict: {
|
|
26
|
+
type: string;
|
|
27
|
+
entries: Record<string, object>;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
23
30
|
protected tokenize(): PdfToken[];
|
|
24
31
|
cloneImpl(): this;
|
|
25
32
|
setModified(modified?: boolean): void;
|