pdf-lite 1.5.0 → 1.6.1
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/EXAMPLES.md +51 -70
- package/README.md +1 -1
- package/dist/acroform/appearance/pdf-button-appearance-stream.d.ts +1 -1
- package/dist/acroform/appearance/pdf-button-appearance-stream.js +6 -2
- package/dist/acroform/fields/pdf-button-form-field.d.ts +0 -9
- package/dist/acroform/fields/pdf-button-form-field.js +7 -39
- package/dist/acroform/fields/pdf-choice-form-field.d.ts +2 -1
- package/dist/acroform/fields/pdf-choice-form-field.js +19 -38
- package/dist/acroform/fields/pdf-default-appearance.js +1 -1
- package/dist/acroform/fields/pdf-form-field.d.ts +27 -32
- package/dist/acroform/fields/pdf-form-field.js +180 -94
- package/dist/acroform/fields/pdf-text-form-field.js +6 -33
- package/dist/acroform/fields/types.d.ts +1 -1
- package/dist/acroform/index.d.ts +0 -2
- package/dist/acroform/index.js +0 -2
- package/dist/acroform/pdf-acro-form.d.ts +12 -36
- package/dist/acroform/pdf-acro-form.js +111 -201
- package/dist/acroform/xfa/pdf-xfa-data.d.ts +4 -3
- package/dist/acroform/xfa/pdf-xfa-data.js +16 -12
- package/dist/acroform/xfa/pdf-xfa-form.d.ts +9 -4
- package/dist/acroform/xfa/pdf-xfa-form.js +17 -39
- package/dist/annotations/index.d.ts +0 -1
- package/dist/annotations/index.js +0 -1
- package/dist/annotations/pdf-annotation.d.ts +7 -2
- package/dist/annotations/pdf-annotation.js +30 -19
- package/dist/annotations/pdf-default-resources.d.ts +11 -0
- package/dist/annotations/pdf-default-resources.js +3 -0
- package/dist/core/decoder.js +1 -1
- package/dist/core/objects/pdf-array.d.ts +8 -1
- package/dist/core/objects/pdf-array.js +31 -0
- package/dist/core/objects/pdf-dictionary.d.ts +2 -0
- package/dist/core/objects/pdf-dictionary.js +14 -7
- package/dist/core/objects/pdf-hexadecimal.d.ts +1 -0
- package/dist/core/objects/pdf-hexadecimal.js +3 -3
- package/dist/core/objects/pdf-indirect-object.d.ts +18 -9
- package/dist/core/objects/pdf-indirect-object.js +75 -16
- package/dist/core/objects/pdf-number.d.ts +1 -0
- package/dist/core/objects/pdf-number.js +5 -4
- package/dist/core/objects/pdf-object-reference.d.ts +8 -1
- package/dist/core/objects/pdf-object-reference.js +14 -0
- package/dist/core/objects/pdf-object.d.ts +14 -0
- package/dist/core/objects/pdf-object.js +36 -0
- package/dist/core/objects/pdf-start-xref.d.ts +1 -0
- package/dist/core/objects/pdf-start-xref.js +4 -0
- package/dist/core/objects/pdf-stream.d.ts +47 -7
- package/dist/core/objects/pdf-stream.js +301 -32
- package/dist/core/objects/pdf-string.d.ts +1 -0
- package/dist/core/objects/pdf-string.js +3 -6
- package/dist/core/objects/pdf-trailer.d.ts +1 -0
- package/dist/core/objects/pdf-trailer.js +6 -3
- package/dist/core/objects/pdf-xref-table.js +1 -1
- package/dist/core/ref.d.ts +3 -1
- package/dist/core/ref.js +8 -5
- package/dist/core/tokens/token.d.ts +2 -1
- package/dist/core/tokens/token.js +3 -0
- package/dist/fonts/index.d.ts +0 -1
- package/dist/fonts/index.js +0 -1
- package/dist/fonts/pdf-font.d.ts +32 -27
- package/dist/fonts/pdf-font.js +115 -77
- package/dist/pdf/index.d.ts +2 -0
- package/dist/pdf/index.js +2 -0
- package/dist/pdf/pdf-document.d.ts +63 -37
- package/dist/pdf/pdf-document.js +351 -135
- package/dist/pdf/pdf-page.d.ts +50 -0
- package/dist/pdf/pdf-page.js +144 -0
- package/dist/pdf/pdf-pages.d.ts +28 -0
- package/dist/pdf/pdf-pages.js +94 -0
- package/dist/pdf/pdf-reader.d.ts +5 -1
- package/dist/pdf/pdf-reader.js +36 -2
- package/dist/pdf/pdf-revision.d.ts +3 -3
- package/dist/pdf/pdf-revision.js +7 -7
- package/dist/pdf/pdf-xref-lookup.js +34 -14
- package/dist/signing/document-security-store.d.ts +14 -17
- package/dist/signing/document-security-store.js +19 -34
- package/dist/signing/signer.d.ts +23 -8
- package/dist/signing/signer.js +51 -17
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/needsCentralWhitespace.d.ts +10 -0
- package/dist/utils/needsCentralWhitespace.js +34 -0
- package/package.json +3 -3
- package/dist/acroform/acroform.d.ts +0 -9
- package/dist/acroform/acroform.js +0 -7
- package/dist/acroform/manager.d.ts +0 -37
- package/dist/acroform/manager.js +0 -57
- package/dist/acroform/pdf-font-encoding-cache.d.ts +0 -27
- package/dist/acroform/pdf-font-encoding-cache.js +0 -188
- package/dist/annotations/pdf-annotation-writer.d.ts +0 -20
- package/dist/annotations/pdf-annotation-writer.js +0 -76
- package/dist/fonts/manager.d.ts +0 -127
- package/dist/fonts/manager.js +0 -378
- package/dist/utils/predictors.d.ts +0 -113
- package/dist/utils/predictors.js +0 -279
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
|
|
2
|
+
import { PdfArray } from '../core/objects/pdf-array.js';
|
|
3
|
+
import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
|
|
4
|
+
import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
|
|
5
|
+
import { PdfNumber } from '../core/objects/pdf-number.js';
|
|
6
|
+
import { PdfName } from '../core/objects/pdf-name.js';
|
|
7
|
+
import { PdfPages } from './pdf-pages.js';
|
|
8
|
+
type PdfPageDictionary = PdfDictionary<{
|
|
9
|
+
Type: PdfName<'Page'>;
|
|
10
|
+
Parent: PdfObjectReference;
|
|
11
|
+
MediaBox: PdfArray<PdfNumber>;
|
|
12
|
+
CropBox?: PdfArray<PdfNumber>;
|
|
13
|
+
BleedBox?: PdfArray<PdfNumber>;
|
|
14
|
+
TrimBox?: PdfArray<PdfNumber>;
|
|
15
|
+
ArtBox?: PdfArray<PdfNumber>;
|
|
16
|
+
Rotate?: PdfNumber;
|
|
17
|
+
Contents?: PdfObjectReference | PdfArray<PdfObjectReference>;
|
|
18
|
+
Resources?: PdfDictionary | PdfObjectReference;
|
|
19
|
+
Annots?: PdfArray<PdfObjectReference> | PdfObjectReference;
|
|
20
|
+
}>;
|
|
21
|
+
export declare class PdfPage extends PdfIndirectObject<PdfPageDictionary> {
|
|
22
|
+
constructor(options?: PdfIndirectObject);
|
|
23
|
+
private getBox;
|
|
24
|
+
private setBox;
|
|
25
|
+
get mediaBox(): [number, number, number, number];
|
|
26
|
+
set mediaBox(value: [number, number, number, number]);
|
|
27
|
+
get cropBox(): [number, number, number, number] | null;
|
|
28
|
+
set cropBox(value: [number, number, number, number] | null);
|
|
29
|
+
get bleedBox(): [number, number, number, number] | null;
|
|
30
|
+
set bleedBox(value: [number, number, number, number] | null);
|
|
31
|
+
get trimBox(): [number, number, number, number] | null;
|
|
32
|
+
set trimBox(value: [number, number, number, number] | null);
|
|
33
|
+
get artBox(): [number, number, number, number] | null;
|
|
34
|
+
set artBox(value: [number, number, number, number] | null);
|
|
35
|
+
get width(): number;
|
|
36
|
+
get height(): number;
|
|
37
|
+
get rotate(): number;
|
|
38
|
+
set rotate(value: number);
|
|
39
|
+
get contents(): PdfObjectReference | PdfArray<PdfObjectReference> | null;
|
|
40
|
+
set contents(value: PdfObjectReference | PdfArray<PdfObjectReference> | null);
|
|
41
|
+
get resources(): PdfDictionary | null;
|
|
42
|
+
set resources(value: PdfDictionary | PdfObjectReference | null);
|
|
43
|
+
get annotations(): PdfArray<PdfObjectReference>;
|
|
44
|
+
set annotations(value: PdfArray<PdfObjectReference>);
|
|
45
|
+
get parentRef(): PdfObjectReference;
|
|
46
|
+
set parentRef(value: PdfObjectReference);
|
|
47
|
+
get parent(): PdfPages;
|
|
48
|
+
set parent(value: PdfPages);
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
|
|
2
|
+
import { PdfArray } from '../core/objects/pdf-array.js';
|
|
3
|
+
import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
|
|
4
|
+
import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
|
|
5
|
+
import { PdfNumber } from '../core/objects/pdf-number.js';
|
|
6
|
+
import { PdfPages } from './pdf-pages.js';
|
|
7
|
+
export class PdfPage extends PdfIndirectObject {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(options ??
|
|
10
|
+
new PdfIndirectObject({
|
|
11
|
+
content: new PdfDictionary(),
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
getBox(name) {
|
|
15
|
+
const box = this.content.get(name)?.as((PdfArray));
|
|
16
|
+
if (!box || box.items.length < 4)
|
|
17
|
+
return null;
|
|
18
|
+
return [
|
|
19
|
+
box.items[0].value,
|
|
20
|
+
box.items[1].value,
|
|
21
|
+
box.items[2].value,
|
|
22
|
+
box.items[3].value,
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
setBox(name, value) {
|
|
26
|
+
if (value === null) {
|
|
27
|
+
this.content.delete(name);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.content.set(name, new PdfArray(value.map((v) => new PdfNumber(v))));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
get mediaBox() {
|
|
34
|
+
return this.getBox('MediaBox') ?? [0, 0, 612, 792];
|
|
35
|
+
}
|
|
36
|
+
set mediaBox(value) {
|
|
37
|
+
this.setBox('MediaBox', value);
|
|
38
|
+
}
|
|
39
|
+
get cropBox() {
|
|
40
|
+
return this.getBox('CropBox');
|
|
41
|
+
}
|
|
42
|
+
set cropBox(value) {
|
|
43
|
+
this.setBox('CropBox', value);
|
|
44
|
+
}
|
|
45
|
+
get bleedBox() {
|
|
46
|
+
return this.getBox('BleedBox');
|
|
47
|
+
}
|
|
48
|
+
set bleedBox(value) {
|
|
49
|
+
this.setBox('BleedBox', value);
|
|
50
|
+
}
|
|
51
|
+
get trimBox() {
|
|
52
|
+
return this.getBox('TrimBox');
|
|
53
|
+
}
|
|
54
|
+
set trimBox(value) {
|
|
55
|
+
this.setBox('TrimBox', value);
|
|
56
|
+
}
|
|
57
|
+
get artBox() {
|
|
58
|
+
return this.getBox('ArtBox');
|
|
59
|
+
}
|
|
60
|
+
set artBox(value) {
|
|
61
|
+
this.setBox('ArtBox', value);
|
|
62
|
+
}
|
|
63
|
+
get width() {
|
|
64
|
+
const box = this.mediaBox;
|
|
65
|
+
return box[2] - box[0];
|
|
66
|
+
}
|
|
67
|
+
get height() {
|
|
68
|
+
const box = this.mediaBox;
|
|
69
|
+
return box[3] - box[1];
|
|
70
|
+
}
|
|
71
|
+
get rotate() {
|
|
72
|
+
return this.content.get('Rotate')?.as(PdfNumber)?.value ?? 0;
|
|
73
|
+
}
|
|
74
|
+
set rotate(value) {
|
|
75
|
+
this.content.set('Rotate', new PdfNumber(value));
|
|
76
|
+
}
|
|
77
|
+
get contents() {
|
|
78
|
+
const entry = this.content.get('Contents');
|
|
79
|
+
if (!entry)
|
|
80
|
+
return null;
|
|
81
|
+
if (entry instanceof PdfArray)
|
|
82
|
+
return entry;
|
|
83
|
+
return entry.as(PdfObjectReference) ?? null;
|
|
84
|
+
}
|
|
85
|
+
set contents(value) {
|
|
86
|
+
if (value === null) {
|
|
87
|
+
this.content.delete('Contents');
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
this.content.set('Contents', value);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
get resources() {
|
|
94
|
+
const entry = this.content.get('Resources');
|
|
95
|
+
if (!entry)
|
|
96
|
+
return null;
|
|
97
|
+
if (entry instanceof PdfObjectReference) {
|
|
98
|
+
const resolved = entry.resolve();
|
|
99
|
+
if (resolved?.content instanceof PdfDictionary) {
|
|
100
|
+
return resolved.content;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
return entry.as(PdfDictionary) ?? null;
|
|
105
|
+
}
|
|
106
|
+
set resources(value) {
|
|
107
|
+
if (value === null) {
|
|
108
|
+
this.content.delete('Resources');
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
this.content.set('Resources', value);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
get annotations() {
|
|
115
|
+
const entry = this.content.get('Annots');
|
|
116
|
+
if (entry instanceof PdfArray) {
|
|
117
|
+
return entry;
|
|
118
|
+
}
|
|
119
|
+
if (entry instanceof PdfObjectReference) {
|
|
120
|
+
const resolved = entry.resolve();
|
|
121
|
+
if (resolved?.content instanceof PdfArray) {
|
|
122
|
+
return resolved.content;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const newArray = new PdfArray();
|
|
126
|
+
this.content.set('Annots', newArray);
|
|
127
|
+
return newArray;
|
|
128
|
+
}
|
|
129
|
+
set annotations(value) {
|
|
130
|
+
this.content.set('Annots', value);
|
|
131
|
+
}
|
|
132
|
+
get parentRef() {
|
|
133
|
+
return this.content.get('Parent').as(PdfObjectReference);
|
|
134
|
+
}
|
|
135
|
+
set parentRef(value) {
|
|
136
|
+
this.content.set('Parent', value);
|
|
137
|
+
}
|
|
138
|
+
get parent() {
|
|
139
|
+
return this.parentRef.resolve(PdfPages);
|
|
140
|
+
}
|
|
141
|
+
set parent(value) {
|
|
142
|
+
this.parentRef = value.reference;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
|
|
2
|
+
import { PdfArray } from '../core/objects/pdf-array.js';
|
|
3
|
+
import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
|
|
4
|
+
import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
|
|
5
|
+
import { PdfNumber } from '../core/objects/pdf-number.js';
|
|
6
|
+
import { PdfName } from '../core/objects/pdf-name.js';
|
|
7
|
+
import { PdfPage } from './pdf-page.js';
|
|
8
|
+
type PdfPagesDictionary = PdfDictionary<{
|
|
9
|
+
Type: PdfName<'Pages'>;
|
|
10
|
+
Kids: PdfArray<PdfObjectReference>;
|
|
11
|
+
Count: PdfNumber;
|
|
12
|
+
Parent?: PdfObjectReference;
|
|
13
|
+
}>;
|
|
14
|
+
export declare class PdfPages extends PdfIndirectObject<PdfPagesDictionary> implements Iterable<PdfPage> {
|
|
15
|
+
constructor(options?: PdfIndirectObject);
|
|
16
|
+
get kids(): (PdfPage | PdfPages)[];
|
|
17
|
+
set kids(value: PdfArray<PdfObjectReference>);
|
|
18
|
+
get count(): number;
|
|
19
|
+
set count(value: number);
|
|
20
|
+
get parentRef(): PdfObjectReference | null;
|
|
21
|
+
set parentRef(value: PdfObjectReference | null);
|
|
22
|
+
get parent(): PdfPages | null;
|
|
23
|
+
set parent(value: PdfPages | null);
|
|
24
|
+
get(index: number): PdfPage;
|
|
25
|
+
toArray(): PdfPage[];
|
|
26
|
+
[Symbol.iterator](): Iterator<PdfPage>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
|
|
2
|
+
import { PdfArray } from '../core/objects/pdf-array.js';
|
|
3
|
+
import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
|
|
4
|
+
import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
|
|
5
|
+
import { PdfNumber } from '../core/objects/pdf-number.js';
|
|
6
|
+
import { PdfName } from '../core/objects/pdf-name.js';
|
|
7
|
+
import { PdfPage } from './pdf-page.js';
|
|
8
|
+
export class PdfPages extends PdfIndirectObject {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
super(options ??
|
|
11
|
+
new PdfIndirectObject({
|
|
12
|
+
content: new PdfDictionary({
|
|
13
|
+
Type: new PdfName('Pages'),
|
|
14
|
+
Kids: new PdfArray(),
|
|
15
|
+
Count: new PdfNumber(0),
|
|
16
|
+
}),
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
get kids() {
|
|
20
|
+
const kidsArray = this.content
|
|
21
|
+
.get('Kids')
|
|
22
|
+
?.as((PdfArray));
|
|
23
|
+
if (!kidsArray)
|
|
24
|
+
return [];
|
|
25
|
+
return kidsArray.items.map((ref) => {
|
|
26
|
+
const resolved = ref.as(PdfObjectReference).resolve();
|
|
27
|
+
const type = resolved.content
|
|
28
|
+
?.as(PdfDictionary)
|
|
29
|
+
?.get('Type')
|
|
30
|
+
?.as(PdfName);
|
|
31
|
+
if (type?.value === 'Pages') {
|
|
32
|
+
return resolved.becomes(PdfPages);
|
|
33
|
+
}
|
|
34
|
+
return resolved.becomes(PdfPage);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
set kids(value) {
|
|
38
|
+
this.content.set('Kids', value);
|
|
39
|
+
}
|
|
40
|
+
get count() {
|
|
41
|
+
return this.content.get('Count')?.as(PdfNumber)?.value ?? 0;
|
|
42
|
+
}
|
|
43
|
+
set count(value) {
|
|
44
|
+
this.content.set('Count', new PdfNumber(value));
|
|
45
|
+
}
|
|
46
|
+
get parentRef() {
|
|
47
|
+
return this.content.get('Parent')?.as(PdfObjectReference) ?? null;
|
|
48
|
+
}
|
|
49
|
+
set parentRef(value) {
|
|
50
|
+
if (value === null) {
|
|
51
|
+
this.content.delete('Parent');
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
this.content.set('Parent', value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
get parent() {
|
|
58
|
+
const ref = this.parentRef;
|
|
59
|
+
if (!ref)
|
|
60
|
+
return null;
|
|
61
|
+
return ref.resolve(PdfPages);
|
|
62
|
+
}
|
|
63
|
+
set parent(value) {
|
|
64
|
+
this.parentRef = value?.reference ?? null;
|
|
65
|
+
}
|
|
66
|
+
get(index) {
|
|
67
|
+
return [...this][index];
|
|
68
|
+
}
|
|
69
|
+
toArray() {
|
|
70
|
+
return [...this];
|
|
71
|
+
}
|
|
72
|
+
*[Symbol.iterator]() {
|
|
73
|
+
const kidsArray = this.content
|
|
74
|
+
.get('Kids')
|
|
75
|
+
?.as((PdfArray));
|
|
76
|
+
if (!kidsArray)
|
|
77
|
+
return;
|
|
78
|
+
for (const ref of kidsArray.items) {
|
|
79
|
+
const resolved = ref.as(PdfObjectReference)?.resolve();
|
|
80
|
+
if (!resolved)
|
|
81
|
+
continue;
|
|
82
|
+
const typeEntry = resolved.content
|
|
83
|
+
?.as(PdfDictionary)
|
|
84
|
+
?.get('Type')
|
|
85
|
+
?.as(PdfName);
|
|
86
|
+
if (typeEntry?.value === 'Pages') {
|
|
87
|
+
yield* resolved.becomes(PdfPages);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
yield resolved.becomes(PdfPage);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
package/dist/pdf/pdf-reader.d.ts
CHANGED
|
@@ -33,5 +33,9 @@ export declare class PdfReader {
|
|
|
33
33
|
* @param input - Async or sync iterable of byte arrays
|
|
34
34
|
* @returns A promise that resolves to the parsed PdfDocument
|
|
35
35
|
*/
|
|
36
|
-
static fromBytes(input: AsyncIterable<ByteArray> | Iterable<ByteArray
|
|
36
|
+
static fromBytes(input: AsyncIterable<ByteArray> | Iterable<ByteArray>, options?: {
|
|
37
|
+
password?: string;
|
|
38
|
+
ownerPassword?: string;
|
|
39
|
+
incremental?: boolean;
|
|
40
|
+
}): Promise<PdfDocument>;
|
|
37
41
|
}
|
package/dist/pdf/pdf-reader.js
CHANGED
|
@@ -40,8 +40,42 @@ export class PdfReader {
|
|
|
40
40
|
* @param input - Async or sync iterable of byte arrays
|
|
41
41
|
* @returns A promise that resolves to the parsed PdfDocument
|
|
42
42
|
*/
|
|
43
|
-
static async fromBytes(input) {
|
|
43
|
+
static async fromBytes(input, options) {
|
|
44
44
|
const reader = new PdfReader(new PdfObjectStream(input));
|
|
45
|
-
|
|
45
|
+
const document = await reader.read();
|
|
46
|
+
let shouldDecrypt = Boolean(document.encryptionDictionary);
|
|
47
|
+
if (typeof options?.password === 'string') {
|
|
48
|
+
document.setPassword(options.password);
|
|
49
|
+
shouldDecrypt = true;
|
|
50
|
+
}
|
|
51
|
+
if (typeof options?.ownerPassword === 'string') {
|
|
52
|
+
document.setOwnerPassword(options.ownerPassword);
|
|
53
|
+
shouldDecrypt = true;
|
|
54
|
+
}
|
|
55
|
+
if (options?.incremental) {
|
|
56
|
+
// Lock revisions first to preserve the original bytes
|
|
57
|
+
// (including encrypted data) via cached tokens.
|
|
58
|
+
document.setIncremental(true);
|
|
59
|
+
// Then decrypt the live object data so built-in operations
|
|
60
|
+
// (AcroForm, fonts, etc.) can read it. The cached tokens
|
|
61
|
+
// still produce the original encrypted bytes on serialization.
|
|
62
|
+
if (shouldDecrypt) {
|
|
63
|
+
try {
|
|
64
|
+
await document.decryptObjects();
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
document.resetSecurityHandler();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (shouldDecrypt) {
|
|
72
|
+
try {
|
|
73
|
+
await document.decryptObjects();
|
|
74
|
+
}
|
|
75
|
+
catch (e) {
|
|
76
|
+
document.resetSecurityHandler();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return document;
|
|
46
80
|
}
|
|
47
81
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
|
|
2
|
+
import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
|
|
2
3
|
import { PdfObject } from '../core/objects/pdf-object.js';
|
|
3
4
|
import { PdfTrailerEntries } from '../core/objects/pdf-trailer.js';
|
|
4
5
|
import { PdfToken } from '../core/tokens/token.js';
|
|
5
6
|
import { PdfComment } from '../index.js';
|
|
6
|
-
import { ByteArray } from '../types.js';
|
|
7
7
|
import { PdfXrefLookup } from './pdf-xref-lookup.js';
|
|
8
8
|
/**
|
|
9
9
|
* Represents a single revision of a PDF document.
|
|
@@ -17,7 +17,6 @@ export declare class PdfRevision extends PdfObject {
|
|
|
17
17
|
private _locked;
|
|
18
18
|
/** Cross-reference lookup table for this revision */
|
|
19
19
|
xref: PdfXrefLookup;
|
|
20
|
-
private cachedBytes?;
|
|
21
20
|
/**
|
|
22
21
|
* Creates a new PDF revision.
|
|
23
22
|
*
|
|
@@ -54,6 +53,7 @@ export declare class PdfRevision extends PdfObject {
|
|
|
54
53
|
* @throws Error if the revision is locked
|
|
55
54
|
*/
|
|
56
55
|
set objects(value: PdfObject[]);
|
|
56
|
+
get indirectObjects(): PdfIndirectObject[];
|
|
57
57
|
/**
|
|
58
58
|
* Links this revision to a previous revision's cross-reference table.
|
|
59
59
|
*
|
|
@@ -126,5 +126,5 @@ export declare class PdfRevision extends PdfObject {
|
|
|
126
126
|
*/
|
|
127
127
|
cloneImpl(): this;
|
|
128
128
|
protected tokenize(): PdfToken[];
|
|
129
|
-
|
|
129
|
+
isEmpty(): boolean;
|
|
130
130
|
}
|
package/dist/pdf/pdf-revision.js
CHANGED
|
@@ -15,7 +15,6 @@ export class PdfRevision extends PdfObject {
|
|
|
15
15
|
_locked = false;
|
|
16
16
|
/** Cross-reference lookup table for this revision */
|
|
17
17
|
xref;
|
|
18
|
-
cachedBytes;
|
|
19
18
|
/**
|
|
20
19
|
* Creates a new PDF revision.
|
|
21
20
|
*
|
|
@@ -66,7 +65,6 @@ export class PdfRevision extends PdfObject {
|
|
|
66
65
|
*/
|
|
67
66
|
set locked(value) {
|
|
68
67
|
this._locked = value;
|
|
69
|
-
this.cachedBytes = value ? this.toBytes() : undefined;
|
|
70
68
|
for (const obj of this._objects) {
|
|
71
69
|
obj.setImmutable(value);
|
|
72
70
|
}
|
|
@@ -89,6 +87,9 @@ export class PdfRevision extends PdfObject {
|
|
|
89
87
|
}
|
|
90
88
|
this._objects = value;
|
|
91
89
|
}
|
|
90
|
+
get indirectObjects() {
|
|
91
|
+
return this._objects.filter((obj) => obj instanceof PdfIndirectObject);
|
|
92
|
+
}
|
|
92
93
|
/**
|
|
93
94
|
* Links this revision to a previous revision's cross-reference table.
|
|
94
95
|
*
|
|
@@ -264,10 +265,9 @@ export class PdfRevision extends PdfObject {
|
|
|
264
265
|
});
|
|
265
266
|
return output;
|
|
266
267
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return super.toBytes();
|
|
268
|
+
isEmpty() {
|
|
269
|
+
return (this.indirectObjects.length < 1 ||
|
|
270
|
+
(this.indirectObjects.length === 1 &&
|
|
271
|
+
this.indirectObjects[0] === this.xref.object));
|
|
272
272
|
}
|
|
273
273
|
}
|
|
@@ -77,14 +77,18 @@ export class PdfXrefLookup {
|
|
|
77
77
|
this.prev = xref;
|
|
78
78
|
const prevDict = xref.trailerDict;
|
|
79
79
|
const dict = this.trailerDict;
|
|
80
|
-
!dict.has('Info') && dict.set('Info', prevDict.get('Info')
|
|
81
|
-
!dict.has('Root') && dict.set('Root', prevDict.get('Root')
|
|
82
|
-
!dict.has('Encrypt') &&
|
|
83
|
-
|
|
84
|
-
!dict.has('
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
!dict.has('Info') && dict.set('Info', prevDict.get('Info'));
|
|
81
|
+
!dict.has('Root') && dict.set('Root', prevDict.get('Root'));
|
|
82
|
+
!dict.has('Encrypt') && dict.set('Encrypt', prevDict.get('Encrypt'));
|
|
83
|
+
!dict.has('ID') && dict.set('ID', prevDict.get('ID'));
|
|
84
|
+
if (!dict.has('Prev')) {
|
|
85
|
+
const prevNumber = new PdfNumber(xref.offset);
|
|
86
|
+
prevNumber.isByteOffset = true;
|
|
87
|
+
dict.set('Prev', prevNumber);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
const prev = dict.get('Prev');
|
|
91
|
+
prev.ref.update(xref.offset);
|
|
88
92
|
prev.isByteOffset = true;
|
|
89
93
|
}
|
|
90
94
|
}
|
|
@@ -137,8 +141,18 @@ export class PdfXrefLookup {
|
|
|
137
141
|
}
|
|
138
142
|
const initialLookup = lookup;
|
|
139
143
|
while (lookup) {
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
const prevEntry = lookup.trailerDict.get('Prev');
|
|
145
|
+
const prevLookup = lookups.find((x) => x.offset.equals(prevEntry?.value));
|
|
146
|
+
if (prevLookup) {
|
|
147
|
+
lookup.prev = prevLookup;
|
|
148
|
+
// Link the Prev entry's Ref to the previous xref's offset Ref
|
|
149
|
+
// so it automatically updates when positions change
|
|
150
|
+
if (prevEntry) {
|
|
151
|
+
prevEntry.ref.update(prevLookup.offset);
|
|
152
|
+
prevEntry.isByteOffset = true;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
lookup = prevLookup;
|
|
142
156
|
}
|
|
143
157
|
return initialLookup;
|
|
144
158
|
}
|
|
@@ -248,11 +262,11 @@ export class PdfXrefLookup {
|
|
|
248
262
|
* @param objects - Array of xref lookups to search for the previous one
|
|
249
263
|
*/
|
|
250
264
|
linkPrev(objects) {
|
|
251
|
-
const
|
|
252
|
-
if (
|
|
265
|
+
const prevEntry = this.trailerDict.get('Prev');
|
|
266
|
+
if (prevEntry?.value === undefined) {
|
|
253
267
|
return;
|
|
254
268
|
}
|
|
255
|
-
const prevLookup = objects.filter((obj) => obj.offset.equals(
|
|
269
|
+
const prevLookup = objects.filter((obj) => obj.offset.equals(prevEntry.value));
|
|
256
270
|
if (prevLookup.length === 0) {
|
|
257
271
|
return;
|
|
258
272
|
}
|
|
@@ -261,7 +275,10 @@ export class PdfXrefLookup {
|
|
|
261
275
|
}
|
|
262
276
|
if (prevLookup[0].offset.equals(0))
|
|
263
277
|
return;
|
|
264
|
-
this.
|
|
278
|
+
this.prev = prevLookup[0];
|
|
279
|
+
// Link the Prev entry's Ref to the previous xref's offset Ref
|
|
280
|
+
prevEntry.ref.update(prevLookup[0].offset);
|
|
281
|
+
prevEntry.isByteOffset = true;
|
|
265
282
|
}
|
|
266
283
|
/**
|
|
267
284
|
* Updates the xref object with current entries.
|
|
@@ -270,6 +287,9 @@ export class PdfXrefLookup {
|
|
|
270
287
|
* @returns The updated xref object
|
|
271
288
|
*/
|
|
272
289
|
update() {
|
|
290
|
+
if (this.object?.isImmutable()) {
|
|
291
|
+
return this.object;
|
|
292
|
+
}
|
|
273
293
|
if (this.object instanceof PdfXRefTable) {
|
|
274
294
|
const tableEntries = this.entriesValues.filter((entry) => entry instanceof PdfXRefTableEntry);
|
|
275
295
|
const compressedEntries = this.entriesValues.filter((entry) => entry instanceof PdfXRefStreamCompressedEntry);
|
|
@@ -6,7 +6,6 @@ import { PdfName } from '../core/objects/pdf-name.js';
|
|
|
6
6
|
import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
|
|
7
7
|
import { PdfStream } from '../core/objects/pdf-stream.js';
|
|
8
8
|
import { PdfString } from '../core/objects/pdf-string.js';
|
|
9
|
-
import { PdfDocument } from '../pdf/pdf-document.js';
|
|
10
9
|
import { ByteArray } from '../types.js';
|
|
11
10
|
import { RevocationInfo } from './types.js';
|
|
12
11
|
/**
|
|
@@ -31,9 +30,9 @@ export declare class PdfOcspObject extends PdfIndirectObject<PdfStream> {
|
|
|
31
30
|
export type PdfVriObject = PdfIndirectObject<PdfDictionary<{
|
|
32
31
|
[CertHash: string]: PdfDictionary<{
|
|
33
32
|
Type?: PdfName<'VRI'>;
|
|
34
|
-
Cert?: PdfObjectReference
|
|
35
|
-
OCSP?: PdfObjectReference
|
|
36
|
-
CRL?: PdfObjectReference
|
|
33
|
+
Cert?: PdfObjectReference<PdfIndirectObject<PdfStream>>;
|
|
34
|
+
OCSP?: PdfObjectReference<PdfIndirectObject<PdfStream>>;
|
|
35
|
+
CRL?: PdfObjectReference<PdfIndirectObject<PdfStream>>;
|
|
37
36
|
TU?: PdfDate;
|
|
38
37
|
TS?: PdfString;
|
|
39
38
|
}>;
|
|
@@ -45,9 +44,9 @@ export type PdfVriObject = PdfIndirectObject<PdfDictionary<{
|
|
|
45
44
|
export declare class PdfDocumentSecurityStoreDictionary extends PdfDictionary<{
|
|
46
45
|
Type?: PdfName<'DSS'>;
|
|
47
46
|
VRI?: PdfObjectReference;
|
|
48
|
-
OCSPs?: PdfArray<PdfObjectReference
|
|
49
|
-
CRLs?: PdfArray<PdfObjectReference
|
|
50
|
-
Certs?: PdfArray<PdfObjectReference
|
|
47
|
+
OCSPs?: PdfArray<PdfObjectReference<PdfIndirectObject<PdfStream>>>;
|
|
48
|
+
CRLs?: PdfArray<PdfObjectReference<PdfIndirectObject<PdfStream>>>;
|
|
49
|
+
Certs?: PdfArray<PdfObjectReference<PdfIndirectObject<PdfStream>>>;
|
|
51
50
|
}> {
|
|
52
51
|
}
|
|
53
52
|
/**
|
|
@@ -57,48 +56,46 @@ export declare class PdfDocumentSecurityStoreDictionary extends PdfDictionary<{
|
|
|
57
56
|
* @example
|
|
58
57
|
* ```typescript
|
|
59
58
|
* const dss = new PdfDocumentSecurityStoreObject(document)
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
59
|
+
* dss.addCert(certificateBytes)
|
|
60
|
+
* dss.addCrl(crlBytes)
|
|
61
|
+
* dss.addOcsp(ocspBytes)
|
|
63
62
|
* ```
|
|
64
63
|
*/
|
|
65
64
|
export declare class PdfDocumentSecurityStoreObject extends PdfIndirectObject<PdfDocumentSecurityStoreDictionary> {
|
|
66
|
-
/** Reference to the parent document. */
|
|
67
|
-
private document;
|
|
68
65
|
/**
|
|
69
66
|
* Creates a new DSS object.
|
|
70
67
|
*
|
|
71
68
|
* @param document - The parent PDF document.
|
|
72
69
|
* @param content - Optional pre-existing DSS dictionary.
|
|
73
70
|
*/
|
|
74
|
-
constructor(
|
|
71
|
+
constructor(content?: PdfDocumentSecurityStoreDictionary);
|
|
75
72
|
/**
|
|
76
73
|
* Adds an OCSP response to the DSS, avoiding duplicates.
|
|
77
74
|
*
|
|
78
75
|
* @param ocsp - The DER-encoded OCSP response.
|
|
79
76
|
* @returns The created or existing OCSP object.
|
|
80
77
|
*/
|
|
81
|
-
addOcsp(ocsp: ByteArray):
|
|
78
|
+
addOcsp(ocsp: ByteArray): PdfOcspObject;
|
|
82
79
|
/**
|
|
83
80
|
* Adds a CRL to the DSS, avoiding duplicates.
|
|
84
81
|
*
|
|
85
82
|
* @param crl - The DER-encoded CRL.
|
|
86
83
|
* @returns The created or existing CRL object.
|
|
87
84
|
*/
|
|
88
|
-
addCrl(crl: ByteArray):
|
|
85
|
+
addCrl(crl: ByteArray): PdfCrlObject;
|
|
89
86
|
/**
|
|
90
87
|
* Adds a certificate to the DSS, avoiding duplicates.
|
|
91
88
|
*
|
|
92
89
|
* @param cert - The DER-encoded certificate.
|
|
93
90
|
* @returns The created or existing certificate object.
|
|
94
91
|
*/
|
|
95
|
-
addCert(cert: ByteArray):
|
|
92
|
+
addCert(cert: ByteArray): PdfCertObject;
|
|
96
93
|
/**
|
|
97
94
|
* Adds revocation information (CRLs and OCSPs) to the DSS.
|
|
98
95
|
*
|
|
99
96
|
* @param revocationInfo - The revocation information to add.
|
|
100
97
|
*/
|
|
101
|
-
addRevocationInfo(revocationInfo: RevocationInfo):
|
|
98
|
+
addRevocationInfo(revocationInfo: RevocationInfo): void;
|
|
102
99
|
/**
|
|
103
100
|
* Checks if the DSS is empty (contains no certificates, CRLs, or OCSPs).
|
|
104
101
|
*
|