pdf-lite 1.3.3 → 1.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 (124) hide show
  1. package/dist/acroform/acroform.d.ts +7 -454
  2. package/dist/acroform/acroform.js +5 -1664
  3. package/dist/acroform/appearance/index.d.ts +4 -0
  4. package/dist/acroform/appearance/index.js +4 -0
  5. package/dist/acroform/appearance/pdf-appearance-stream.d.ts +21 -0
  6. package/dist/acroform/appearance/pdf-appearance-stream.js +41 -0
  7. package/dist/acroform/appearance/pdf-button-appearance-stream.d.ts +13 -0
  8. package/dist/acroform/appearance/pdf-button-appearance-stream.js +54 -0
  9. package/dist/acroform/appearance/pdf-choice-appearance-stream.d.ts +22 -0
  10. package/dist/acroform/appearance/pdf-choice-appearance-stream.js +75 -0
  11. package/dist/acroform/appearance/pdf-graphics.d.ts +51 -0
  12. package/dist/acroform/appearance/pdf-graphics.js +239 -0
  13. package/dist/acroform/appearance/pdf-text-appearance-stream.d.ts +22 -0
  14. package/dist/acroform/appearance/pdf-text-appearance-stream.js +104 -0
  15. package/dist/acroform/fields/index.d.ts +8 -0
  16. package/dist/acroform/fields/index.js +8 -0
  17. package/dist/acroform/fields/pdf-button-form-field.d.ts +23 -0
  18. package/dist/acroform/fields/pdf-button-form-field.js +102 -0
  19. package/dist/acroform/fields/pdf-choice-form-field.d.ts +18 -0
  20. package/dist/acroform/fields/pdf-choice-form-field.js +131 -0
  21. package/dist/acroform/fields/pdf-default-appearance.d.ts +23 -0
  22. package/dist/acroform/fields/pdf-default-appearance.js +68 -0
  23. package/dist/acroform/fields/pdf-form-field-flags.d.ts +45 -0
  24. package/dist/acroform/fields/pdf-form-field-flags.js +122 -0
  25. package/dist/acroform/fields/pdf-form-field.d.ts +123 -0
  26. package/dist/acroform/fields/pdf-form-field.js +433 -0
  27. package/dist/acroform/fields/pdf-signature-form-field.d.ts +7 -0
  28. package/dist/acroform/fields/pdf-signature-form-field.js +12 -0
  29. package/dist/acroform/fields/pdf-text-form-field.d.ts +10 -0
  30. package/dist/acroform/fields/pdf-text-form-field.js +77 -0
  31. package/dist/acroform/fields/types.d.ts +26 -0
  32. package/dist/acroform/fields/types.js +9 -0
  33. package/dist/acroform/index.d.ts +5 -1
  34. package/dist/acroform/index.js +5 -1
  35. package/dist/acroform/manager.d.ts +12 -1
  36. package/dist/acroform/manager.js +20 -2
  37. package/dist/acroform/pdf-acro-form.d.ts +69 -0
  38. package/dist/acroform/pdf-acro-form.js +293 -0
  39. package/dist/acroform/pdf-font-encoding-cache.d.ts +27 -0
  40. package/dist/acroform/pdf-font-encoding-cache.js +188 -0
  41. package/dist/acroform/xfa/index.d.ts +3 -0
  42. package/dist/acroform/xfa/index.js +2 -0
  43. package/dist/acroform/xfa/pdf-xfa-data.d.ts +20 -0
  44. package/dist/acroform/xfa/pdf-xfa-data.js +68 -0
  45. package/dist/acroform/xfa/pdf-xfa-form.d.ts +11 -0
  46. package/dist/acroform/xfa/pdf-xfa-form.js +56 -0
  47. package/dist/annotations/index.d.ts +4 -0
  48. package/dist/annotations/index.js +4 -0
  49. package/dist/annotations/pdf-annotation-flags.d.ts +24 -0
  50. package/dist/annotations/pdf-annotation-flags.js +93 -0
  51. package/dist/annotations/pdf-annotation-writer.d.ts +20 -0
  52. package/dist/annotations/pdf-annotation-writer.js +76 -0
  53. package/dist/annotations/pdf-annotation.d.ts +61 -0
  54. package/dist/annotations/pdf-annotation.js +106 -0
  55. package/dist/annotations/pdf-widget-annotation.d.ts +15 -0
  56. package/dist/annotations/pdf-widget-annotation.js +37 -0
  57. package/dist/core/objects/pdf-array.d.ts +1 -1
  58. package/dist/core/objects/pdf-array.js +3 -2
  59. package/dist/core/objects/pdf-boolean.d.ts +1 -1
  60. package/dist/core/objects/pdf-boolean.js +3 -2
  61. package/dist/core/objects/pdf-comment.d.ts +1 -1
  62. package/dist/core/objects/pdf-comment.js +1 -1
  63. package/dist/core/objects/pdf-dictionary.d.ts +1 -1
  64. package/dist/core/objects/pdf-dictionary.js +3 -2
  65. package/dist/core/objects/pdf-hexadecimal.d.ts +1 -1
  66. package/dist/core/objects/pdf-hexadecimal.js +3 -2
  67. package/dist/core/objects/pdf-indirect-object.d.ts +1 -1
  68. package/dist/core/objects/pdf-indirect-object.js +1 -1
  69. package/dist/core/objects/pdf-name.d.ts +1 -1
  70. package/dist/core/objects/pdf-name.js +3 -2
  71. package/dist/core/objects/pdf-null.d.ts +1 -1
  72. package/dist/core/objects/pdf-null.js +3 -2
  73. package/dist/core/objects/pdf-number.d.ts +1 -1
  74. package/dist/core/objects/pdf-number.js +3 -2
  75. package/dist/core/objects/pdf-object-reference.d.ts +1 -1
  76. package/dist/core/objects/pdf-object-reference.js +3 -2
  77. package/dist/core/objects/pdf-object.d.ts +3 -1
  78. package/dist/core/objects/pdf-object.js +6 -0
  79. package/dist/core/objects/pdf-start-xref.d.ts +1 -1
  80. package/dist/core/objects/pdf-start-xref.js +3 -2
  81. package/dist/core/objects/pdf-stream.d.ts +4 -3
  82. package/dist/core/objects/pdf-stream.js +45 -16
  83. package/dist/core/objects/pdf-string.d.ts +2 -1
  84. package/dist/core/objects/pdf-string.js +17 -2
  85. package/dist/core/objects/pdf-trailer.d.ts +1 -1
  86. package/dist/core/objects/pdf-trailer.js +3 -2
  87. package/dist/core/objects/pdf-xref-table.d.ts +3 -3
  88. package/dist/core/objects/pdf-xref-table.js +3 -3
  89. package/dist/core/parser/incremental-parser.d.ts +0 -13
  90. package/dist/core/parser/incremental-parser.js +1 -18
  91. package/dist/core/streams/object-stream.d.ts +1 -1
  92. package/dist/core/streams/object-stream.js +1 -1
  93. package/dist/errors.d.ts +22 -0
  94. package/dist/errors.js +24 -0
  95. package/dist/fonts/index.d.ts +1 -1
  96. package/dist/fonts/index.js +1 -1
  97. package/dist/fonts/pdf-font.d.ts +64 -7
  98. package/dist/fonts/pdf-font.js +188 -8
  99. package/dist/index.d.ts +2 -0
  100. package/dist/index.js +2 -0
  101. package/dist/pdf/index.d.ts +0 -1
  102. package/dist/pdf/index.js +0 -1
  103. package/dist/pdf/pdf-document.d.ts +16 -12
  104. package/dist/pdf/pdf-document.js +51 -37
  105. package/dist/pdf/pdf-revision.d.ts +1 -1
  106. package/dist/pdf/pdf-revision.js +1 -1
  107. package/dist/pdf/pdf-xref-lookup.d.ts +8 -0
  108. package/dist/pdf/pdf-xref-lookup.js +12 -0
  109. package/dist/security/handlers/base.js +3 -0
  110. package/dist/utils/encodePdfText.d.ts +17 -0
  111. package/dist/utils/encodePdfText.js +61 -0
  112. package/dist/utils/index.d.ts +1 -1
  113. package/dist/utils/index.js +1 -1
  114. package/package.json +1 -1
  115. package/dist/pdf/errors.d.ts +0 -6
  116. package/dist/pdf/errors.js +0 -6
  117. package/dist/xfa/index.d.ts +0 -1
  118. package/dist/xfa/index.js +0 -1
  119. package/dist/xfa/manager.d.ts +0 -44
  120. package/dist/xfa/manager.js +0 -136
  121. /package/dist/fonts/{font-manager.d.ts → manager.d.ts} +0 -0
  122. /package/dist/fonts/{font-manager.js → manager.js} +0 -0
  123. /package/dist/utils/{IterableReadableStream.d.ts → iterable-readable-stream.d.ts} +0 -0
  124. /package/dist/utils/{IterableReadableStream.js → iterable-readable-stream.js} +0 -0
