pdf-lite 1.6.1 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EXAMPLES.md +289 -0
- package/README.md +148 -8
- package/dist/acroform/appearance/pdf-graphics.js +4 -3
- package/dist/acroform/appearance/pdf-text-appearance-stream.js +37 -22
- package/dist/acroform/fields/pdf-button-form-field.js +23 -7
- package/dist/acroform/fields/pdf-default-appearance.js +1 -4
- package/dist/acroform/fields/pdf-form-field.d.ts +10 -0
- package/dist/acroform/fields/pdf-form-field.js +43 -0
- package/dist/acroform/index.d.ts +1 -0
- package/dist/acroform/index.js +1 -0
- package/dist/acroform/js/index.d.ts +5 -0
- package/dist/acroform/js/index.js +5 -0
- package/dist/acroform/js/pdf-field-actions.d.ts +17 -0
- package/dist/acroform/js/pdf-field-actions.js +52 -0
- package/dist/acroform/js/pdf-javascript-action.d.ts +17 -0
- package/dist/acroform/js/pdf-javascript-action.js +38 -0
- package/dist/acroform/js/pdf-js-builtins.d.ts +12 -0
- package/dist/acroform/js/pdf-js-builtins.js +454 -0
- package/dist/acroform/js/pdf-js-engine-impl.d.ts +18 -0
- package/dist/acroform/js/pdf-js-engine-impl.js +22 -0
- package/dist/acroform/js/pdf-js-engine.d.ts +10 -0
- package/dist/acroform/js/pdf-js-engine.js +1 -0
- package/dist/acroform/pdf-acro-form.d.ts +4 -0
- package/dist/acroform/pdf-acro-form.js +58 -2
- package/dist/annotations/pdf-annotation.d.ts +20 -0
- package/dist/core/objects/pdf-dictionary.d.ts +2 -0
- package/dist/core/objects/pdf-dictionary.js +14 -0
- package/package.json +1 -1
|
@@ -10,6 +10,8 @@ import type { PdfFieldType } from './types.js';
|
|
|
10
10
|
import { PdfFormFieldFlags } from './pdf-form-field-flags.js';
|
|
11
11
|
import { PdfDefaultResourcesDictionary } from '../../annotations/pdf-default-resources.js';
|
|
12
12
|
import type { PdfAcroForm } from '../pdf-acro-form.js';
|
|
13
|
+
import { PdfFieldActions } from '../js/pdf-field-actions.js';
|
|
14
|
+
import { PdfJavaScriptAction } from '../js/pdf-javascript-action.js';
|
|
13
15
|
/**
|
|
14
16
|
* Abstract base form field class. Extends PdfWidgetAnnotation with form-specific properties:
|
|
15
17
|
* FT, V, DA, Ff, T (name), field hierarchy (parent/children/siblings).
|
|
@@ -100,6 +102,9 @@ export declare abstract class PdfFormField extends PdfWidgetAnnotation {
|
|
|
100
102
|
set maxLen(maxLen: number | null);
|
|
101
103
|
get kids(): PdfArray<PdfObjectReference> | undefined;
|
|
102
104
|
set kids(kids: PdfObjectReference[]);
|
|
105
|
+
private _resolveActionDict;
|
|
106
|
+
get actions(): PdfFieldActions | null;
|
|
107
|
+
get activateAction(): PdfJavaScriptAction | null;
|
|
103
108
|
abstract generateAppearance(options?: {
|
|
104
109
|
makeReadOnly?: boolean;
|
|
105
110
|
textYOffset?: number;
|
|
@@ -107,6 +112,11 @@ export declare abstract class PdfFormField extends PdfWidgetAnnotation {
|
|
|
107
112
|
setAppearanceStream(stream: PdfIndirectObject | {
|
|
108
113
|
[key: string]: PdfIndirectObject;
|
|
109
114
|
}): void;
|
|
115
|
+
/**
|
|
116
|
+
* Returns the list of appearance state names from the normal appearance
|
|
117
|
+
* dictionary (e.g. ["Yes", "Off"] for a checkbox).
|
|
118
|
+
*/
|
|
119
|
+
get appearanceStates(): string[];
|
|
110
120
|
getAppearanceStream(setting?: string): PdfIndirectObject<PdfStream> | null;
|
|
111
121
|
private static _fallbackCtor?;
|
|
112
122
|
private static _registry;
|
|
@@ -12,6 +12,8 @@ import { PdfWidgetAnnotation } from '../../annotations/pdf-widget-annotation.js'
|
|
|
12
12
|
import { PdfDefaultAppearance } from './pdf-default-appearance.js';
|
|
13
13
|
import { PdfFieldType as PdfFieldTypeConst } from './types.js';
|
|
14
14
|
import { PdfFormFieldFlags } from './pdf-form-field-flags.js';
|
|
15
|
+
import { PdfFieldActions } from '../js/pdf-field-actions.js';
|
|
16
|
+
import { PdfJavaScriptAction } from '../js/pdf-javascript-action.js';
|
|
15
17
|
/**
|
|
16
18
|
* Abstract base form field class. Extends PdfWidgetAnnotation with form-specific properties:
|
|
17
19
|
* FT, V, DA, Ff, T (name), field hierarchy (parent/children/siblings).
|
|
@@ -467,6 +469,36 @@ export class PdfFormField extends PdfWidgetAnnotation {
|
|
|
467
469
|
const kidsArray = new PdfArray(kids);
|
|
468
470
|
this.content.set('Kids', kidsArray);
|
|
469
471
|
}
|
|
472
|
+
_resolveActionDict(key) {
|
|
473
|
+
const entry = this.content.get(key);
|
|
474
|
+
if (entry instanceof PdfObjectReference) {
|
|
475
|
+
const resolved = entry.resolve();
|
|
476
|
+
if (resolved?.content instanceof PdfDictionary) {
|
|
477
|
+
return resolved.content;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
else if (entry instanceof PdfDictionary) {
|
|
481
|
+
return entry;
|
|
482
|
+
}
|
|
483
|
+
return undefined;
|
|
484
|
+
}
|
|
485
|
+
get actions() {
|
|
486
|
+
const aaDict = this._resolveActionDict('AA');
|
|
487
|
+
if (!aaDict)
|
|
488
|
+
return null;
|
|
489
|
+
return aaDict.becomes(PdfFieldActions, {
|
|
490
|
+
activateDict: this._resolveActionDict('A'),
|
|
491
|
+
engine: this._form?.jsEngine,
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
get activateAction() {
|
|
495
|
+
const aDict = this._resolveActionDict('A');
|
|
496
|
+
if (!aDict)
|
|
497
|
+
return null;
|
|
498
|
+
return aDict.becomes(PdfJavaScriptAction, {
|
|
499
|
+
engine: this._form?.jsEngine,
|
|
500
|
+
});
|
|
501
|
+
}
|
|
470
502
|
setAppearanceStream(stream) {
|
|
471
503
|
this.appearanceStreamDict ||= new PdfDictionary();
|
|
472
504
|
if (stream instanceof PdfIndirectObject) {
|
|
@@ -480,6 +512,17 @@ export class PdfFormField extends PdfWidgetAnnotation {
|
|
|
480
512
|
this.appearanceStreamDict.set('N', dict);
|
|
481
513
|
}
|
|
482
514
|
}
|
|
515
|
+
/**
|
|
516
|
+
* Returns the list of appearance state names from the normal appearance
|
|
517
|
+
* dictionary (e.g. ["Yes", "Off"] for a checkbox).
|
|
518
|
+
*/
|
|
519
|
+
get appearanceStates() {
|
|
520
|
+
const n = this.appearanceStreamDict?.get('N');
|
|
521
|
+
if (n instanceof PdfDictionary) {
|
|
522
|
+
return Array.from(n.entries(), ([key]) => key);
|
|
523
|
+
}
|
|
524
|
+
return [];
|
|
525
|
+
}
|
|
483
526
|
getAppearanceStream(setting) {
|
|
484
527
|
const n = this.appearanceStreamDict?.get('N');
|
|
485
528
|
if (!n)
|
package/dist/acroform/index.d.ts
CHANGED
package/dist/acroform/index.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
|
|
2
|
+
import { PdfJavaScriptAction } from './pdf-javascript-action.js';
|
|
3
|
+
import type { PdfJsEngine } from './pdf-js-engine.js';
|
|
4
|
+
export declare class PdfFieldActions extends PdfDictionary {
|
|
5
|
+
private readonly activateDict?;
|
|
6
|
+
readonly engine?: PdfJsEngine;
|
|
7
|
+
constructor(dict: PdfDictionary, options?: {
|
|
8
|
+
activateDict?: PdfDictionary;
|
|
9
|
+
engine?: PdfJsEngine;
|
|
10
|
+
});
|
|
11
|
+
private _resolve;
|
|
12
|
+
get keystroke(): PdfJavaScriptAction | null;
|
|
13
|
+
get validate(): PdfJavaScriptAction | null;
|
|
14
|
+
get calculate(): PdfJavaScriptAction | null;
|
|
15
|
+
get format(): PdfJavaScriptAction | null;
|
|
16
|
+
get activate(): PdfJavaScriptAction | null;
|
|
17
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
|
|
2
|
+
import { PdfObjectReference } from '../../core/objects/pdf-object-reference.js';
|
|
3
|
+
import { PdfJavaScriptAction } from './pdf-javascript-action.js';
|
|
4
|
+
export class PdfFieldActions extends PdfDictionary {
|
|
5
|
+
activateDict;
|
|
6
|
+
engine;
|
|
7
|
+
constructor(dict, options) {
|
|
8
|
+
super();
|
|
9
|
+
this.copyFrom(dict);
|
|
10
|
+
this.activateDict = options?.activateDict;
|
|
11
|
+
this.engine = options?.engine;
|
|
12
|
+
}
|
|
13
|
+
_resolve(key) {
|
|
14
|
+
const entry = this.get(key);
|
|
15
|
+
if (!entry)
|
|
16
|
+
return null;
|
|
17
|
+
let actionDict;
|
|
18
|
+
if (entry instanceof PdfObjectReference) {
|
|
19
|
+
const resolved = entry.resolve();
|
|
20
|
+
if (resolved?.content instanceof PdfDictionary) {
|
|
21
|
+
actionDict = resolved.content;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else if (entry instanceof PdfDictionary) {
|
|
25
|
+
actionDict = entry;
|
|
26
|
+
}
|
|
27
|
+
if (!actionDict)
|
|
28
|
+
return null;
|
|
29
|
+
return actionDict.becomes(PdfJavaScriptAction, {
|
|
30
|
+
engine: this.engine,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
get keystroke() {
|
|
34
|
+
return this._resolve('K');
|
|
35
|
+
}
|
|
36
|
+
get validate() {
|
|
37
|
+
return this._resolve('V');
|
|
38
|
+
}
|
|
39
|
+
get calculate() {
|
|
40
|
+
return this._resolve('C');
|
|
41
|
+
}
|
|
42
|
+
get format() {
|
|
43
|
+
return this._resolve('F');
|
|
44
|
+
}
|
|
45
|
+
get activate() {
|
|
46
|
+
if (!this.activateDict)
|
|
47
|
+
return null;
|
|
48
|
+
return this.activateDict.becomes(PdfJavaScriptAction, {
|
|
49
|
+
engine: this.engine,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
|
|
2
|
+
import { PdfString } from '../../core/objects/pdf-string.js';
|
|
3
|
+
import { PdfStream } from '../../core/objects/pdf-stream.js';
|
|
4
|
+
import { PdfObjectReference } from '../../core/objects/pdf-object-reference.js';
|
|
5
|
+
import { PdfName } from '../../core/objects/pdf-name.js';
|
|
6
|
+
import type { PdfJsEngine, PdfJsEvent } from './pdf-js-engine.js';
|
|
7
|
+
export declare class PdfJavaScriptAction extends PdfDictionary<{
|
|
8
|
+
S?: PdfName;
|
|
9
|
+
JS?: PdfString | PdfStream | PdfObjectReference;
|
|
10
|
+
}> {
|
|
11
|
+
engine?: PdfJsEngine;
|
|
12
|
+
constructor(dict: PdfDictionary, options?: {
|
|
13
|
+
engine?: PdfJsEngine;
|
|
14
|
+
});
|
|
15
|
+
get code(): string | null;
|
|
16
|
+
execute(event: PdfJsEvent): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
|
|
2
|
+
import { PdfString } from '../../core/objects/pdf-string.js';
|
|
3
|
+
import { PdfStream } from '../../core/objects/pdf-stream.js';
|
|
4
|
+
import { PdfObjectReference } from '../../core/objects/pdf-object-reference.js';
|
|
5
|
+
import { bytesToString } from '../../utils/bytesToString.js';
|
|
6
|
+
export class PdfJavaScriptAction extends PdfDictionary {
|
|
7
|
+
engine;
|
|
8
|
+
constructor(dict, options) {
|
|
9
|
+
super();
|
|
10
|
+
this.copyFrom(dict);
|
|
11
|
+
this.engine = options?.engine;
|
|
12
|
+
}
|
|
13
|
+
get code() {
|
|
14
|
+
const js = this.get('JS');
|
|
15
|
+
if (js instanceof PdfString) {
|
|
16
|
+
return js.value;
|
|
17
|
+
}
|
|
18
|
+
if (js instanceof PdfObjectReference) {
|
|
19
|
+
const resolved = js.resolve();
|
|
20
|
+
if (resolved?.content instanceof PdfStream) {
|
|
21
|
+
return bytesToString(resolved.content.data);
|
|
22
|
+
}
|
|
23
|
+
if (resolved?.content instanceof PdfString) {
|
|
24
|
+
return resolved.content.value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (js instanceof PdfStream) {
|
|
28
|
+
return bytesToString(js.data);
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
execute(event) {
|
|
33
|
+
const code = this.code;
|
|
34
|
+
if (code && this.engine) {
|
|
35
|
+
this.engine.execute(code, event);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PdfJsEvent } from './pdf-js-engine.js';
|
|
2
|
+
export declare function printd(fmt: string, date: Date): string;
|
|
3
|
+
export declare function scand(fmt: string, str: string): Date | null;
|
|
4
|
+
export declare function printf(fmt: string, ...args: unknown[]): string;
|
|
5
|
+
export declare const util: {
|
|
6
|
+
printd: typeof printd;
|
|
7
|
+
scand: typeof scand;
|
|
8
|
+
printf: typeof printf;
|
|
9
|
+
};
|
|
10
|
+
type GetFieldValue = (name: string) => string;
|
|
11
|
+
export declare function createBuiltins(event: PdfJsEvent, getFieldValue?: GetFieldValue): Record<string, unknown>;
|
|
12
|
+
export {};
|