@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.
Files changed (118) hide show
  1. package/cjs/api/PDFDocument.d.ts +6 -6
  2. package/cjs/api/PDFDocument.d.ts.map +1 -1
  3. package/cjs/api/PDFDocument.js +8 -6
  4. package/cjs/api/PDFDocument.js.map +1 -1
  5. package/cjs/api/index.d.ts +21 -21
  6. package/cjs/api/index.d.ts.map +1 -1
  7. package/cjs/api/index.js +20 -20
  8. package/cjs/api/index.js.map +1 -1
  9. package/cjs/api/snapshot/DefaultDocumentSnapshot.d.ts +6 -2
  10. package/cjs/api/snapshot/DefaultDocumentSnapshot.d.ts.map +1 -1
  11. package/cjs/api/snapshot/DefaultDocumentSnapshot.js +10 -0
  12. package/cjs/api/snapshot/DefaultDocumentSnapshot.js.map +1 -1
  13. package/cjs/api/snapshot/DocumentSnapshot.d.ts +5 -1
  14. package/cjs/api/snapshot/DocumentSnapshot.d.ts.map +1 -1
  15. package/cjs/api/snapshot/IncrementalDocumentSnapshot.d.ts +7 -2
  16. package/cjs/api/snapshot/IncrementalDocumentSnapshot.d.ts.map +1 -1
  17. package/cjs/api/snapshot/IncrementalDocumentSnapshot.js +17 -0
  18. package/cjs/api/snapshot/IncrementalDocumentSnapshot.js.map +1 -1
  19. package/cjs/core/PDFContext.d.ts +2 -1
  20. package/cjs/core/PDFContext.d.ts.map +1 -1
  21. package/cjs/core/PDFContext.js +2 -0
  22. package/cjs/core/PDFContext.js.map +1 -1
  23. package/cjs/core/document/PDFCrossRefSection.d.ts +1 -1
  24. package/cjs/core/document/PDFCrossRefSection.d.ts.map +1 -1
  25. package/cjs/core/document/PDFCrossRefSection.js +49 -2
  26. package/cjs/core/document/PDFCrossRefSection.js.map +1 -1
  27. package/cjs/core/parser/PDFParser.d.ts.map +1 -1
  28. package/cjs/core/parser/PDFParser.js +6 -0
  29. package/cjs/core/parser/PDFParser.js.map +1 -1
  30. package/cjs/core/parser/PDFXRefStreamParser.d.ts.map +1 -1
  31. package/cjs/core/parser/PDFXRefStreamParser.js +6 -0
  32. package/cjs/core/parser/PDFXRefStreamParser.js.map +1 -1
  33. package/cjs/core/writers/PDFStreamWriter.d.ts +7 -7
  34. package/cjs/core/writers/PDFStreamWriter.d.ts.map +1 -1
  35. package/cjs/core/writers/PDFStreamWriter.js +16 -16
  36. package/cjs/core/writers/PDFStreamWriter.js.map +1 -1
  37. package/cjs/core/writers/PDFWriter.d.ts +10 -10
  38. package/cjs/core/writers/PDFWriter.d.ts.map +1 -1
  39. package/cjs/core/writers/PDFWriter.js +20 -10
  40. package/cjs/core/writers/PDFWriter.js.map +1 -1
  41. package/dist/pdf-lib.esm.js +21436 -6660
  42. package/dist/pdf-lib.esm.js.map +1 -1
  43. package/dist/pdf-lib.esm.min.js +3 -3
  44. package/dist/pdf-lib.esm.min.js.map +1 -1
  45. package/dist/pdf-lib.js +21372 -6514
  46. package/dist/pdf-lib.js.map +1 -1
  47. package/dist/pdf-lib.min.js +3 -3
  48. package/dist/pdf-lib.min.js.map +1 -1
  49. package/es/api/PDFDocument.d.ts +6 -6
  50. package/es/api/PDFDocument.d.ts.map +1 -1
  51. package/es/api/PDFDocument.js +8 -6
  52. package/es/api/PDFDocument.js.map +1 -1
  53. package/es/api/index.d.ts +21 -21
  54. package/es/api/index.d.ts.map +1 -1
  55. package/es/api/index.js +20 -20
  56. package/es/api/index.js.map +1 -1
  57. package/es/api/snapshot/DefaultDocumentSnapshot.d.ts +6 -2
  58. package/es/api/snapshot/DefaultDocumentSnapshot.d.ts.map +1 -1
  59. package/es/api/snapshot/DefaultDocumentSnapshot.js +10 -0
  60. package/es/api/snapshot/DefaultDocumentSnapshot.js.map +1 -1
  61. package/es/api/snapshot/DocumentSnapshot.d.ts +5 -1
  62. package/es/api/snapshot/DocumentSnapshot.d.ts.map +1 -1
  63. package/es/api/snapshot/IncrementalDocumentSnapshot.d.ts +7 -2
  64. package/es/api/snapshot/IncrementalDocumentSnapshot.d.ts.map +1 -1
  65. package/es/api/snapshot/IncrementalDocumentSnapshot.js +17 -0
  66. package/es/api/snapshot/IncrementalDocumentSnapshot.js.map +1 -1
  67. package/es/core/PDFContext.d.ts +2 -1
  68. package/es/core/PDFContext.d.ts.map +1 -1
  69. package/es/core/PDFContext.js +2 -0
  70. package/es/core/PDFContext.js.map +1 -1
  71. package/es/core/document/PDFCrossRefSection.d.ts +1 -1
  72. package/es/core/document/PDFCrossRefSection.d.ts.map +1 -1
  73. package/es/core/document/PDFCrossRefSection.js +49 -2
  74. package/es/core/document/PDFCrossRefSection.js.map +1 -1
  75. package/es/core/parser/PDFParser.d.ts.map +1 -1
  76. package/es/core/parser/PDFParser.js +6 -0
  77. package/es/core/parser/PDFParser.js.map +1 -1
  78. package/es/core/parser/PDFXRefStreamParser.d.ts.map +1 -1
  79. package/es/core/parser/PDFXRefStreamParser.js +6 -0
  80. package/es/core/parser/PDFXRefStreamParser.js.map +1 -1
  81. package/es/core/writers/PDFStreamWriter.d.ts +7 -7
  82. package/es/core/writers/PDFStreamWriter.d.ts.map +1 -1
  83. package/es/core/writers/PDFStreamWriter.js +16 -16
  84. package/es/core/writers/PDFStreamWriter.js.map +1 -1
  85. package/es/core/writers/PDFWriter.d.ts +10 -10
  86. package/es/core/writers/PDFWriter.d.ts.map +1 -1
  87. package/es/core/writers/PDFWriter.js +20 -10
  88. package/es/core/writers/PDFWriter.js.map +1 -1
  89. package/package.json +4 -4
  90. package/src/api/PDFDocument.ts +14 -11
  91. package/src/api/index.ts +21 -21
  92. package/src/api/snapshot/DefaultDocumentSnapshot.ts +15 -2
  93. package/src/api/snapshot/DocumentSnapshot.ts +7 -1
  94. package/src/api/snapshot/IncrementalDocumentSnapshot.ts +22 -2
  95. package/src/core/PDFContext.ts +3 -1
  96. package/src/core/document/PDFCrossRefSection.ts +46 -2
  97. package/src/core/parser/PDFParser.ts +7 -0
  98. package/src/core/parser/PDFXRefStreamParser.ts +8 -0
  99. package/src/core/writers/PDFStreamWriter.ts +19 -18
  100. package/src/core/writers/PDFWriter.ts +27 -16
  101. package/ts3.4/cjs/api/PDFDocument.d.ts +5 -5
  102. package/ts3.4/cjs/api/index.d.ts +21 -21
  103. package/ts3.4/cjs/api/snapshot/DefaultDocumentSnapshot.d.ts +5 -1
  104. package/ts3.4/cjs/api/snapshot/DocumentSnapshot.d.ts +5 -1
  105. package/ts3.4/cjs/api/snapshot/IncrementalDocumentSnapshot.d.ts +6 -1
  106. package/ts3.4/cjs/core/PDFContext.d.ts +2 -1
  107. package/ts3.4/cjs/core/document/PDFCrossRefSection.d.ts +1 -1
  108. package/ts3.4/cjs/core/writers/PDFStreamWriter.d.ts +7 -7
  109. package/ts3.4/cjs/core/writers/PDFWriter.d.ts +10 -10
  110. package/ts3.4/es/api/PDFDocument.d.ts +5 -5
  111. package/ts3.4/es/api/index.d.ts +21 -21
  112. package/ts3.4/es/api/snapshot/DefaultDocumentSnapshot.d.ts +5 -1
  113. package/ts3.4/es/api/snapshot/DocumentSnapshot.d.ts +5 -1
  114. package/ts3.4/es/api/snapshot/IncrementalDocumentSnapshot.d.ts +6 -1
  115. package/ts3.4/es/core/PDFContext.d.ts +2 -1
  116. package/ts3.4/es/core/document/PDFCrossRefSection.d.ts +1 -1
  117. package/ts3.4/es/core/writers/PDFStreamWriter.d.ts +7 -7
  118. package/ts3.4/es/core/writers/PDFWriter.d.ts +10 -10
