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.
Files changed (93) hide show
  1. package/EXAMPLES.md +51 -70
  2. package/README.md +1 -1
  3. package/dist/acroform/appearance/pdf-button-appearance-stream.d.ts +1 -1
  4. package/dist/acroform/appearance/pdf-button-appearance-stream.js +6 -2
  5. package/dist/acroform/fields/pdf-button-form-field.d.ts +0 -9
  6. package/dist/acroform/fields/pdf-button-form-field.js +7 -39
  7. package/dist/acroform/fields/pdf-choice-form-field.d.ts +2 -1
  8. package/dist/acroform/fields/pdf-choice-form-field.js +19 -38
  9. package/dist/acroform/fields/pdf-default-appearance.js +1 -1
  10. package/dist/acroform/fields/pdf-form-field.d.ts +27 -32
  11. package/dist/acroform/fields/pdf-form-field.js +180 -94
  12. package/dist/acroform/fields/pdf-text-form-field.js +6 -33
  13. package/dist/acroform/fields/types.d.ts +1 -1
  14. package/dist/acroform/index.d.ts +0 -2
  15. package/dist/acroform/index.js +0 -2
  16. package/dist/acroform/pdf-acro-form.d.ts +12 -36
  17. package/dist/acroform/pdf-acro-form.js +111 -201
  18. package/dist/acroform/xfa/pdf-xfa-data.d.ts +4 -3
  19. package/dist/acroform/xfa/pdf-xfa-data.js +16 -12
  20. package/dist/acroform/xfa/pdf-xfa-form.d.ts +9 -4
  21. package/dist/acroform/xfa/pdf-xfa-form.js +17 -39
  22. package/dist/annotations/index.d.ts +0 -1
  23. package/dist/annotations/index.js +0 -1
  24. package/dist/annotations/pdf-annotation.d.ts +7 -2
  25. package/dist/annotations/pdf-annotation.js +30 -19
  26. package/dist/annotations/pdf-default-resources.d.ts +11 -0
  27. package/dist/annotations/pdf-default-resources.js +3 -0
  28. package/dist/core/decoder.js +1 -1
  29. package/dist/core/objects/pdf-array.d.ts +8 -1
  30. package/dist/core/objects/pdf-array.js +31 -0
  31. package/dist/core/objects/pdf-dictionary.d.ts +2 -0
  32. package/dist/core/objects/pdf-dictionary.js +14 -7
  33. package/dist/core/objects/pdf-hexadecimal.d.ts +1 -0
  34. package/dist/core/objects/pdf-hexadecimal.js +3 -3
  35. package/dist/core/objects/pdf-indirect-object.d.ts +18 -9
  36. package/dist/core/objects/pdf-indirect-object.js +75 -16
  37. package/dist/core/objects/pdf-number.d.ts +1 -0
  38. package/dist/core/objects/pdf-number.js +5 -4
  39. package/dist/core/objects/pdf-object-reference.d.ts +8 -1
  40. package/dist/core/objects/pdf-object-reference.js +14 -0
  41. package/dist/core/objects/pdf-object.d.ts +14 -0
  42. package/dist/core/objects/pdf-object.js +36 -0
  43. package/dist/core/objects/pdf-start-xref.d.ts +1 -0
  44. package/dist/core/objects/pdf-start-xref.js +4 -0
  45. package/dist/core/objects/pdf-stream.d.ts +47 -7
  46. package/dist/core/objects/pdf-stream.js +301 -32
  47. package/dist/core/objects/pdf-string.d.ts +1 -0
  48. package/dist/core/objects/pdf-string.js +3 -6
  49. package/dist/core/objects/pdf-trailer.d.ts +1 -0
  50. package/dist/core/objects/pdf-trailer.js +6 -3
  51. package/dist/core/objects/pdf-xref-table.js +1 -1
  52. package/dist/core/ref.d.ts +3 -1
  53. package/dist/core/ref.js +8 -5
  54. package/dist/core/tokens/token.d.ts +2 -1
  55. package/dist/core/tokens/token.js +3 -0
  56. package/dist/fonts/index.d.ts +0 -1
  57. package/dist/fonts/index.js +0 -1
  58. package/dist/fonts/pdf-font.d.ts +32 -27
  59. package/dist/fonts/pdf-font.js +115 -77
  60. package/dist/pdf/index.d.ts +2 -0
  61. package/dist/pdf/index.js +2 -0
  62. package/dist/pdf/pdf-document.d.ts +63 -37
  63. package/dist/pdf/pdf-document.js +351 -135
  64. package/dist/pdf/pdf-page.d.ts +50 -0
  65. package/dist/pdf/pdf-page.js +144 -0
  66. package/dist/pdf/pdf-pages.d.ts +28 -0
  67. package/dist/pdf/pdf-pages.js +94 -0
  68. package/dist/pdf/pdf-reader.d.ts +5 -1
  69. package/dist/pdf/pdf-reader.js +36 -2
  70. package/dist/pdf/pdf-revision.d.ts +3 -3
  71. package/dist/pdf/pdf-revision.js +7 -7
  72. package/dist/pdf/pdf-xref-lookup.js +34 -14
  73. package/dist/signing/document-security-store.d.ts +14 -17
  74. package/dist/signing/document-security-store.js +19 -34
  75. package/dist/signing/signer.d.ts +23 -8
  76. package/dist/signing/signer.js +51 -17
  77. package/dist/utils/index.d.ts +0 -1
  78. package/dist/utils/index.js +0 -1
  79. package/dist/utils/needsCentralWhitespace.d.ts +10 -0
  80. package/dist/utils/needsCentralWhitespace.js +34 -0
  81. package/package.json +3 -3
  82. package/dist/acroform/acroform.d.ts +0 -9
  83. package/dist/acroform/acroform.js +0 -7
  84. package/dist/acroform/manager.d.ts +0 -37
  85. package/dist/acroform/manager.js +0 -57
  86. package/dist/acroform/pdf-font-encoding-cache.d.ts +0 -27
  87. package/dist/acroform/pdf-font-encoding-cache.js +0 -188
  88. package/dist/annotations/pdf-annotation-writer.d.ts +0 -20
  89. package/dist/annotations/pdf-annotation-writer.js +0 -76
  90. package/dist/fonts/manager.d.ts +0 -127
  91. package/dist/fonts/manager.js +0 -378
  92. package/dist/utils/predictors.d.ts +0 -113
  93. package/dist/utils/predictors.js +0 -279
