@adnsistemas/pdf-lib 2.4.4 → 2.5.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/cjs/api/PDFDocument.d.ts +6 -6
- package/cjs/api/PDFDocument.d.ts.map +1 -1
- package/cjs/api/PDFDocument.js +8 -6
- package/cjs/api/PDFDocument.js.map +1 -1
- package/cjs/api/index.d.ts +21 -21
- package/cjs/api/index.d.ts.map +1 -1
- package/cjs/api/index.js +20 -20
- package/cjs/api/index.js.map +1 -1
- package/cjs/api/snapshot/DefaultDocumentSnapshot.d.ts +6 -2
- package/cjs/api/snapshot/DefaultDocumentSnapshot.d.ts.map +1 -1
- package/cjs/api/snapshot/DefaultDocumentSnapshot.js +10 -0
- package/cjs/api/snapshot/DefaultDocumentSnapshot.js.map +1 -1
- package/cjs/api/snapshot/DocumentSnapshot.d.ts +5 -1
- package/cjs/api/snapshot/DocumentSnapshot.d.ts.map +1 -1
- package/cjs/api/snapshot/IncrementalDocumentSnapshot.d.ts +7 -2
- package/cjs/api/snapshot/IncrementalDocumentSnapshot.d.ts.map +1 -1
- package/cjs/api/snapshot/IncrementalDocumentSnapshot.js +17 -0
- package/cjs/api/snapshot/IncrementalDocumentSnapshot.js.map +1 -1
- package/cjs/core/PDFContext.d.ts +2 -1
- package/cjs/core/PDFContext.d.ts.map +1 -1
- package/cjs/core/PDFContext.js +2 -0
- package/cjs/core/PDFContext.js.map +1 -1
- package/cjs/core/document/PDFCrossRefSection.d.ts +1 -1
- package/cjs/core/document/PDFCrossRefSection.d.ts.map +1 -1
- package/cjs/core/document/PDFCrossRefSection.js +49 -2
- package/cjs/core/document/PDFCrossRefSection.js.map +1 -1
- package/cjs/core/parser/PDFParser.d.ts.map +1 -1
- package/cjs/core/parser/PDFParser.js +6 -0
- package/cjs/core/parser/PDFParser.js.map +1 -1
- package/cjs/core/parser/PDFXRefStreamParser.d.ts.map +1 -1
- package/cjs/core/parser/PDFXRefStreamParser.js +6 -0
- package/cjs/core/parser/PDFXRefStreamParser.js.map +1 -1
- package/cjs/core/writers/PDFStreamWriter.d.ts +7 -7
- package/cjs/core/writers/PDFStreamWriter.d.ts.map +1 -1
- package/cjs/core/writers/PDFStreamWriter.js +16 -16
- package/cjs/core/writers/PDFStreamWriter.js.map +1 -1
- package/cjs/core/writers/PDFWriter.d.ts +10 -10
- package/cjs/core/writers/PDFWriter.d.ts.map +1 -1
- package/cjs/core/writers/PDFWriter.js +20 -10
- package/cjs/core/writers/PDFWriter.js.map +1 -1
- package/dist/pdf-lib.esm.js +21436 -6660
- package/dist/pdf-lib.esm.js.map +1 -1
- package/dist/pdf-lib.esm.min.js +3 -3
- package/dist/pdf-lib.esm.min.js.map +1 -1
- package/dist/pdf-lib.js +21372 -6514
- package/dist/pdf-lib.js.map +1 -1
- package/dist/pdf-lib.min.js +3 -3
- package/dist/pdf-lib.min.js.map +1 -1
- package/es/api/PDFDocument.d.ts +6 -6
- package/es/api/PDFDocument.d.ts.map +1 -1
- package/es/api/PDFDocument.js +8 -6
- package/es/api/PDFDocument.js.map +1 -1
- package/es/api/index.d.ts +21 -21
- package/es/api/index.d.ts.map +1 -1
- package/es/api/index.js +20 -20
- package/es/api/index.js.map +1 -1
- package/es/api/snapshot/DefaultDocumentSnapshot.d.ts +6 -2
- package/es/api/snapshot/DefaultDocumentSnapshot.d.ts.map +1 -1
- package/es/api/snapshot/DefaultDocumentSnapshot.js +10 -0
- package/es/api/snapshot/DefaultDocumentSnapshot.js.map +1 -1
- package/es/api/snapshot/DocumentSnapshot.d.ts +5 -1
- package/es/api/snapshot/DocumentSnapshot.d.ts.map +1 -1
- package/es/api/snapshot/IncrementalDocumentSnapshot.d.ts +7 -2
- package/es/api/snapshot/IncrementalDocumentSnapshot.d.ts.map +1 -1
- package/es/api/snapshot/IncrementalDocumentSnapshot.js +17 -0
- package/es/api/snapshot/IncrementalDocumentSnapshot.js.map +1 -1
- package/es/core/PDFContext.d.ts +2 -1
- package/es/core/PDFContext.d.ts.map +1 -1
- package/es/core/PDFContext.js +2 -0
- package/es/core/PDFContext.js.map +1 -1
- package/es/core/document/PDFCrossRefSection.d.ts +1 -1
- package/es/core/document/PDFCrossRefSection.d.ts.map +1 -1
- package/es/core/document/PDFCrossRefSection.js +49 -2
- package/es/core/document/PDFCrossRefSection.js.map +1 -1
- package/es/core/parser/PDFParser.d.ts.map +1 -1
- package/es/core/parser/PDFParser.js +6 -0
- package/es/core/parser/PDFParser.js.map +1 -1
- package/es/core/parser/PDFXRefStreamParser.d.ts.map +1 -1
- package/es/core/parser/PDFXRefStreamParser.js +6 -0
- package/es/core/parser/PDFXRefStreamParser.js.map +1 -1
- package/es/core/writers/PDFStreamWriter.d.ts +7 -7
- package/es/core/writers/PDFStreamWriter.d.ts.map +1 -1
- package/es/core/writers/PDFStreamWriter.js +16 -16
- package/es/core/writers/PDFStreamWriter.js.map +1 -1
- package/es/core/writers/PDFWriter.d.ts +10 -10
- package/es/core/writers/PDFWriter.d.ts.map +1 -1
- package/es/core/writers/PDFWriter.js +20 -10
- package/es/core/writers/PDFWriter.js.map +1 -1
- package/package.json +4 -4
- package/src/api/PDFDocument.ts +14 -11
- package/src/api/index.ts +21 -21
- package/src/api/snapshot/DefaultDocumentSnapshot.ts +15 -2
- package/src/api/snapshot/DocumentSnapshot.ts +7 -1
- package/src/api/snapshot/IncrementalDocumentSnapshot.ts +22 -2
- package/src/core/PDFContext.ts +3 -1
- package/src/core/document/PDFCrossRefSection.ts +46 -2
- package/src/core/parser/PDFParser.ts +7 -0
- package/src/core/parser/PDFXRefStreamParser.ts +8 -0
- package/src/core/writers/PDFStreamWriter.ts +19 -18
- package/src/core/writers/PDFWriter.ts +27 -16
- package/ts3.4/cjs/api/PDFDocument.d.ts +5 -5
- package/ts3.4/cjs/api/index.d.ts +21 -21
- package/ts3.4/cjs/api/snapshot/DefaultDocumentSnapshot.d.ts +5 -1
- package/ts3.4/cjs/api/snapshot/DocumentSnapshot.d.ts +5 -1
- package/ts3.4/cjs/api/snapshot/IncrementalDocumentSnapshot.d.ts +6 -1
- package/ts3.4/cjs/core/PDFContext.d.ts +2 -1
- package/ts3.4/cjs/core/document/PDFCrossRefSection.d.ts +1 -1
- package/ts3.4/cjs/core/writers/PDFStreamWriter.d.ts +7 -7
- package/ts3.4/cjs/core/writers/PDFWriter.d.ts +10 -10
- package/ts3.4/es/api/PDFDocument.d.ts +5 -5
- package/ts3.4/es/api/index.d.ts +21 -21
- package/ts3.4/es/api/snapshot/DefaultDocumentSnapshot.d.ts +5 -1
- package/ts3.4/es/api/snapshot/DocumentSnapshot.d.ts +5 -1
- package/ts3.4/es/api/snapshot/IncrementalDocumentSnapshot.d.ts +6 -1
- package/ts3.4/es/core/PDFContext.d.ts +2 -1
- package/ts3.4/es/core/document/PDFCrossRefSection.d.ts +1 -1
- package/ts3.4/es/core/writers/PDFStreamWriter.d.ts +7 -7
- package/ts3.4/es/core/writers/PDFWriter.d.ts +10 -10
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { PDFObject, PDFRef } from '
|
|
2
|
-
import { DocumentSnapshot } from './DocumentSnapshot';
|
|
1
|
+
import type { PDFObject, PDFRef } from '../../core';
|
|
2
|
+
import type { DocumentSnapshot } from './DocumentSnapshot';
|
|
3
3
|
|
|
4
4
|
export class DefaultDocumentSnapshot implements DocumentSnapshot {
|
|
5
5
|
pdfSize = 0;
|
|
6
6
|
prevStartXRef = 0;
|
|
7
|
+
deletedCount = 0;
|
|
7
8
|
|
|
8
9
|
shouldSave(_objectNumber: number): boolean {
|
|
9
10
|
return true;
|
|
@@ -24,6 +25,18 @@ export class DefaultDocumentSnapshot implements DocumentSnapshot {
|
|
|
24
25
|
markObjsForSave(_objs: PDFObject[]): void {
|
|
25
26
|
throw new Error('This method should not be called.');
|
|
26
27
|
}
|
|
28
|
+
|
|
29
|
+
markDeletedObj(_obj: PDFObject): void {
|
|
30
|
+
throw new Error('This method should not be called.');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
markDeletedRef(_ref: PDFRef): void {
|
|
34
|
+
throw new Error('This method should not be called.');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
deletedRef(_index: number): PDFRef | null {
|
|
38
|
+
throw new Error('This method should not be called.');
|
|
39
|
+
}
|
|
27
40
|
}
|
|
28
41
|
|
|
29
42
|
export const defaultDocumentSnapshot = new DefaultDocumentSnapshot();
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { PDFObject, PDFRef } from '
|
|
1
|
+
import type { PDFObject, PDFRef } from '../../core';
|
|
2
2
|
|
|
3
3
|
export interface DocumentSnapshot {
|
|
4
4
|
pdfSize: number;
|
|
5
5
|
prevStartXRef: number;
|
|
6
|
+
deletedCount: number;
|
|
6
7
|
|
|
7
8
|
shouldSave: (objectNumber: number) => boolean;
|
|
8
9
|
|
|
@@ -11,4 +12,9 @@ export interface DocumentSnapshot {
|
|
|
11
12
|
|
|
12
13
|
markObjForSave: (obj: PDFObject) => void;
|
|
13
14
|
markObjsForSave: (objs: PDFObject[]) => void;
|
|
15
|
+
|
|
16
|
+
markDeletedRef: (ref: PDFRef) => void;
|
|
17
|
+
markDeletedObj: (obj: PDFObject) => void;
|
|
18
|
+
|
|
19
|
+
deletedRef: (index: number) => PDFRef | null;
|
|
14
20
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type { PDFContext, PDFObject, PDFRef } from '
|
|
2
|
-
import { DocumentSnapshot } from './DocumentSnapshot';
|
|
1
|
+
import type { PDFContext, PDFObject, PDFRef } from '../../core';
|
|
2
|
+
import type { DocumentSnapshot } from './DocumentSnapshot';
|
|
3
3
|
|
|
4
4
|
export class IncrementalDocumentSnapshot implements DocumentSnapshot {
|
|
5
5
|
pdfSize: number;
|
|
6
6
|
prevStartXRef: number;
|
|
7
|
+
deletedCount: number = 0;
|
|
7
8
|
|
|
9
|
+
private deleted: PDFRef[] = [];
|
|
8
10
|
private lastObjectNumber: number;
|
|
9
11
|
private changedObjects: number[];
|
|
10
12
|
|
|
@@ -56,4 +58,22 @@ export class IncrementalDocumentSnapshot implements DocumentSnapshot {
|
|
|
56
58
|
.filter((ref) => ref !== undefined) as PDFRef[],
|
|
57
59
|
);
|
|
58
60
|
}
|
|
61
|
+
|
|
62
|
+
markDeletedRef(ref: PDFRef): void {
|
|
63
|
+
if (
|
|
64
|
+
this.deleted.findIndex((dref) => dref.objectNumber === ref.objectNumber) <
|
|
65
|
+
0
|
|
66
|
+
)
|
|
67
|
+
this.deletedCount = this.deleted.push(ref);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
markDeletedObj(obj: PDFObject): void {
|
|
71
|
+
const oref = this.context.getRef(obj);
|
|
72
|
+
if (oref) this.markDeletedRef(oref);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
deletedRef(index: number): PDFRef | null {
|
|
76
|
+
if (index < 0 || index >= this.deleted.length) return null;
|
|
77
|
+
return this.deleted[index];
|
|
78
|
+
}
|
|
59
79
|
}
|
package/src/core/PDFContext.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import pako from 'pako';
|
|
2
|
-
import { DocumentSnapshot } from '
|
|
2
|
+
import type { DocumentSnapshot } from '../api';
|
|
3
3
|
|
|
4
4
|
import PDFHeader from './document/PDFHeader';
|
|
5
5
|
import { UnexpectedObjectTypeError } from './errors';
|
|
@@ -60,6 +60,7 @@ class PDFContext {
|
|
|
60
60
|
largestObjectNumber: number;
|
|
61
61
|
header: PDFHeader;
|
|
62
62
|
trailerInfo: {
|
|
63
|
+
Size?: PDFNumber;
|
|
63
64
|
Root?: PDFObject;
|
|
64
65
|
Encrypt?: PDFObject;
|
|
65
66
|
Info?: PDFObject;
|
|
@@ -114,6 +115,7 @@ class PDFContext {
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
delete(ref: PDFRef): boolean {
|
|
118
|
+
if (this.snapshot) this.snapshot.markDeletedRef(ref);
|
|
117
119
|
return this.indirectObjects.delete(ref);
|
|
118
120
|
}
|
|
119
121
|
|
|
@@ -10,7 +10,7 @@ export interface Entry {
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Entries should be added using the [[addEntry]] and [[addDeletedEntry]]
|
|
13
|
-
* methods
|
|
13
|
+
* methods.
|
|
14
14
|
*/
|
|
15
15
|
class PDFCrossRefSection {
|
|
16
16
|
static create = () =>
|
|
@@ -37,6 +37,22 @@ class PDFCrossRefSection {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
addDeletedEntry(ref: PDFRef, nextFreeObjectNumber: number): void {
|
|
40
|
+
// fix the first entry if required
|
|
41
|
+
if (!this.subsections.length) {
|
|
42
|
+
this.subsections = [
|
|
43
|
+
[
|
|
44
|
+
{
|
|
45
|
+
ref: PDFRef.of(0, 65535),
|
|
46
|
+
offset: ref.objectNumber,
|
|
47
|
+
deleted: true,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
];
|
|
51
|
+
this.chunkIdx = 0;
|
|
52
|
+
this.chunkLength = 1;
|
|
53
|
+
} else if (!this.subsections[0][0].offset) {
|
|
54
|
+
this.subsections[0][0].offset = ref.objectNumber;
|
|
55
|
+
}
|
|
40
56
|
this.append({ ref, offset: nextFreeObjectNumber, deleted: true });
|
|
41
57
|
}
|
|
42
58
|
|
|
@@ -159,7 +175,35 @@ class PDFCrossRefSection {
|
|
|
159
175
|
const chunk = this.subsections[this.chunkIdx];
|
|
160
176
|
const prevEntry = chunk[this.chunkLength - 1];
|
|
161
177
|
|
|
162
|
-
if (currEntry.ref.objectNumber - prevEntry.ref.objectNumber
|
|
178
|
+
if (currEntry.ref.objectNumber - prevEntry.ref.objectNumber !== 1) {
|
|
179
|
+
// the current chunk is not the right chunk, find the right one, or create a new one
|
|
180
|
+
for (let c = 0; c < this.subsections.length; c++) {
|
|
181
|
+
const first = this.subsections[c][0];
|
|
182
|
+
const last = this.subsections[c][this.subsections[c].length - 1];
|
|
183
|
+
if (first.ref.objectNumber > currEntry.ref.objectNumber) {
|
|
184
|
+
// goes before this subsection, or at the start of it
|
|
185
|
+
if (first.ref.objectNumber - currEntry.ref.objectNumber === 1) {
|
|
186
|
+
// first element of subsection
|
|
187
|
+
this.subsections[c].unshift(currEntry);
|
|
188
|
+
if (c === this.chunkIdx) this.chunkLength += 1;
|
|
189
|
+
return;
|
|
190
|
+
} else {
|
|
191
|
+
// create subsection
|
|
192
|
+
this.subsections.splice(c, 0, [currEntry]);
|
|
193
|
+
this.chunkIdx++;
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
} else if (last.ref.objectNumber > currEntry.ref.objectNumber) {
|
|
197
|
+
// goes in this subsection, find its place..
|
|
198
|
+
const cep = this.subsections[c].findIndex(
|
|
199
|
+
(ee) => ee.ref.objectNumber > currEntry.ref.objectNumber,
|
|
200
|
+
);
|
|
201
|
+
this.subsections[c].splice(cep, 0, currEntry);
|
|
202
|
+
if (c === this.chunkIdx) this.chunkLength += 1;
|
|
203
|
+
}
|
|
204
|
+
// bigger, keep looking
|
|
205
|
+
}
|
|
206
|
+
// if got to here, then a new subsection is required
|
|
163
207
|
this.subsections.push([currEntry]);
|
|
164
208
|
this.chunkIdx += 1;
|
|
165
209
|
this.chunkLength = 1;
|
|
@@ -24,6 +24,7 @@ import { Keywords } from '../syntax/Keywords';
|
|
|
24
24
|
import { IsDigit } from '../syntax/Numeric';
|
|
25
25
|
import { waitForTick } from '../../utils';
|
|
26
26
|
import { CipherTransformFactory } from '../crypto';
|
|
27
|
+
import PDFNumber from '../objects/PDFNumber';
|
|
27
28
|
|
|
28
29
|
class PDFParser extends PDFObjectParser {
|
|
29
30
|
static forBytesWithOptions = (
|
|
@@ -307,11 +308,17 @@ class PDFParser extends PDFObjectParser {
|
|
|
307
308
|
|
|
308
309
|
const { context } = this;
|
|
309
310
|
context.trailerInfo = {
|
|
311
|
+
Size:
|
|
312
|
+
dict.lookupMaybe(PDFName.of('Size'), PDFNumber) ||
|
|
313
|
+
context.trailerInfo.Size,
|
|
310
314
|
Root: dict.get(PDFName.of('Root')) || context.trailerInfo.Root,
|
|
311
315
|
Encrypt: dict.get(PDFName.of('Encrypt')) || context.trailerInfo.Encrypt,
|
|
312
316
|
Info: dict.get(PDFName.of('Info')) || context.trailerInfo.Info,
|
|
313
317
|
ID: dict.get(PDFName.of('ID')) || context.trailerInfo.ID,
|
|
314
318
|
};
|
|
319
|
+
// if open for incremental update, then deleted objects need to be preserved, and largestObjectNumber has to be Size-1
|
|
320
|
+
if (context.trailerInfo.Size && context.pdfFileDetails.originalBytes)
|
|
321
|
+
context.largestObjectNumber = context.trailerInfo.Size.asNumber() - 1;
|
|
315
322
|
}
|
|
316
323
|
|
|
317
324
|
private maybeParseTrailer(): PDFTrailer | void {
|
|
@@ -66,11 +66,19 @@ class PDFXRefStreamParser {
|
|
|
66
66
|
this.alreadyParsed = true;
|
|
67
67
|
|
|
68
68
|
this.context.trailerInfo = {
|
|
69
|
+
Size: this.dict.lookup(PDFName.of('Size'), PDFNumber),
|
|
69
70
|
Root: this.dict.get(PDFName.of('Root')),
|
|
70
71
|
Encrypt: this.dict.get(PDFName.of('Encrypt')),
|
|
71
72
|
Info: this.dict.get(PDFName.of('Info')),
|
|
72
73
|
ID: this.dict.get(PDFName.of('ID')),
|
|
73
74
|
};
|
|
75
|
+
// if open for incremental update, make sure next object number doesn't overlap a deleted one
|
|
76
|
+
if (
|
|
77
|
+
this.context.trailerInfo.Size &&
|
|
78
|
+
this.context.pdfFileDetails.originalBytes
|
|
79
|
+
)
|
|
80
|
+
this.context.largestObjectNumber =
|
|
81
|
+
this.context.trailerInfo.Size.asNumber() - 1;
|
|
74
82
|
|
|
75
83
|
const entries = this.parseEntries();
|
|
76
84
|
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { defaultDocumentSnapshot
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
1
|
+
import { defaultDocumentSnapshot } from '../../api/snapshot';
|
|
2
|
+
import type { DocumentSnapshot } from '../../api/snapshot';
|
|
3
|
+
import PDFHeader from '../document/PDFHeader';
|
|
4
|
+
import PDFTrailer from '../document/PDFTrailer';
|
|
5
|
+
import PDFInvalidObject from '../objects/PDFInvalidObject';
|
|
6
|
+
import PDFName from '../objects/PDFName';
|
|
7
|
+
import PDFNumber from '../objects/PDFNumber';
|
|
8
|
+
import PDFObject from '../objects/PDFObject';
|
|
9
|
+
import PDFRef from '../objects/PDFRef';
|
|
10
|
+
import PDFStream from '../objects/PDFStream';
|
|
11
|
+
import PDFContext from '../PDFContext';
|
|
12
|
+
import PDFCrossRefStream from '../structures/PDFCrossRefStream';
|
|
13
|
+
import PDFObjectStream from '../structures/PDFObjectStream';
|
|
14
|
+
import PDFWriter from '../writers/PDFWriter';
|
|
15
|
+
import { last, waitForTick } from '../../utils';
|
|
16
|
+
import PDFDict from '../objects/PDFDict';
|
|
17
|
+
import PDFCatalog from '../structures/PDFCatalog';
|
|
18
|
+
import PDFPageTree from '../structures/PDFPageTree';
|
|
19
|
+
import PDFPageLeaf from '../structures/PDFPageLeaf';
|
|
19
20
|
|
|
20
21
|
class PDFStreamWriter extends PDFWriter {
|
|
21
22
|
static forContext = (
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DefaultDocumentSnapshot,
|
|
3
3
|
defaultDocumentSnapshot,
|
|
4
|
-
} from '
|
|
5
|
-
import type { DocumentSnapshot } from '
|
|
6
|
-
import PDFCrossRefSection from '
|
|
7
|
-
import PDFHeader from '
|
|
8
|
-
import PDFTrailer from '
|
|
9
|
-
import PDFTrailerDict from '
|
|
10
|
-
import PDFDict from '
|
|
11
|
-
import PDFObject from '
|
|
12
|
-
import PDFRef from '
|
|
13
|
-
import PDFContext from '
|
|
14
|
-
import PDFObjectStream from '
|
|
15
|
-
import CharCodes from '
|
|
16
|
-
import { copyStringIntoBuffer, waitForTick } from '
|
|
17
|
-
import PDFNumber from '
|
|
18
|
-
import PDFSecurity from '
|
|
19
|
-
import PDFStream from '
|
|
4
|
+
} from '../../api/snapshot';
|
|
5
|
+
import type { DocumentSnapshot } from '../../api/snapshot';
|
|
6
|
+
import PDFCrossRefSection from '../document/PDFCrossRefSection';
|
|
7
|
+
import PDFHeader from '../document/PDFHeader';
|
|
8
|
+
import PDFTrailer from '../document/PDFTrailer';
|
|
9
|
+
import PDFTrailerDict from '../document/PDFTrailerDict';
|
|
10
|
+
import PDFDict from '../objects/PDFDict';
|
|
11
|
+
import PDFObject from '../objects/PDFObject';
|
|
12
|
+
import PDFRef from '../objects/PDFRef';
|
|
13
|
+
import PDFContext from '../PDFContext';
|
|
14
|
+
import PDFObjectStream from '../structures/PDFObjectStream';
|
|
15
|
+
import CharCodes from '../syntax/CharCodes';
|
|
16
|
+
import { copyStringIntoBuffer, waitForTick } from '../../utils';
|
|
17
|
+
import PDFNumber from '../objects/PDFNumber';
|
|
18
|
+
import PDFSecurity from '../security/PDFSecurity';
|
|
19
|
+
import PDFStream from '../objects/PDFStream';
|
|
20
20
|
|
|
21
21
|
export interface SerializationInfo {
|
|
22
22
|
size: number;
|
|
@@ -166,6 +166,17 @@ class PDFWriter {
|
|
|
166
166
|
size += this.computeIndirectObjectSize(indirectObject);
|
|
167
167
|
if (this.shouldWaitForTick(1)) await waitForTick();
|
|
168
168
|
}
|
|
169
|
+
// deleted objects
|
|
170
|
+
for (let idx = 0; idx < this.snapshot.deletedCount; idx++) {
|
|
171
|
+
const dref = this.snapshot.deletedRef(idx);
|
|
172
|
+
if (!dref) break;
|
|
173
|
+
const nextdref = this.snapshot.deletedRef(idx + 1);
|
|
174
|
+
// add 1 to generation number for deleted ref
|
|
175
|
+
xref.addDeletedEntry(
|
|
176
|
+
PDFRef.of(dref.objectNumber, dref.generationNumber + 1),
|
|
177
|
+
nextdref ? nextdref.objectNumber : 0,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
169
180
|
|
|
170
181
|
const xrefOffset = size;
|
|
171
182
|
size += xref.sizeInBytes() + 1; // '\n'
|
|
@@ -5,11 +5,11 @@ import PDFPage from './PDFPage';
|
|
|
5
5
|
import PDFForm from './form/PDFForm';
|
|
6
6
|
import { StandardFonts } from './StandardFonts';
|
|
7
7
|
import { PageBoundingBox, PDFCatalog, PDFContext } from '../core';
|
|
8
|
-
import { AttachmentOptions, SaveOptions, Base64SaveOptions, LoadOptions, CreateOptions, EmbedFontOptions, SetTitleOptions, IncrementalSaveOptions } from '
|
|
9
|
-
import PDFRef from '
|
|
10
|
-
import { Fontkit } from '
|
|
11
|
-
import { TransformationMatrix } from '
|
|
12
|
-
import { AFRelationship } from '
|
|
8
|
+
import { AttachmentOptions, SaveOptions, Base64SaveOptions, LoadOptions, CreateOptions, EmbedFontOptions, SetTitleOptions, IncrementalSaveOptions } from './PDFDocumentOptions';
|
|
9
|
+
import PDFRef from '../core/objects/PDFRef';
|
|
10
|
+
import { Fontkit } from '../types/fontkit';
|
|
11
|
+
import { TransformationMatrix } from '../types/matrix';
|
|
12
|
+
import { AFRelationship } from '../core/embedders/FileEmbedder';
|
|
13
13
|
import PDFSvg from './PDFSvg';
|
|
14
14
|
import { SecurityOptions } from '../core/security/PDFSecurity';
|
|
15
15
|
import { DocumentSnapshot } from './snapshot';
|
package/ts3.4/cjs/api/index.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from '
|
|
3
|
-
export * from '
|
|
4
|
-
export * from '
|
|
5
|
-
export * from '
|
|
6
|
-
export * from '
|
|
7
|
-
export * from '
|
|
8
|
-
export * from '
|
|
9
|
-
export * from '
|
|
10
|
-
export * from '
|
|
11
|
-
export * from '
|
|
12
|
-
export * from '
|
|
13
|
-
export * from '
|
|
14
|
-
export * from '
|
|
15
|
-
export { default as PDFDocument } from '
|
|
16
|
-
export { default as PDFFont } from '
|
|
17
|
-
export { default as PDFImage } from '
|
|
18
|
-
export { default as PDFPage } from '
|
|
19
|
-
export { default as PDFEmbeddedPage } from '
|
|
20
|
-
export { default as PDFJavaScript } from '
|
|
21
|
-
export { default as Embeddable } from '
|
|
1
|
+
export * from './form';
|
|
2
|
+
export * from './text';
|
|
3
|
+
export * from './colors';
|
|
4
|
+
export * from './errors';
|
|
5
|
+
export * from './image';
|
|
6
|
+
export * from './objects';
|
|
7
|
+
export * from './operations';
|
|
8
|
+
export * from './operators';
|
|
9
|
+
export * from './rotations';
|
|
10
|
+
export * from './sizes';
|
|
11
|
+
export * from './snapshot';
|
|
12
|
+
export * from './PDFPageOptions';
|
|
13
|
+
export * from './PDFDocumentOptions';
|
|
14
|
+
export * from './StandardFonts';
|
|
15
|
+
export { default as PDFDocument } from './PDFDocument';
|
|
16
|
+
export { default as PDFFont } from './PDFFont';
|
|
17
|
+
export { default as PDFImage } from './PDFImage';
|
|
18
|
+
export { default as PDFPage } from './PDFPage';
|
|
19
|
+
export { default as PDFEmbeddedPage } from './PDFEmbeddedPage';
|
|
20
|
+
export { default as PDFJavaScript } from './PDFJavaScript';
|
|
21
|
+
export { default as Embeddable } from './Embeddable';
|
|
22
22
|
export { default as PDFSvg } from './PDFSvg';
|
|
23
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { PDFObject, PDFRef } from '
|
|
1
|
+
import { PDFObject, PDFRef } from '../../core';
|
|
2
2
|
import { DocumentSnapshot } from './DocumentSnapshot';
|
|
3
3
|
export declare class DefaultDocumentSnapshot implements DocumentSnapshot {
|
|
4
4
|
pdfSize: number;
|
|
5
5
|
prevStartXRef: number;
|
|
6
|
+
deletedCount: number;
|
|
6
7
|
shouldSave(_objectNumber: number): boolean;
|
|
7
8
|
markRefForSave(_ref: PDFRef): void;
|
|
8
9
|
markRefsForSave(_refs: PDFRef[]): void;
|
|
9
10
|
markObjForSave(_obj: PDFObject): void;
|
|
10
11
|
markObjsForSave(_objs: PDFObject[]): void;
|
|
12
|
+
markDeletedObj(_obj: PDFObject): void;
|
|
13
|
+
markDeletedRef(_ref: PDFRef): void;
|
|
14
|
+
deletedRef(_index: number): PDFRef | null;
|
|
11
15
|
}
|
|
12
16
|
export declare const defaultDocumentSnapshot: DefaultDocumentSnapshot;
|
|
13
17
|
//# sourceMappingURL=DefaultDocumentSnapshot.d.ts.map
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { PDFObject, PDFRef } from '
|
|
1
|
+
import { PDFObject, PDFRef } from '../../core';
|
|
2
2
|
export interface DocumentSnapshot {
|
|
3
3
|
pdfSize: number;
|
|
4
4
|
prevStartXRef: number;
|
|
5
|
+
deletedCount: number;
|
|
5
6
|
shouldSave: (objectNumber: number) => boolean;
|
|
6
7
|
markRefForSave: (ref: PDFRef) => void;
|
|
7
8
|
markRefsForSave: (refs: PDFRef[]) => void;
|
|
8
9
|
markObjForSave: (obj: PDFObject) => void;
|
|
9
10
|
markObjsForSave: (objs: PDFObject[]) => void;
|
|
11
|
+
markDeletedRef: (ref: PDFRef) => void;
|
|
12
|
+
markDeletedObj: (obj: PDFObject) => void;
|
|
13
|
+
deletedRef: (index: number) => PDFRef | null;
|
|
10
14
|
}
|
|
11
15
|
//# sourceMappingURL=DocumentSnapshot.d.ts.map
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { PDFContext, PDFObject, PDFRef } from '
|
|
1
|
+
import { PDFContext, PDFObject, PDFRef } from '../../core';
|
|
2
2
|
import { DocumentSnapshot } from './DocumentSnapshot';
|
|
3
3
|
export declare class IncrementalDocumentSnapshot implements DocumentSnapshot {
|
|
4
4
|
pdfSize: number;
|
|
5
5
|
prevStartXRef: number;
|
|
6
|
+
deletedCount: number;
|
|
7
|
+
private deleted;
|
|
6
8
|
private lastObjectNumber;
|
|
7
9
|
private changedObjects;
|
|
8
10
|
context: PDFContext;
|
|
@@ -12,5 +14,8 @@ export declare class IncrementalDocumentSnapshot implements DocumentSnapshot {
|
|
|
12
14
|
markRefsForSave(refs: PDFRef[]): void;
|
|
13
15
|
markObjForSave(obj: PDFObject): void;
|
|
14
16
|
markObjsForSave(objs: PDFObject[]): void;
|
|
17
|
+
markDeletedRef(ref: PDFRef): void;
|
|
18
|
+
markDeletedObj(obj: PDFObject): void;
|
|
19
|
+
deletedRef(index: number): PDFRef | null;
|
|
15
20
|
}
|
|
16
21
|
//# sourceMappingURL=IncrementalDocumentSnapshot.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DocumentSnapshot } from '
|
|
1
|
+
import { DocumentSnapshot } from '../api';
|
|
2
2
|
import PDFHeader from './document/PDFHeader';
|
|
3
3
|
import PDFArray from './objects/PDFArray';
|
|
4
4
|
import PDFBool from './objects/PDFBool';
|
|
@@ -36,6 +36,7 @@ declare class PDFContext {
|
|
|
36
36
|
largestObjectNumber: number;
|
|
37
37
|
header: PDFHeader;
|
|
38
38
|
trailerInfo: {
|
|
39
|
+
Size?: PDFNumber;
|
|
39
40
|
Root?: PDFObject;
|
|
40
41
|
Encrypt?: PDFObject;
|
|
41
42
|
Info?: PDFObject;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { DocumentSnapshot } from '
|
|
2
|
-
import PDFHeader from '
|
|
3
|
-
import PDFTrailer from '
|
|
4
|
-
import PDFObject from '
|
|
5
|
-
import PDFRef from '
|
|
6
|
-
import PDFContext from '
|
|
7
|
-
import PDFWriter from '
|
|
1
|
+
import { DocumentSnapshot } from '../../api/snapshot';
|
|
2
|
+
import PDFHeader from '../document/PDFHeader';
|
|
3
|
+
import PDFTrailer from '../document/PDFTrailer';
|
|
4
|
+
import PDFObject from '../objects/PDFObject';
|
|
5
|
+
import PDFRef from '../objects/PDFRef';
|
|
6
|
+
import PDFContext from '../PDFContext';
|
|
7
|
+
import PDFWriter from '../writers/PDFWriter';
|
|
8
8
|
declare class PDFStreamWriter extends PDFWriter {
|
|
9
9
|
static forContext: (context: PDFContext, objectsPerTick: number, encodeStreams?: boolean, objectsPerStream?: number) => PDFStreamWriter;
|
|
10
10
|
static forContextWithSnapshot: (context: PDFContext, objectsPerTick: number, snapshot: DocumentSnapshot, encodeStreams?: boolean, objectsPerStream?: number) => PDFStreamWriter;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { DocumentSnapshot } from '
|
|
2
|
-
import PDFCrossRefSection from '
|
|
3
|
-
import PDFHeader from '
|
|
4
|
-
import PDFTrailer from '
|
|
5
|
-
import PDFTrailerDict from '
|
|
6
|
-
import PDFDict from '
|
|
7
|
-
import PDFObject from '
|
|
8
|
-
import PDFRef from '
|
|
9
|
-
import PDFContext from '
|
|
10
|
-
import PDFSecurity from '
|
|
1
|
+
import { DocumentSnapshot } from '../../api/snapshot';
|
|
2
|
+
import PDFCrossRefSection from '../document/PDFCrossRefSection';
|
|
3
|
+
import PDFHeader from '../document/PDFHeader';
|
|
4
|
+
import PDFTrailer from '../document/PDFTrailer';
|
|
5
|
+
import PDFTrailerDict from '../document/PDFTrailerDict';
|
|
6
|
+
import PDFDict from '../objects/PDFDict';
|
|
7
|
+
import PDFObject from '../objects/PDFObject';
|
|
8
|
+
import PDFRef from '../objects/PDFRef';
|
|
9
|
+
import PDFContext from '../PDFContext';
|
|
10
|
+
import PDFSecurity from '../security/PDFSecurity';
|
|
11
11
|
export interface SerializationInfo {
|
|
12
12
|
size: number;
|
|
13
13
|
header: PDFHeader;
|
|
@@ -5,11 +5,11 @@ import PDFPage from './PDFPage';
|
|
|
5
5
|
import PDFForm from './form/PDFForm';
|
|
6
6
|
import { StandardFonts } from './StandardFonts';
|
|
7
7
|
import { PageBoundingBox, PDFCatalog, PDFContext } from '../core';
|
|
8
|
-
import { AttachmentOptions, SaveOptions, Base64SaveOptions, LoadOptions, CreateOptions, EmbedFontOptions, SetTitleOptions, IncrementalSaveOptions } from '
|
|
9
|
-
import PDFRef from '
|
|
10
|
-
import { Fontkit } from '
|
|
11
|
-
import { TransformationMatrix } from '
|
|
12
|
-
import { AFRelationship } from '
|
|
8
|
+
import { AttachmentOptions, SaveOptions, Base64SaveOptions, LoadOptions, CreateOptions, EmbedFontOptions, SetTitleOptions, IncrementalSaveOptions } from './PDFDocumentOptions';
|
|
9
|
+
import PDFRef from '../core/objects/PDFRef';
|
|
10
|
+
import { Fontkit } from '../types/fontkit';
|
|
11
|
+
import { TransformationMatrix } from '../types/matrix';
|
|
12
|
+
import { AFRelationship } from '../core/embedders/FileEmbedder';
|
|
13
13
|
import PDFSvg from './PDFSvg';
|
|
14
14
|
import { SecurityOptions } from '../core/security/PDFSecurity';
|
|
15
15
|
import { DocumentSnapshot } from './snapshot';
|
package/ts3.4/es/api/index.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
export * from '
|
|
2
|
-
export * from '
|
|
3
|
-
export * from '
|
|
4
|
-
export * from '
|
|
5
|
-
export * from '
|
|
6
|
-
export * from '
|
|
7
|
-
export * from '
|
|
8
|
-
export * from '
|
|
9
|
-
export * from '
|
|
10
|
-
export * from '
|
|
11
|
-
export * from '
|
|
12
|
-
export * from '
|
|
13
|
-
export * from '
|
|
14
|
-
export * from '
|
|
15
|
-
export { default as PDFDocument } from '
|
|
16
|
-
export { default as PDFFont } from '
|
|
17
|
-
export { default as PDFImage } from '
|
|
18
|
-
export { default as PDFPage } from '
|
|
19
|
-
export { default as PDFEmbeddedPage } from '
|
|
20
|
-
export { default as PDFJavaScript } from '
|
|
21
|
-
export { default as Embeddable } from '
|
|
1
|
+
export * from './form';
|
|
2
|
+
export * from './text';
|
|
3
|
+
export * from './colors';
|
|
4
|
+
export * from './errors';
|
|
5
|
+
export * from './image';
|
|
6
|
+
export * from './objects';
|
|
7
|
+
export * from './operations';
|
|
8
|
+
export * from './operators';
|
|
9
|
+
export * from './rotations';
|
|
10
|
+
export * from './sizes';
|
|
11
|
+
export * from './snapshot';
|
|
12
|
+
export * from './PDFPageOptions';
|
|
13
|
+
export * from './PDFDocumentOptions';
|
|
14
|
+
export * from './StandardFonts';
|
|
15
|
+
export { default as PDFDocument } from './PDFDocument';
|
|
16
|
+
export { default as PDFFont } from './PDFFont';
|
|
17
|
+
export { default as PDFImage } from './PDFImage';
|
|
18
|
+
export { default as PDFPage } from './PDFPage';
|
|
19
|
+
export { default as PDFEmbeddedPage } from './PDFEmbeddedPage';
|
|
20
|
+
export { default as PDFJavaScript } from './PDFJavaScript';
|
|
21
|
+
export { default as Embeddable } from './Embeddable';
|
|
22
22
|
export { default as PDFSvg } from './PDFSvg';
|
|
23
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { PDFObject, PDFRef } from '
|
|
1
|
+
import { PDFObject, PDFRef } from '../../core';
|
|
2
2
|
import { DocumentSnapshot } from './DocumentSnapshot';
|
|
3
3
|
export declare class DefaultDocumentSnapshot implements DocumentSnapshot {
|
|
4
4
|
pdfSize: number;
|
|
5
5
|
prevStartXRef: number;
|
|
6
|
+
deletedCount: number;
|
|
6
7
|
shouldSave(_objectNumber: number): boolean;
|
|
7
8
|
markRefForSave(_ref: PDFRef): void;
|
|
8
9
|
markRefsForSave(_refs: PDFRef[]): void;
|
|
9
10
|
markObjForSave(_obj: PDFObject): void;
|
|
10
11
|
markObjsForSave(_objs: PDFObject[]): void;
|
|
12
|
+
markDeletedObj(_obj: PDFObject): void;
|
|
13
|
+
markDeletedRef(_ref: PDFRef): void;
|
|
14
|
+
deletedRef(_index: number): PDFRef | null;
|
|
11
15
|
}
|
|
12
16
|
export declare const defaultDocumentSnapshot: DefaultDocumentSnapshot;
|
|
13
17
|
//# sourceMappingURL=DefaultDocumentSnapshot.d.ts.map
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { PDFObject, PDFRef } from '
|
|
1
|
+
import { PDFObject, PDFRef } from '../../core';
|
|
2
2
|
export interface DocumentSnapshot {
|
|
3
3
|
pdfSize: number;
|
|
4
4
|
prevStartXRef: number;
|
|
5
|
+
deletedCount: number;
|
|
5
6
|
shouldSave: (objectNumber: number) => boolean;
|
|
6
7
|
markRefForSave: (ref: PDFRef) => void;
|
|
7
8
|
markRefsForSave: (refs: PDFRef[]) => void;
|
|
8
9
|
markObjForSave: (obj: PDFObject) => void;
|
|
9
10
|
markObjsForSave: (objs: PDFObject[]) => void;
|
|
11
|
+
markDeletedRef: (ref: PDFRef) => void;
|
|
12
|
+
markDeletedObj: (obj: PDFObject) => void;
|
|
13
|
+
deletedRef: (index: number) => PDFRef | null;
|
|
10
14
|
}
|
|
11
15
|
//# sourceMappingURL=DocumentSnapshot.d.ts.map
|