@@ -1,9 +1,10 @@
1
- import type { PDFObject, PDFRef } from 'src/core';
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 'src/core';
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 'src/core';
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
  }
@@ -1,5 +1,5 @@
1
1
  import pako from 'pako';
2
- import { DocumentSnapshot } from 'src/api';
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 **in order of ascending object number**.
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 > 1) {
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, DocumentSnapshot } from 'src/api/snapshot';
2
- import PDFHeader from 'src/core/document/PDFHeader';
3
- import PDFTrailer from 'src/core/document/PDFTrailer';
4
- import PDFInvalidObject from 'src/core/objects/PDFInvalidObject';
5
- import PDFName from 'src/core/objects/PDFName';
6
- import PDFNumber from 'src/core/objects/PDFNumber';
7
- import PDFObject from 'src/core/objects/PDFObject';
8
- import PDFRef from 'src/core/objects/PDFRef';
9
- import PDFStream from 'src/core/objects/PDFStream';
10
- import PDFContext from 'src/core/PDFContext';
11
- import PDFCrossRefStream from 'src/core/structures/PDFCrossRefStream';
12
- import PDFObjectStream from 'src/core/structures/PDFObjectStream';
13
- import PDFWriter from 'src/core/writers/PDFWriter';
14
- import { last, waitForTick } from 'src/utils';
15
- import PDFDict from 'src/core/objects/PDFDict';
16
- import PDFCatalog from 'src/core/structures/PDFCatalog';
17
- import PDFPageTree from 'src/core/structures/PDFPageTree';
18
- import PDFPageLeaf from 'src/core/structures/PDFPageLeaf';
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 'src/api/snapshot';
5
- import type { DocumentSnapshot } from 'src/api/snapshot';
6
- import PDFCrossRefSection from 'src/core/document/PDFCrossRefSection';
7
- import PDFHeader from 'src/core/document/PDFHeader';
8
- import PDFTrailer from 'src/core/document/PDFTrailer';
9
- import PDFTrailerDict from 'src/core/document/PDFTrailerDict';
10
- import PDFDict from 'src/core/objects/PDFDict';
11
- import PDFObject from 'src/core/objects/PDFObject';
12
- import PDFRef from 'src/core/objects/PDFRef';
13
- import PDFContext from 'src/core/PDFContext';
14
- import PDFObjectStream from 'src/core/structures/PDFObjectStream';
15
- import CharCodes from 'src/core/syntax/CharCodes';
16
- import { copyStringIntoBuffer, waitForTick } from 'src/utils';
17
- import PDFNumber from 'src/core/objects/PDFNumber';
18
- import PDFSecurity from 'src/core/security/PDFSecurity';
19
- import PDFStream from 'src/core/objects/PDFStream';
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 'src/api/PDFDocumentOptions';
9
- import PDFRef from 'src/core/objects/PDFRef';
10
- import { Fontkit } from 'src/types/fontkit';
11
- import { TransformationMatrix } from 'src/types/matrix';
12
- import { AFRelationship } from 'src/core/embedders/FileEmbedder';
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';
@@ -1,23 +1,23 @@
1
- export * from 'src/api/form';
2
- export * from 'src/api/text';
3
- export * from 'src/api/colors';
4
- export * from 'src/api/errors';
5
- export * from 'src/api/image';
6
- export * from 'src/api/objects';
7
- export * from 'src/api/operations';
8
- export * from 'src/api/operators';
9
- export * from 'src/api/rotations';
10
- export * from 'src/api/sizes';
11
- export * from 'src/api/snapshot';
12
- export * from 'src/api/PDFPageOptions';
13
- export * from 'src/api/PDFDocumentOptions';
14
- export * from 'src/api/StandardFonts';
15
- export { default as PDFDocument } from 'src/api/PDFDocument';
16
- export { default as PDFFont } from 'src/api/PDFFont';
17
- export { default as PDFImage } from 'src/api/PDFImage';
18
- export { default as PDFPage } from 'src/api/PDFPage';
19
- export { default as PDFEmbeddedPage } from 'src/api/PDFEmbeddedPage';
20
- export { default as PDFJavaScript } from 'src/api/PDFJavaScript';
21
- export { default as Embeddable } from 'src/api/Embeddable';
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 'src/core';
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 'src/core';
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 'src/core';
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 'src/api';
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;
@@ -6,7 +6,7 @@ export interface Entry {
6
6
  }