@@ -4,16 +4,15 @@ import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
4
4
  import { PdfComment } from '../core/objects/pdf-comment.js';
5
5
  import { PdfToken } from '../core/tokens/token.js';
6
6
  import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
7
- import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
7
+ import { IPdfObjectResolver, PdfObjectReference } from '../core/objects/pdf-object-reference.js';
8
8
  import { PdfXrefLookup } from './pdf-xref-lookup.js';
9
9
  import { PdfRevision } from './pdf-revision.js';
10
10
  import { PdfEncryptionDictionaryObject } from '../security/types.js';
11
11
  import { PdfTrailerEntries } from '../core/objects/pdf-trailer.js';
12
- import { PdfDocumentSecurityStoreObject } from '../signing/document-security-store.js';
13
12
  import { ByteArray } from '../types.js';
14
13
  import { PdfDocumentVerificationResult, PdfSigner } from '../signing/signer.js';
15
- import { PdfAcroFormManager } from '../acroform/manager.js';
16
- import { PdfFontManager } from '../fonts/manager.js';
14
+ import { PdfAcroForm } from '../acroform/pdf-acro-form.js';
15
+ import { PdfPages } from './pdf-pages.js';
17
16
  /**
18
17
  * Represents a PDF document with support for reading, writing, and modifying PDF files.
19
18
  * Handles document structure, revisions, encryption, and digital signatures.
@@ -31,18 +30,23 @@ import { PdfFontManager } from '../fonts/manager.js';
31
30
  * await document.commit()
32
31
  * ```
33
32
  */