@@ -3,5 +3,5 @@ import { PdfNullToken } from '../tokens/null-token.js';
3
3
  export declare class PdfNull extends PdfObject {
4
4
  static readonly NULL: PdfNull;
5
5
  protected tokenize(): PdfNullToken[];
6
- clone(): this;
6
+ cloneImpl(): this;
7
7
  }
@@ -5,7 +5,8 @@ export class PdfNull extends PdfObject {
5
5
  tokenize() {
6
6
  return [new PdfNullToken()];
7
7
  }
8
- clone() {
9
- return new PdfNull();
8
+ cloneImpl() {
9
+ const cloned = new PdfNull();
10
+ return cloned;
10
11
  }
11
12
  }
@@ -17,7 +17,7 @@ export declare class PdfNumber extends PdfObject {
17
17
  onChange(callback: (value: number) => void): void;
18
18
  toToken(): PdfNumberToken;
19
19
  protected tokenize(): PdfNumberToken[];
20
- clone(): this;
20
+ cloneImpl(): this;
21
21
  isModified(): boolean;
22
22
  }
23
23
  export declare class PdfByteOffsetNumber extends PdfNumber {
@@ -64,12 +64,13 @@ export class PdfNumber extends PdfObject {
64
64
  tokenize() {
65
65
  return [this.toToken()];
66
66
  }
67
- clone() {
68
- return new PdfNumber({
67
+ cloneImpl() {
68
+ const cloned = new PdfNumber({
69
69
  value: this.value,
70
70
  padTo: this.padTo,
71
71
  decimalPlaces: this.decimalPlaces,
72
72
  });
73
+ return cloned;
73
74
  }
74
75
  isModified() {
75
76
  return super.isModified() || this.#value.isModified;
@@ -5,5 +5,5 @@ export declare class PdfObjectReference extends PdfObject {
5
5
  generationNumber: number;
6
6
  constructor(objectNumber: number, generationNumber: number);
7
7
  protected tokenize(): PdfToken[];
8
- clone(): this;
8
+ cloneImpl(): this;
9
9
  }
@@ -13,7 +13,8 @@ export class PdfObjectReference extends PdfObject {
13
13
  new PdfObjectReferenceToken(this.objectNumber, this.generationNumber),
14
14
  ];
15
15
  }
16
- clone() {
17
- return new PdfObjectReference(this.objectNumber, this.generationNumber);
16
+ cloneImpl() {
17
+ const cloned = new PdfObjectReference(this.objectNumber, this.generationNumber);
18
+ return cloned;
18
19
  }
19
20
  }
@@ -29,8 +29,10 @@ export declare abstract class PdfObject {
29
29
  toString(): string;
30
30
  /** Attempts to cast the object to a specific PdfObject subclass */
31
31
  as<T extends PdfObject>(ctor: new (...args: any[]) => T): T;
32
+ /** Creates a deep clone of the object. Override this method in subclasses to ensure all properties are cloned correctly */
33
+ protected abstract cloneImpl(): this;
32
34
  /** Creates a deep clone of the object */
33
- abstract clone(): this;
35
+ clone(): this;
34
36
  /** Compares this object to another for equality based on their token representations */
35
37
  equals(other?: PdfObject): boolean;
36
38
  }
@@ -63,6 +63,12 @@ export class PdfObject {
63
63
  }
64
64
  throw new Error(`Cannot cast object of type ${this.objectType} to ${ctor.name}`);
65
65
  }
66
+ /** Creates a deep clone of the object */
67
+ clone() {
68
+ const cloned = this.cloneImpl();
69
+ cloned.setModified(this.modified);
70
+ return cloned;
71
+ }
66
72
  /** Compares this object to another for equality based on their token representations */
67
73
  equals(other) {
68
74
  if (!other) {
@@ -5,6 +5,6 @@ export declare class PdfStartXRef extends PdfObject {
5
5
  offset: PdfNumber;
6
6
  constructor(offset?: number | PdfNumber | Ref<number>);
7
7
  protected tokenize(): import("../index.js").PdfToken[];
8
- clone(): this;
8
+ cloneImpl(): this;
9
9
  isModified(): boolean;
10
10
  }
@@ -23,8 +23,9 @@ export class PdfStartXRef extends PdfObject {
23
23
  ...this.offset.toTokens(),
24
24
  ];
25
25
  }
26
- clone() {
27
- return new PdfStartXRef(this.offset.clone());
26
+ cloneImpl() {
27
+ const cloned = new PdfStartXRef(this.offset.clone());
28
+ return cloned;
28
29
  }
29
30
  isModified() {
30
31
  return super.isModified() || this.offset.isModified();
@@ -20,6 +20,7 @@ export declare class PdfStream<T extends PdfDictionary = PdfDictionary> extends
20
20
  set raw(data: ByteArray);
21
21
  get originalAsString(): string;
22
22
  get rawAsString(): string;
23
+ set rawAsString(str: string);
23
24
  getFilters(): PdfStreamFilterType[];
24
25
  addFilter(filterName: PdfStreamFilterType): this;
25
26
  setPredictor(predictorParams: {
@@ -53,7 +54,7 @@ export declare class PdfStream<T extends PdfDictionary = PdfDictionary> extends
53
54
  readonly Crypt: PdfFilter;
54
55
  };
55
56
  static applyFilters(data: ByteArray, filters: PdfStreamFilterType[]): ByteArray;
56
- clone(): this;
57
+ cloneImpl(): this;
57
58
  static fromString(data: string): PdfStream;
58
59
  }
59
60
  export declare class PdfObjStream extends PdfStream {
@@ -68,7 +69,7 @@ export declare class PdfObjStream extends PdfStream {
68
69
  objectNumber: number;
69
70
  }): PdfIndirectObject | undefined;
70
71
  getObjects(): PdfIndirectObject[];
71
- clone(): this;
72
+ cloneImpl(): this;
72
73
  }
73
74
  export declare class PdfXRefStreamCompressedEntry {
74
75
  objectNumber: PdfNumber;
@@ -97,5 +98,5 @@ export declare class PdfXRefStream extends PdfStream {
97
98
  getEntryStream(): Generator<PdfXRefStreamEntry>;
98
99
  getEntries(): PdfXRefStreamEntry[];
99
100
  private readInt;
100
- clone(): this;
101
+ cloneImpl(): this;
101
102
  }
@@ -17,6 +17,7 @@ import { bytesToPdfObjects } from '../generators.js';
17
17
  import { PdfIndirectObject } from './pdf-indirect-object.js';
18
18
  import { PdfXRefTableEntry } from './pdf-xref-table.js';
19
19
  import { stringToBytes } from '../../utils/stringToBytes.js';
20
+ import { bytesToString } from '../../utils/bytesToString.js';
20
21
  export class PdfStream extends PdfObject {
21
22
  header;
22
23
  original;
@@ -52,10 +53,13 @@ export class PdfStream extends PdfObject {
52
53
  this.header.set('Length', new PdfNumber(data.length));
53
54
  }
54
55
  get originalAsString() {
55
- return new TextDecoder().decode(this.original);
56
+ return bytesToString(this.original);
56
57
  }
57
58
  get rawAsString() {
58
- return new TextDecoder().decode(this.raw);
59
+ return bytesToString(this.raw);
60
+ }
61
+ set rawAsString(str) {
62
+ this.raw = stringToBytes(str);
59
63
  }
60
64
  getFilters() {
61
65
  const filters = this.header.get('Filter');
@@ -217,7 +221,7 @@ export class PdfStream extends PdfObject {
217
221
  }
218
222
  return result;
219
223
  }
220
- clone() {
224
+ cloneImpl() {
221
225
  return new PdfStream({
222
226
  header: this.header.clone(),
223
227
  original: new Uint8Array(this.original),
@@ -238,23 +242,48 @@ export class PdfObjStream extends PdfStream {
238
242
  }
239
243
  }
240
244
  static fromObjects(objects) {
241
- let header = '';
242
- let objectData = '';
245
+ const objByteChunks = [];
246
+ const headerParts = [];
243
247
  let offset = 0;
248
+ let objectCount = 0;
244
249
  for (const obj of objects) {
245
- header += `${obj.objectNumber} ${offset} `;
246
- const objString = obj.content.toString();
247
- objectData += objString + '\n';
248
- offset += objString.length + 1;
249
- }
250
+ // Use toBytes() to preserve binary content (e.g. UTF-16BE strings)
251
+ // instead of toString() which is Latin-1 and would be re-encoded as UTF-8
252
+ headerParts.push(`${obj.objectNumber} ${offset}`);
253
+ const bytes = obj.content.toBytes();
254
+ objByteChunks.push(bytes, new Uint8Array([0x0a])); // object + newline
255
+ offset += bytes.length + 1;
256
+ objectCount++;
257
+ }
258
+ const headerStr = headerParts.join(' ');
259
+ // First = byte offset of first compressed object from stream start
260
+ const first = objectCount > 0 ? headerStr.length + 1 : 0;
250
261
  const headerDict = new PdfDictionary();
251
262
  headerDict.set('Type', new PdfName('ObjStm'));
252
- headerDict.set('N', new PdfNumber(header.length));
253
- headerDict.set('First', new PdfNumber(offset));
254
- objectData = `${header.trim()}\n${objectData.trim()}`;
263
+ headerDict.set('N', new PdfNumber(objectCount));
264
+ headerDict.set('First', new PdfNumber(first));
265
+ if (objectCount === 0) {
266
+ return new PdfObjStream({
267
+ header: headerDict,
268
+ original: new Uint8Array(),
269
+ });
270
+ }
271
+ // Build stream bytes: headerStr + '\n' + obj1bytes + obj2bytes + ...
272
+ // Drop trailing newline after the last object
273
+ objByteChunks.pop();
274
+ const headerBytes = stringToBytes(headerStr + '\n');
275
+ const totalLength = objByteChunks.reduce((sum, chunk) => sum + chunk.length, headerBytes.length);
276
+ const streamBytes = new Uint8Array(totalLength);
277
+ let pos = 0;
278
+ streamBytes.set(headerBytes, pos);
279
+ pos += headerBytes.length;
280
+ for (const chunk of objByteChunks) {
281
+ streamBytes.set(chunk, pos);
282
+ pos += chunk.length;
283
+ }
255
284
  return new PdfObjStream({
256
285
  header: headerDict,
257
- original: objectData,
286
+ original: streamBytes,
258
287
  });
259
288
  }
260
289
  *getObjectStream() {
@@ -302,7 +331,7 @@ export class PdfObjStream extends PdfStream {
302
331
  getObjects() {
303
332
  return Array.from(this.getObjectStream());
304
333
  }
305
- clone() {
334
+ cloneImpl() {
306
335
  return new PdfObjStream({
307
336
  header: this.header.clone(),
308
337
  original: new Uint8Array(this.original),
@@ -528,7 +557,7 @@ export class PdfXRefStream extends PdfStream {
528
557
  }
529
558
  return value;
530
559
  }
531
- clone() {
560
+ cloneImpl() {
532
561
  return new PdfXRefStream({
533
562
  header: this.header.clone(),
534
563
  original: new Uint8Array(this.original),
@@ -19,7 +19,8 @@ export declare class PdfString extends PdfObject {
19
19
  * UTF-16BE strings start with the byte order mark 0xFE 0xFF.
20
20
  */
21
21
  get isUTF16BE(): boolean;
22
+ set value(str: string);
22
23
  get value(): string;
23
24
  protected tokenize(): PdfStringToken[];
24
- clone(): this;
25
+ cloneImpl(): this;
25
26
  }
@@ -52,6 +52,20 @@ export class PdfString extends PdfObject {
52
52
  get isUTF16BE() {
53
53
  return (this.raw.length >= 2 && this.raw[0] === 0xfe && this.raw[1] === 0xff);
54
54
  }
55
+ set value(str) {
56
+ if (this.isImmutable()) {
57
+ throw new Error('Cannot modify an immutable PdfString');
58
+ }
59
+ this.setModified();
60
+ if (needsUnicodeEncoding(str)) {
61
+ this._raw = encodeAsUTF16BE(str);
62
+ }
63
+ else {
64
+ this._raw = encodeToPDFDocEncoding(str);
65
+ }
66
+ // Clear original bytes when modified
67
+ this._originalBytes = undefined;
68
+ }
55
69
  get value() {
56
70
  // Check for UTF-16BE BOM (0xFE 0xFF)
57
71
  if (this.isUTF16BE) {
@@ -63,9 +77,10 @@ export class PdfString extends PdfObject {
63
77
  tokenize() {
64
78
  return [new PdfStringToken(this.raw, this._originalBytes)];
65
79
  }
66
- clone() {
67
- return new PdfString(new Uint8Array(this.raw), this._originalBytes
80
+ cloneImpl() {
81
+ const cloned = new PdfString(new Uint8Array(this.raw), this._originalBytes
68
82
  ? new Uint8Array(this._originalBytes)
69
83
  : undefined);
84
+ return cloned;
70
85
  }
71
86
  }
@@ -21,6 +21,6 @@ export declare class PdfTrailer extends PdfObject {
21
21
  offset: Ref<number>;
22
22
  constructor(entries: PdfTrailerEntries | PdfDictionary<PdfTrailerEntries>);
23
23
  protected tokenize(): PdfToken[];
24
- clone(): this;
24
+ cloneImpl(): this;
25
25
  isModified(): boolean;
26
26
  }
@@ -22,8 +22,9 @@ export class PdfTrailer extends PdfObject {
22
22
  ...this.dict.toTokens(),
23
23
  ];
24
24
  }
25
- clone() {
26
- return new PdfTrailer(this.dict.clone());
25
+ cloneImpl() {
26
+ const cloned = new PdfTrailer(this.dict.clone());
27
+ return cloned;
27
28
  }
28
29
  isModified() {
29
30
  return (super.isModified() ||
@@ -16,7 +16,7 @@ export declare class PdfXRefTableEntry extends PdfObject {
16
16
  inUse: boolean;
17
17
  });
18
18
  protected tokenize(): PdfXRefTableEntryToken[];
19
- clone(): this;
19
+ cloneImpl(): this;
20
20
  isModified(): boolean;
21
21
  }
22
22
  export declare class PdfXRefTableSectionHeader extends PdfObject {
@@ -27,7 +27,7 @@ export declare class PdfXRefTableSectionHeader extends PdfObject {
27
27
  entryCount: number | PdfNumber;
28
28
  });
29
29
  protected tokenize(): PdfXRefTableSectionStartToken[];
30
- clone(): this;
30
+ cloneImpl(): this;
31
31
  }
32
32
  export declare class PdfXRefTable extends PdfObject {
33
33
  sections: PdfXRefTableSectionHeader[];
@@ -44,5 +44,5 @@ export declare class PdfXRefTable extends PdfObject {
44
44
  get lastSection(): PdfXRefTableSectionHeader | null;
45
45
  protected tokenize(): import("../index.js").PdfToken[];
46
46
  private sortEntriesIntoSections;
47
- clone(): this;
47
+ cloneImpl(): this;
48
48
  }
@@ -36,7 +36,7 @@ export class PdfXRefTableEntry extends PdfObject {
36
36
  new PdfXRefTableEntryToken(this.byteOffset.toToken(), this.generationNumber.toToken(), this.objectNumber.toToken(), this.inUse),
37
37
  ];
38
38
  }
39
- clone() {
39
+ cloneImpl() {
40
40
  return new PdfXRefTableEntry({
41
41
  byteOffset: this.byteOffset.clone(),
42
42
  objectNumber: this.objectNumber.clone(),
@@ -64,7 +64,7 @@ export class PdfXRefTableSectionHeader extends PdfObject {
64
64
  new PdfXRefTableSectionStartToken(this.startObjectNumber.value, this.entryCount.value),
65
65
  ];
66
66
  }
67
- clone() {
67
+ cloneImpl() {
68
68
  return new PdfXRefTableSectionHeader({
69
69
  startObjectNumber: this.startObjectNumber.clone(),
70
70
  entryCount: this.entryCount.clone(),
@@ -173,7 +173,7 @@ export class PdfXRefTable extends PdfObject {
173
173
  }
174
174
  return sections;
175
175
  }
176
- clone() {
176
+ cloneImpl() {
177
177
  return new PdfXRefTable({
178
178
  sections: this.sections.map((s) => s.clone()),
179
179
  entries: this.entries.map((e) => e.clone()),
@@ -1,17 +1,4 @@
1
1
  import { Parser } from './parser.js';
2
- /**
3
- * Error thrown when the parser needs more input to continue parsing.
4
- */
5
- export declare class NoMoreTokensError extends Error {
6
- }
7
- /**
8
- * Error thrown when the end of file has been reached and no more input is available.
9
- */
10
- export declare class EofReachedError extends Error {
11
- }
12
- export declare class UnexpectedTokenError extends Error {
13
- constructor(expected: string, actual: string | null);
14
- }
15
2
  /**
16
3
  * Abstract base class for incremental parsers that can process input as it becomes available.
17
4
  * Supports buffering, lookahead, and backtracking for complex parsing scenarios.
@@ -1,22 +1,5 @@
1
1
  import { Parser } from './parser.js';
2
- /**
3
- * Error thrown when the parser needs more input to continue parsing.
4
- */
5
- export class NoMoreTokensError extends Error {
6
- }
7
- /**
8
- * Error thrown when the end of file has been reached and no more input is available.
9
- */
10
- export class EofReachedError extends Error {
11
- }
12
- /*
13
- * Error thrown when an unexpected token is encountered during parsing.
14
- */
15
- export class UnexpectedTokenError extends Error {
16
- constructor(expected, actual) {
17
- super(`Unexpected token: expected ${expected}, but got ${actual === null ? 'EOF' : actual}`);
18
- }
19
- }
2
+ import { NoMoreTokensError, EofReachedError } from '../../errors.js';
20
3
  /**
21
4
  * Abstract base class for incremental parsers that can process input as it becomes available.
22
5
  * Supports buffering, lookahead, and backtracking for complex parsing scenarios.
@@ -1,6 +1,6 @@
1
1
  import { PdfObject } from '../objects/pdf-object.js';
2
2
  import { ByteArray } from '../../types.js';
3
- import { IterableReadableStream } from '../../utils/IterableReadableStream.js';
3
+ import { IterableReadableStream } from '../../utils/iterable-readable-stream.js';
4
4
  export declare class PdfObjectStream extends IterableReadableStream<PdfObject> {
5
5
  constructor(input: AsyncIterable<ByteArray> | Iterable<ByteArray>);
6
6
  }
@@ -1,4 +1,4 @@
1
- import { IterableReadableStream } from '../../utils/IterableReadableStream.js';
1
+ import { IterableReadableStream } from '../../utils/iterable-readable-stream.js';
2
2
  import { pdfDecoderAsync } from '../generators.js';
3
3
  export class PdfObjectStream extends IterableReadableStream {
4
4
  constructor(input) {
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Error thrown when the parser needs more input to continue parsing.
3
+ */
4
+ export declare class NoMoreTokensError extends Error {
5
+ }
6
+ /**
7
+ * Error thrown when the end of file has been reached and no more input is available.
8
+ */
9
+ export declare class EofReachedError extends Error {
10
+ }
11
+ /**
12
+ * Error thrown when an unexpected token is encountered during parsing.
13
+ */
14
+ export declare class UnexpectedTokenError extends Error {
15
+ constructor(expected: string, actual: string | null);
16
+ }
17
+ /**
18
+ * Error thrown when attempting to access a compressed object
19
+ * that requires decompression from an object stream.
20
+ */
21
+ export declare class FoundCompressedObjectError extends Error {
22
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Error thrown when the parser needs more input to continue parsing.
3
+ */
4
+ export class NoMoreTokensError extends Error {
5
+ }
6
+ /**
7
+ * Error thrown when the end of file has been reached and no more input is available.
8
+ */
9
+ export class EofReachedError extends Error {
10
+ }
11
+ /**
12
+ * Error thrown when an unexpected token is encountered during parsing.
13
+ */
14
+ export class UnexpectedTokenError extends Error {
15
+ constructor(expected, actual) {
16
+ super(`Unexpected token: expected ${expected}, but got ${actual === null ? 'EOF' : actual}`);
17
+ }
18
+ }
19
+ /**
20
+ * Error thrown when attempting to access a compressed object
21
+ * that requires decompression from an object stream.
22
+ */
23
+ export class FoundCompressedObjectError extends Error {
24
+ }
@@ -1,4 +1,4 @@
1
1
  export * from './types.js';
2
- export * from './font-manager.js';
2
+ export * from './manager.js';
3
3
  export * from './pdf-font.js';
4
4
  export * from './parsers/index.js';
@@ -1,4 +1,4 @@
1
1
  export * from './types.js';
2
- export * from './font-manager.js';
2
+ export * from './manager.js';
3
3
  export * from './pdf-font.js';
4
4
  export * from './parsers/index.js';
@@ -4,9 +4,10 @@ import { PdfName } from '../core/objects/pdf-name.js';
4
4
  import { PdfNumber } from '../core/objects/pdf-number.js';
5
5
  import { PdfArray } from '../core/objects/pdf-array.js';
6
6
  import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
7
- import type { PdfFontManager } from './font-manager.js';
7
+ import type { PdfFontManager } from './manager.js';
8
8
  import type { FontDescriptor, UnicodeFontDescriptor, FontParser } from './types.js';
9
9
  import type { ByteArray } from '../types.js';
10
+ type PdfStandardFontName = 'Helvetica' | 'Helvetica-Bold' | 'Helvetica-Oblique' | 'Helvetica-BoldOblique' | 'Times-Roman' | 'Times-Bold' | 'Times-Italic' | 'Times-BoldItalic' | 'Courier' | 'Courier-Bold' | 'Courier-Oblique' | 'Courier-BoldOblique' | 'Symbol' | 'ZapfDingbats';
10
11
  /**
11
12
  * Represents an embedded font in a PDF document.
12
13
  * Extends PdfDictionary to provide both font metadata and PDF dictionary structure.
@@ -38,11 +39,6 @@ export declare class PdfFont extends PdfDictionary<{
38
39
  * Includes FontDescriptor, FontFile2, CIDFont, ToUnicode, etc.
39
40
  */
40
41
  protected auxiliaryObjects: PdfIndirectObject[];
41
- /**
42
- * @internal
43
- * Reference to the font manager that created this font.
44
- */
45
- private manager?;
46
42
  /**
47
43
  * @internal
48
44
  * Font descriptor with metrics and properties.
@@ -53,6 +49,7 @@ export declare class PdfFont extends PdfDictionary<{
53
49
  * Original font file bytes.
54
50
  */
55
51
  private _fontData?;
52
+ constructor(fontName: string);
56
53
  constructor(options: {
57
54
  dict?: PdfDictionary;
58
55
  fontName?: string;
@@ -109,6 +106,39 @@ export declare class PdfFont extends PdfDictionary<{
109
106
  * Sets the character widths array.
110
107
  */
111
108
  set widths(values: number[] | undefined);
109
+ /**
110
+ * Gets the raw character width (in 1000-unit em square) for a character code.
111
+ * Returns null if the character is not in the font's width table.
112
+ *
113
+ * @param charCode - The character code to get the width for
114
+ * @returns The raw character width or null if not found
115
+ */
116
+ getRawCharacterWidth(charCode: number): number | null;
117
+ /**
118
+ * Gets the character width scaled to the specified font size.
119
+ * Returns null if the character is not in the font's width table.
120
+ *
121
+ * @param charCode - The character code to get the width for
122
+ * @param fontSize - The font size to scale to
123
+ * @returns The scaled character width or null if not found
124
+ */
125
+ getCharacterWidth(charCode: number, fontSize: number): number | null;
126
+ /**
127
+ * Checks if the font has width data for a character code.
128
+ *
129
+ * @param charCode - The character code to check
130
+ * @returns True if width data is available, false otherwise
131
+ */
132
+ hasCharacterWidth(charCode: number): boolean;
133
+ /**
134
+ * Gets character widths for all characters in a string.
135
+ * Returns null for characters not in the font's width table.
136
+ *
137
+ * @param text - The text to get character widths for
138
+ * @param fontSize - The font size to scale to
139
+ * @returns Array of character widths (null for missing characters)
140
+ */
141
+ getCharacterWidthsForString(text: string, fontSize: number): (number | null)[];
112
142
  /**
113
143
  * Returns the resource name for string coercion.
114
144
  * This enables using PdfFont objects in template literals like:
@@ -150,9 +180,35 @@ export declare class PdfFont extends PdfDictionary<{
150
180
  * These fonts don't require font data as they're built into PDF viewers.
151
181
  *
152
182
  * @param fontName - One of the 14 standard PDF fonts
183
+ * @param widths - Optional AFM widths array (1/1000 em units) for chars 32–126
153
184
  * @returns A PdfFont instance ready to be written to the PDF
154
185
  */
155
- static fromStandardFont(fontName: 'Helvetica' | 'Helvetica-Bold' | 'Helvetica-Oblique' | 'Helvetica-BoldOblique' | 'Times-Roman' | 'Times-Bold' | 'Times-Italic' | 'Times-BoldItalic' | 'Courier' | 'Courier-Bold' | 'Courier-Oblique' | 'Courier-BoldOblique' | 'Symbol' | 'ZapfDingbats'): PdfFont;
186
+ static fromStandardFont(fontName: PdfStandardFontName, widths?: number[]): PdfFont;
187
+ private static readonly _HELVETICA_WIDTHS;
188
+ private static readonly _HELVETICA_BOLD_WIDTHS;
189
+ private static readonly _TIMES_ROMAN_WIDTHS;
190
+ private static readonly _TIMES_BOLD_WIDTHS;
191
+ private static readonly _TIMES_ITALIC_WIDTHS;
192
+ private static readonly _TIMES_BOLD_ITALIC_WIDTHS;
193
+ static readonly HELVETICA: PdfFont;
194
+ static readonly HELVETICA_BOLD: PdfFont;
195
+ static readonly HELVETICA_OBLIQUE: PdfFont;
196
+ static readonly HELVETICA_BOLD_OBLIQUE: PdfFont;
197
+ static readonly TIMES_ROMAN: PdfFont;
198
+ static readonly TIMES_BOLD: PdfFont;
199
+ static readonly TIMES_ITALIC: PdfFont;
200
+ static readonly TIMES_BOLD_ITALIC: PdfFont;
201
+ static readonly COURIER: PdfFont;
202
+ static readonly COURIER_BOLD: PdfFont;
203
+ static readonly COURIER_OBLIQUE: PdfFont;
204
+ static readonly COURIER_BOLD_OBLIQUE: PdfFont;
205
+ static readonly SYMBOL: PdfFont;
206
+ static readonly ZAPF_DINGBATS: PdfFont;
207
+ private static readonly BY_BASE_FONT;
208
+ /**
209
+ * Returns the static PdfFont instance for a standard font name, or null if not found.
210
+ */
211
+ static getStandardFont(fontName: string): PdfFont | null;
156
212
  /**
157
213
  * Creates a TrueType font from font file data.
158
214
  * Uses WinAnsiEncoding for standard 8-bit character support.
@@ -183,3 +239,4 @@ export declare class PdfFont extends PdfDictionary<{
183
239
  */
184
240
  private static buildCIDWidthArray;
185
241
  }
242
+ export {};