7
7
  /**
8
8
  * Entries should be added using the [[addEntry]] and [[addDeletedEntry]]
9
- * methods **in order of ascending object number**.
9
+ * methods.
10
10
  */
11
11
  declare class PDFCrossRefSection {
12
12
  static create: () => PDFCrossRefSection;
@@ -1,10 +1,10 @@
1
- import { DocumentSnapshot } from 'src/api/snapshot';
2
- import PDFHeader from 'src/core/document/PDFHeader';
3
- import PDFTrailer from 'src/core/document/PDFTrailer';
4
- import PDFObject from 'src/core/objects/PDFObject';
5
- import PDFRef from 'src/core/objects/PDFRef';
6
- import PDFContext from 'src/core/PDFContext';
7
- import PDFWriter from 'src/core/writers/PDFWriter';
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 'src/api/snapshot';
2
- import PDFCrossRefSection from 'src/core/document/PDFCrossRefSection';
3
- import PDFHeader from 'src/core/document/PDFHeader';
4
- import PDFTrailer from 'src/core/document/PDFTrailer';
5
- import PDFTrailerDict from 'src/core/document/PDFTrailerDict';
6
- import PDFDict from 'src/core/objects/PDFDict';
7
- import PDFObject from 'src/core/objects/PDFObject';
8
- import PDFRef from 'src/core/objects/PDFRef';
9
- import PDFContext from 'src/core/PDFContext';
10
- import PDFSecurity from 'src/core/security/PDFSecurity';
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 'src/api/PDFDocumentOptions';
9
- import PDFRef from 'src/core/objects/PDFRef';
10
- import { Fontkit } from 'src/types/fontkit';
11
- import { TransformationMatrix } from 'src/types/matrix';
12
- import { AFRelationship } from 'src/core/embedders/FileEmbedder';
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';
@@ -1,23 +1,23 @@
1
- export * from 'src/api/form';
2
- export * from 'src/api/text';
3
- export * from 'src/api/colors';
4
- export * from 'src/api/errors';
5
- export * from 'src/api/image';
6
- export * from 'src/api/objects';
7
- export * from 'src/api/operations';
8
- export * from 'src/api/operators';
9
- export * from 'src/api/rotations';
10
- export * from 'src/api/sizes';
11
- export * from 'src/api/snapshot';
12
- export * from 'src/api/PDFPageOptions';
13
- export * from 'src/api/PDFDocumentOptions';
14
- export * from 'src/api/StandardFonts';
15
- export { default as PDFDocument } from 'src/api/PDFDocument';
16
- export { default as PDFFont } from 'src/api/PDFFont';
17
- export { default as PDFImage } from 'src/api/PDFImage';
18
- export { default as PDFPage } from 'src/api/PDFPage';
19
- export { default as PDFEmbeddedPage } from 'src/api/PDFEmbeddedPage';
20
- export { default as PDFJavaScript } from 'src/api/PDFJavaScript';
21
- export { default as Embeddable } from 'src/api/Embeddable';
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 'src/core';
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 'src/core';
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