34
- export declare class PdfDocument extends PdfObject {
33
+ export declare class PdfDocument extends PdfObject implements IPdfObjectResolver {
35
34
  /** List of document revisions for incremental updates */
36
35
  revisions: PdfRevision[];
37
36
  /** Signer instance for digital signature operations */
38
37
  signer: PdfSigner;
39
38
  /** Security handler for encryption/decryption operations */
40
39
  securityHandler?: PdfSecurityHandler;
41
- /** */
42
- readonly acroForm: PdfAcroFormManager;
43
- readonly fonts: PdfFontManager;
40
+ /** Whether the document is currently in incremental mode (appending changes as a new revision) */
41
+ private incremental;
42
+ private originalSecurityHandler?;
44
43
  private hasEncryptionDictionary?;
45
- private toBeCommitted;
44
+ private _resolvedCache;
45
+ private _objStreamCache;
46
+ private _committing;
47
+ private _updating;
48
+ private _finalized;
49
+ private _signed;
46
50
  /**
47
51
  * Creates a new PDF document instance.
48
52
  *
@@ -62,6 +66,9 @@ export declare class PdfDocument extends PdfObject {
62
66
  securityHandler?: PdfSecurityHandler;
63
67
  signer?: PdfSigner;
64
68
  });
69
+ resolve(objectNumber: number, generationNumber: number): PdfIndirectObject;
70
+ get acroform(): PdfAcroForm | null;
71
+ get pages(): PdfPages;
65
72
  get header(): PdfComment | undefined;
66
73
  set header(comment: PdfComment | undefined);
67
74
  /**
@@ -79,6 +86,7 @@ export declare class PdfDocument extends PdfObject {
79
86
  * @returns The document instance for method chaining
80
87
  */
81
88
  startNewRevision(): PdfDocument;
89
+ hasObjectInLatestRevision(obj: PdfObject): boolean;
82
90
  /**
83
91
  * Adds objects to the document's latest revision.
84
92
  * Automatically starts a new revision if the current one is locked.
@@ -142,6 +150,7 @@ export declare class PdfDocument extends PdfObject {
142
150
  * @returns The metadata stream reference or undefined if not present
143
151
  */
144
152
  get metadataStreamReference(): PdfObjectReference | undefined;
153
+ resetSecurityHandler(): void;
145
154
  private getSecurityHandler;
146
155
  private initSecurityHandler;
147
156
  /**
@@ -166,14 +175,28 @@ export declare class PdfDocument extends PdfObject {
166
175
  */
167
176
  hasObject(obj: PdfObject): boolean;
168
177
  private isObjectEncryptable;
178
+ commitIncrementalUpdates(): void;
179
+ /**
180
+ * Decrypts all encrypted object data in-place without removing
181
+ * the encryption infrastructure. Useful in incremental mode where
182
+ * the original (encrypted) bytes are preserved via cached tokens
183
+ * but the live object data needs to be readable.
184
+ */
185
+ decryptObjects(): Promise<void>;
186
+ /**
187
+ * Re-encrypts all objects and updates the document structure.
188
+ * No-op if the document has no security handler (unencrypted document).
189
+ */
190
+ finalize(): Promise<void>;
169
191
  /**
170
192
  * Decrypts all encrypted objects in the document.
171
193
  * Removes the security handler and encryption dictionary after decryption.
172
194
  */
173
195
  decrypt(): Promise<void>;
174
196
  /**
175
- * Encrypts all objects in the document using the security handler.
176
- * Creates and adds an encryption dictionary to all revisions.
197
+ * Encrypts all encryptable objects using the security handler.
198
+ * Re-uses the existing encryption dictionary or creates one if needed,
199
+ * propagating it to all revisions.
177
200
  */
178
201
  encrypt(): Promise<void>;
179
202
  /**
@@ -186,7 +209,7 @@ export declare class PdfDocument extends PdfObject {
186
209
  findCompressedObject(options: {
187
210
  objectNumber: number;
188
211
  generationNumber?: number;
189
- } | PdfObjectReference): Promise<PdfIndirectObject | undefined>;
212
+ } | PdfObjectReference): PdfIndirectObject | undefined;
190
213
  /**
191
214
  * Finds an uncompressed indirect object by its object number.
192
215
  *
@@ -212,13 +235,21 @@ export declare class PdfDocument extends PdfObject {
212
235
  objectNumber: number;
213
236
  generationNumber?: number;
214
237
  allowUnindexed?: boolean;
215
- }): Promise<PdfIndirectObject | undefined>;
238
+ cloned?: boolean;
239
+ }): PdfIndirectObject | undefined;
240
+ /**
241
+ * Finds the revision that contains a given PDF object.
242
+ * Useful for determining the origin of an object across multiple revisions.
243
+ * @param obj - The PDF object to find the revision for
244
+ * @returns The PdfRevision that contains the object, or undefined if not found in any revision
245
+ */
246
+ findRevisionForObject(obj: PdfObject): PdfRevision | undefined;
216
247
  /**
217
248
  * Deletes an object from all revisions in the document.
218
249
  *
219
250
  * @param obj - The PDF object to delete
220
251
  */
221
- deleteObject(obj: PdfObject | undefined): Promise<void>;
252
+ deleteObject(obj: PdfObject | undefined): void;
222
253
  /**
223
254
  * Sets the PDF version for the document.
224
255
  *
@@ -239,22 +270,6 @@ export declare class PdfDocument extends PdfObject {
239
270
  * @returns True if all revisions are locked for incremental updates
240
271
  */
241
272
  isIncremental(): boolean;
242
- /**
243
- * Commits pending objects to the document.
244
- * Adds objects, applies encryption if configured, and updates the document structure.
245
- *
246
- * @param newObjects - Additional objects to add before committing
247
- */
248
- commit(...newObjects: PdfObject[]): Promise<void>;
249
- private ensureEncryptionDictionary;
250
- /**
251
- * Sets the Document Security Store (DSS) for the document.
252
- * Used for long-term validation of digital signatures.
253
- *
254
- * @param dss - The Document Security Store object to set
255
- * @throws Error if the document has no root dictionary
256
- */
257
- setDocumentSecurityStore(dss: PdfDocumentSecurityStoreObject): Promise<void>;
258
273
  /**
259
274
  * Returns tokens paired with their source objects.
260
275
  * Useful for debugging and analysis of document structure.
@@ -266,23 +281,30 @@ export declare class PdfDocument extends PdfObject {
266
281
  object: PdfObject | undefined;
267
282
  }[];
268
283
  protected tokenize(): PdfToken[];
284
+ private wireResolvers;
285
+ private collectMissingReferences;
269
286
  private linkRevisions;
270
287
  private linkOffsets;
271
288
  private calculateOffsets;
272
289
  private updateRevisions;
290
+ /**
291
+ * Performs a full update cycle to ensure all revisions are consistent and offsets are correct.
292
+ */
273
293
  private update;
294
+ /**
295
+ * Walks all objects in the document and registers any newly created
296
+ * PdfIndirectObjects that are referenced but not yet part of the document
297
+ * (e.g. appearance streams created by generateAppearance).
298
+ */
299
+ private registerNewReferences;
300
+ private flushResolvedCache;
301
+ sign(): Promise<void>;
274
302
  /**
275
303
  * Serializes the document to a byte array.
276
304
  *
277
305
  * @returns The PDF document as a Uint8Array
278
306
  */
279
307
  toBytes(): ByteArray;
280
- /**
281
- * Serializes the document to a Base64-encoded string.
282
- *
283
- * @returns A promise that resolves to the PDF document as a Base64 string
284
- */
285
- toBase64(): string;
286
308
  /**
287
309
  * Creates a deep copy of the document.
288
310
  *
@@ -295,7 +317,11 @@ export declare class PdfDocument extends PdfObject {
295
317
  * @param input - Async or sync iterable of byte arrays
296
318
  * @returns A promise that resolves to the parsed PdfDocument
297
319
  */
298
- static fromBytes(input: AsyncIterable<ByteArray> | Iterable<ByteArray>): Promise<PdfDocument>;
320
+ static fromBytes(input: AsyncIterable<ByteArray> | Iterable<ByteArray>, options?: {
321
+ password?: string;
322
+ ownerPassword?: string;
323
+ incremental?: boolean;
324
+ }): Promise<PdfDocument>;
299
325
  isModified(): boolean;
300
326
  /**
301
327
  * Verifies all digital signatures in the document.