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.
- package/dist/acroform/acroform.d.ts +7 -454
- package/dist/acroform/acroform.js +5 -1664
- package/dist/acroform/appearance/index.d.ts +4 -0
- package/dist/acroform/appearance/index.js +4 -0
- package/dist/acroform/appearance/pdf-appearance-stream.d.ts +21 -0
- package/dist/acroform/appearance/pdf-appearance-stream.js +41 -0
- package/dist/acroform/appearance/pdf-button-appearance-stream.d.ts +13 -0
- package/dist/acroform/appearance/pdf-button-appearance-stream.js +54 -0
- package/dist/acroform/appearance/pdf-choice-appearance-stream.d.ts +22 -0
- package/dist/acroform/appearance/pdf-choice-appearance-stream.js +75 -0
- package/dist/acroform/appearance/pdf-graphics.d.ts +51 -0
- package/dist/acroform/appearance/pdf-graphics.js +239 -0
- package/dist/acroform/appearance/pdf-text-appearance-stream.d.ts +22 -0
- package/dist/acroform/appearance/pdf-text-appearance-stream.js +104 -0
- package/dist/acroform/fields/index.d.ts +8 -0
- package/dist/acroform/fields/index.js +8 -0
- package/dist/acroform/fields/pdf-button-form-field.d.ts +23 -0
- package/dist/acroform/fields/pdf-button-form-field.js +102 -0
- package/dist/acroform/fields/pdf-choice-form-field.d.ts +18 -0
- package/dist/acroform/fields/pdf-choice-form-field.js +131 -0
- package/dist/acroform/fields/pdf-default-appearance.d.ts +23 -0
- package/dist/acroform/fields/pdf-default-appearance.js +68 -0
- package/dist/acroform/fields/pdf-form-field-flags.d.ts +45 -0
- package/dist/acroform/fields/pdf-form-field-flags.js +122 -0
- package/dist/acroform/fields/pdf-form-field.d.ts +123 -0
- package/dist/acroform/fields/pdf-form-field.js +433 -0
- package/dist/acroform/fields/pdf-signature-form-field.d.ts +7 -0
- package/dist/acroform/fields/pdf-signature-form-field.js +12 -0
- package/dist/acroform/fields/pdf-text-form-field.d.ts +10 -0
- package/dist/acroform/fields/pdf-text-form-field.js +77 -0
- package/dist/acroform/fields/types.d.ts +26 -0
- package/dist/acroform/fields/types.js +9 -0
- package/dist/acroform/index.d.ts +5 -1
- package/dist/acroform/index.js +5 -1
- package/dist/acroform/manager.d.ts +12 -1
- package/dist/acroform/manager.js +20 -2
- package/dist/acroform/pdf-acro-form.d.ts +69 -0
- package/dist/acroform/pdf-acro-form.js +293 -0
- package/dist/acroform/pdf-font-encoding-cache.d.ts +27 -0
- package/dist/acroform/pdf-font-encoding-cache.js +188 -0
- package/dist/acroform/xfa/index.d.ts +3 -0
- package/dist/acroform/xfa/index.js +2 -0
- package/dist/acroform/xfa/pdf-xfa-data.d.ts +20 -0
- package/dist/acroform/xfa/pdf-xfa-data.js +68 -0
- package/dist/acroform/xfa/pdf-xfa-form.d.ts +11 -0
- package/dist/acroform/xfa/pdf-xfa-form.js +56 -0
- package/dist/annotations/index.d.ts +4 -0
- package/dist/annotations/index.js +4 -0
- package/dist/annotations/pdf-annotation-flags.d.ts +24 -0
- package/dist/annotations/pdf-annotation-flags.js +93 -0
- package/dist/annotations/pdf-annotation-writer.d.ts +20 -0
- package/dist/annotations/pdf-annotation-writer.js +76 -0
- package/dist/annotations/pdf-annotation.d.ts +61 -0
- package/dist/annotations/pdf-annotation.js +106 -0
- package/dist/annotations/pdf-widget-annotation.d.ts +15 -0
- package/dist/annotations/pdf-widget-annotation.js +37 -0
- package/dist/core/objects/pdf-array.d.ts +1 -1
- package/dist/core/objects/pdf-array.js +3 -2
- package/dist/core/objects/pdf-boolean.d.ts +1 -1
- package/dist/core/objects/pdf-boolean.js +3 -2
- package/dist/core/objects/pdf-comment.d.ts +1 -1
- package/dist/core/objects/pdf-comment.js +1 -1
- package/dist/core/objects/pdf-dictionary.d.ts +1 -1
- package/dist/core/objects/pdf-dictionary.js +3 -2
- package/dist/core/objects/pdf-hexadecimal.d.ts +1 -1
- package/dist/core/objects/pdf-hexadecimal.js +3 -2
- package/dist/core/objects/pdf-indirect-object.d.ts +1 -1
- package/dist/core/objects/pdf-indirect-object.js +1 -1
- package/dist/core/objects/pdf-name.d.ts +1 -1
- package/dist/core/objects/pdf-name.js +3 -2
- package/dist/core/objects/pdf-null.d.ts +1 -1
- package/dist/core/objects/pdf-null.js +3 -2
- package/dist/core/objects/pdf-number.d.ts +1 -1
- package/dist/core/objects/pdf-number.js +3 -2
- package/dist/core/objects/pdf-object-reference.d.ts +1 -1
- package/dist/core/objects/pdf-object-reference.js +3 -2
- package/dist/core/objects/pdf-object.d.ts +3 -1
- package/dist/core/objects/pdf-object.js +6 -0
- package/dist/core/objects/pdf-start-xref.d.ts +1 -1
- package/dist/core/objects/pdf-start-xref.js +3 -2
- package/dist/core/objects/pdf-stream.d.ts +4 -3
- package/dist/core/objects/pdf-stream.js +45 -16
- package/dist/core/objects/pdf-string.d.ts +2 -1
- package/dist/core/objects/pdf-string.js +17 -2
- package/dist/core/objects/pdf-trailer.d.ts +1 -1
- package/dist/core/objects/pdf-trailer.js +3 -2
- package/dist/core/objects/pdf-xref-table.d.ts +3 -3
- package/dist/core/objects/pdf-xref-table.js +3 -3
- package/dist/core/parser/incremental-parser.d.ts +0 -13
- package/dist/core/parser/incremental-parser.js +1 -18
- package/dist/core/streams/object-stream.d.ts +1 -1
- package/dist/core/streams/object-stream.js +1 -1
- package/dist/errors.d.ts +22 -0
- package/dist/errors.js +24 -0
- package/dist/fonts/index.d.ts +1 -1
- package/dist/fonts/index.js +1 -1
- package/dist/fonts/pdf-font.d.ts +64 -7
- package/dist/fonts/pdf-font.js +188 -8
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/pdf/index.d.ts +0 -1
- package/dist/pdf/index.js +0 -1
- package/dist/pdf/pdf-document.d.ts +16 -12
- package/dist/pdf/pdf-document.js +51 -37
- package/dist/pdf/pdf-revision.d.ts +1 -1
- package/dist/pdf/pdf-revision.js +1 -1
- package/dist/pdf/pdf-xref-lookup.d.ts +8 -0
- package/dist/pdf/pdf-xref-lookup.js +12 -0
- package/dist/security/handlers/base.js +3 -0
- package/dist/utils/encodePdfText.d.ts +17 -0
- package/dist/utils/encodePdfText.js +61 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/package.json +1 -1
- package/dist/pdf/errors.d.ts +0 -6
- package/dist/pdf/errors.js +0 -6
- package/dist/xfa/index.d.ts +0 -1
- package/dist/xfa/index.js +0 -1
- package/dist/xfa/manager.d.ts +0 -44
- package/dist/xfa/manager.js +0 -136
- /package/dist/fonts/{font-manager.d.ts → manager.d.ts} +0 -0
- /package/dist/fonts/{font-manager.js → manager.js} +0 -0
- /package/dist/utils/{IterableReadableStream.d.ts → iterable-readable-stream.d.ts} +0 -0
- /package/dist/utils/{IterableReadableStream.js → iterable-readable-stream.js} +0 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PdfDocument } from '../../pdf/pdf-document.js';
|
|
2
|
+
import { PdfArray } from '../../core/objects/pdf-array.js';
|
|
3
|
+
import { PdfXfaData } from './pdf-xfa-data.js';
|
|
4
|
+
/**
|
|
5
|
+
* Typed wrapper around the XFA name/stream-ref array.
|
|
6
|
+
* Holds eagerly-loaded references to component streams like datasets.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PdfXfaForm extends PdfArray {
|
|
9
|
+
datasets: PdfXfaData | null;
|
|
10
|
+
static fromDocument(document: PdfDocument): Promise<PdfXfaForm | null>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { PdfArray } from '../../core/objects/pdf-array.js';
|
|
2
|
+
import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
|
|
3
|
+
import { PdfString } from '../../core/objects/pdf-string.js';
|
|
4
|
+
import { PdfObjectReference } from '../../core/objects/pdf-object-reference.js';
|
|
5
|
+
import { PdfIndirectObject } from '../../core/objects/pdf-indirect-object.js';
|
|
6
|
+
import { PdfXfaData } from './pdf-xfa-data.js';
|
|
7
|
+
/**
|
|
8
|
+
* Typed wrapper around the XFA name/stream-ref array.
|
|
9
|
+
* Holds eagerly-loaded references to component streams like datasets.
|
|
10
|
+
*/
|
|
11
|
+
export class PdfXfaForm extends PdfArray {
|
|
12
|
+
datasets = null;
|
|
13
|
+
static async fromDocument(document) {
|
|
14
|
+
const catalog = document.root;
|
|
15
|
+
const acroFormRef = catalog.content.get('AcroForm');
|
|
16
|
+
if (!acroFormRef)
|
|
17
|
+
return null;
|
|
18
|
+
let acroFormDict;
|
|
19
|
+
if (acroFormRef instanceof PdfObjectReference) {
|
|
20
|
+
const acroFormObject = await document.readObject(acroFormRef);
|
|
21
|
+
if (!acroFormObject)
|
|
22
|
+
return null;
|
|
23
|
+
acroFormDict = acroFormObject.content.as(PdfDictionary);
|
|
24
|
+
}
|
|
25
|
+
else if (acroFormRef instanceof PdfDictionary) {
|
|
26
|
+
acroFormDict = acroFormRef;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const xfaArray = acroFormDict.get('XFA');
|
|
32
|
+
if (!(xfaArray instanceof PdfArray))
|
|
33
|
+
return null;
|
|
34
|
+
const form = new PdfXfaForm(xfaArray.items.slice());
|
|
35
|
+
// Find the datasets reference in the name/ref pairs
|
|
36
|
+
const items = xfaArray.items;
|
|
37
|
+
for (let i = 0; i < items.length - 1; i += 2) {
|
|
38
|
+
const name = items[i];
|
|
39
|
+
const ref = items[i + 1];
|
|
40
|
+
if (name instanceof PdfString &&
|
|
41
|
+
name.value === 'datasets' &&
|
|
42
|
+
ref instanceof PdfObjectReference) {
|
|
43
|
+
const datasetObject = (await document.readObject({
|
|
44
|
+
objectNumber: ref.objectNumber,
|
|
45
|
+
generationNumber: ref.generationNumber,
|
|
46
|
+
allowUnindexed: true,
|
|
47
|
+
}))?.as((PdfIndirectObject));
|
|
48
|
+
if (datasetObject) {
|
|
49
|
+
form.datasets = new PdfXfaData(datasetObject);
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return form;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { PdfAnnotation, type PdfAppearanceStreamDictionary, } from './pdf-annotation.js';
|
|
2
|
+
export { PdfAnnotationFlags } from './pdf-annotation-flags.js';
|
|
3
|
+
export { PdfWidgetAnnotation } from './pdf-widget-annotation.js';
|
|
4
|
+
export { PdfAnnotationWriter } from './pdf-annotation-writer.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PdfNumber } from '../core/objects/pdf-number.js';
|
|
2
|
+
/**
|
|
3
|
+
* Provides annotation flag (F field) accessors for PDF annotations.
|
|
4
|
+
* These are generic to all annotation types per the PDF spec.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PdfAnnotationFlags extends PdfNumber {
|
|
7
|
+
constructor(value?: number);
|
|
8
|
+
get annotationFlags(): number;
|
|
9
|
+
set annotationFlags(flags: number);
|
|
10
|
+
get invisible(): boolean;
|
|
11
|
+
set invisible(value: boolean);
|
|
12
|
+
get hidden(): boolean;
|
|
13
|
+
set hidden(value: boolean);
|
|
14
|
+
get print(): boolean;
|
|
15
|
+
set print(value: boolean);
|
|
16
|
+
get noZoom(): boolean;
|
|
17
|
+
set noZoom(value: boolean);
|
|
18
|
+
get noRotate(): boolean;
|
|
19
|
+
set noRotate(value: boolean);
|
|
20
|
+
get noView(): boolean;
|
|
21
|
+
set noView(value: boolean);
|
|
22
|
+
get locked(): boolean;
|
|
23
|
+
set locked(value: boolean);
|
|
24
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { PdfNumber } from '../core/objects/pdf-number.js';
|
|
2
|
+
/**
|
|
3
|
+
* Provides annotation flag (F field) accessors for PDF annotations.
|
|
4
|
+
* These are generic to all annotation types per the PDF spec.
|
|
5
|
+
*/
|
|
6
|
+
export class PdfAnnotationFlags extends PdfNumber {
|
|
7
|
+
constructor(value = 0) {
|
|
8
|
+
super(value);
|
|
9
|
+
}
|
|
10
|
+
get annotationFlags() {
|
|
11
|
+
return this.value;
|
|
12
|
+
}
|
|
13
|
+
set annotationFlags(flags) {
|
|
14
|
+
this.value = flags;
|
|
15
|
+
}
|
|
16
|
+
get invisible() {
|
|
17
|
+
return (this.annotationFlags & 1) !== 0;
|
|
18
|
+
}
|
|
19
|
+
set invisible(value) {
|
|
20
|
+
if (value) {
|
|
21
|
+
this.annotationFlags = this.annotationFlags | 1;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this.annotationFlags = this.annotationFlags & ~1;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
get hidden() {
|
|
28
|
+
return (this.annotationFlags & 2) !== 0;
|
|
29
|
+
}
|
|
30
|
+
set hidden(value) {
|
|
31
|
+
if (value) {
|
|
32
|
+
this.annotationFlags = this.annotationFlags | 2;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this.annotationFlags = this.annotationFlags & ~2;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
get print() {
|
|
39
|
+
return (this.annotationFlags & 4) !== 0;
|
|
40
|
+
}
|
|
41
|
+
set print(value) {
|
|
42
|
+
if (value) {
|
|
43
|
+
this.annotationFlags = this.annotationFlags | 4;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.annotationFlags = this.annotationFlags & ~4;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
get noZoom() {
|
|
50
|
+
return (this.annotationFlags & 8) !== 0;
|
|
51
|
+
}
|
|
52
|
+
set noZoom(value) {
|
|
53
|
+
if (value) {
|
|
54
|
+
this.annotationFlags = this.annotationFlags | 8;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.annotationFlags = this.annotationFlags & ~8;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
get noRotate() {
|
|
61
|
+
return (this.annotationFlags & 16) !== 0;
|
|
62
|
+
}
|
|
63
|
+
set noRotate(value) {
|
|
64
|
+
if (value) {
|
|
65
|
+
this.annotationFlags = this.annotationFlags | 16;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
this.annotationFlags = this.annotationFlags & ~16;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
get noView() {
|
|
72
|
+
return (this.annotationFlags & 32) !== 0;
|
|
73
|
+
}
|
|
74
|
+
set noView(value) {
|
|
75
|
+
if (value) {
|
|
76
|
+
this.annotationFlags = this.annotationFlags | 32;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.annotationFlags = this.annotationFlags & ~32;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
get locked() {
|
|
83
|
+
return (this.annotationFlags & 128) !== 0;
|
|
84
|
+
}
|
|
85
|
+
set locked(value) {
|
|
86
|
+
if (value) {
|
|
87
|
+
this.annotationFlags = this.annotationFlags | 128;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
this.annotationFlags = this.annotationFlags & ~128;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PdfDocument } from '../pdf/pdf-document.js';
|
|
2
|
+
import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
|
|
3
|
+
import { PdfArray } from '../core/objects/pdf-array.js';
|
|
4
|
+
import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
|
|
5
|
+
/**
|
|
6
|
+
* Manages page Annots arrays during AcroForm write operations.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PdfAnnotationWriter {
|
|
9
|
+
static getPageAnnotsArray(document: PdfDocument, pageDict: PdfDictionary): Promise<{
|
|
10
|
+
annotsArray: PdfArray<PdfObjectReference>;
|
|
11
|
+
isIndirect: boolean;
|
|
12
|
+
objectNumber?: number;
|
|
13
|
+
generationNumber?: number;
|
|
14
|
+
}>;
|
|
15
|
+
static addFieldsToAnnots(annotsArray: PdfArray<PdfObjectReference>, fieldRefs: PdfObjectReference[]): void;
|
|
16
|
+
static updatePageAnnotations(document: PdfDocument, fieldsByPage: Map<string, {
|
|
17
|
+
pageRef: PdfObjectReference;
|
|
18
|
+
fieldRefs: PdfObjectReference[];
|
|
19
|
+
}>): Promise<void>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
|
|
2
|
+
import { PdfArray } from '../core/objects/pdf-array.js';
|
|
3
|
+
import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
|
|
4
|
+
import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
|
|
5
|
+
/**
|
|
6
|
+
* Manages page Annots arrays during AcroForm write operations.
|
|
7
|
+
*/
|
|
8
|
+
export class PdfAnnotationWriter {
|
|
9
|
+
static async getPageAnnotsArray(document, pageDict) {
|
|
10
|
+
const annotsRef = pageDict.get('Annots');
|
|
11
|
+
if (annotsRef instanceof PdfObjectReference) {
|
|
12
|
+
const annotsObj = await document.readObject({
|
|
13
|
+
objectNumber: annotsRef.objectNumber,
|
|
14
|
+
generationNumber: annotsRef.generationNumber,
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
annotsArray: annotsObj.content
|
|
18
|
+
.as((PdfArray))
|
|
19
|
+
.clone(),
|
|
20
|
+
isIndirect: true,
|
|
21
|
+
objectNumber: annotsRef.objectNumber,
|
|
22
|
+
generationNumber: annotsRef.generationNumber,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else if (annotsRef instanceof PdfArray) {
|
|
26
|
+
return {
|
|
27
|
+
annotsArray: annotsRef.as((PdfArray)).clone(),
|
|
28
|
+
isIndirect: false,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const newArray = new PdfArray();
|
|
33
|
+
pageDict.set('Annots', newArray);
|
|
34
|
+
return {
|
|
35
|
+
annotsArray: newArray,
|
|
36
|
+
isIndirect: false,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
static addFieldsToAnnots(annotsArray, fieldRefs) {
|
|
41
|
+
for (const fieldRef of fieldRefs) {
|
|
42
|
+
const exists = annotsArray.items.some((ref) => ref.equals(fieldRef));
|
|
43
|
+
if (!exists) {
|
|
44
|
+
annotsArray.push(fieldRef);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
static async updatePageAnnotations(document, fieldsByPage) {
|
|
49
|
+
for (const { pageRef, fieldRefs } of fieldsByPage.values()) {
|
|
50
|
+
const pageObj = await document.readObject({
|
|
51
|
+
objectNumber: pageRef.objectNumber,
|
|
52
|
+
generationNumber: pageRef.generationNumber,
|
|
53
|
+
});
|
|
54
|
+
if (!pageObj)
|
|
55
|
+
continue;
|
|
56
|
+
const pageDict = pageObj.content.as(PdfDictionary).clone();
|
|
57
|
+
const annotsInfo = await PdfAnnotationWriter.getPageAnnotsArray(document, pageDict);
|
|
58
|
+
PdfAnnotationWriter.addFieldsToAnnots(annotsInfo.annotsArray, fieldRefs);
|
|
59
|
+
if (annotsInfo.isIndirect &&
|
|
60
|
+
annotsInfo.objectNumber !== undefined) {
|
|
61
|
+
const annotsIndirect = new PdfIndirectObject({
|
|
62
|
+
objectNumber: annotsInfo.objectNumber,
|
|
63
|
+
generationNumber: annotsInfo.generationNumber,
|
|
64
|
+
content: annotsInfo.annotsArray,
|
|
65
|
+
});
|
|
66
|
+
document.add(annotsIndirect);
|
|
67
|
+
}
|
|
68
|
+
const pageIndirect = new PdfIndirectObject({
|
|
69
|
+
objectNumber: pageRef.objectNumber,
|
|
70
|
+
generationNumber: pageRef.generationNumber,
|
|
71
|
+
content: pageDict,
|
|
72
|
+
});
|
|
73
|
+
document.add(pageIndirect);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
|
|
2
|
+
import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
|
|
3
|
+
import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
|
|
4
|
+
import { PdfArray } from '../core/objects/pdf-array.js';
|
|
5
|
+
import { PdfNumber } from '../core/objects/pdf-number.js';
|
|
6
|
+
import { PdfName } from '../core/objects/pdf-name.js';
|
|
7
|
+
import { PdfString } from '../core/objects/pdf-string.js';
|
|
8
|
+
export type PdfAppearanceStreamDictionary = PdfDictionary<{
|
|
9
|
+
N: PdfObjectReference | PdfDictionary;
|
|
10
|
+
R?: PdfObjectReference | PdfDictionary;
|
|
11
|
+
D?: PdfObjectReference | PdfDictionary;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* Base class for all PDF annotations.
|
|
15
|
+
*/
|
|
16
|
+
export declare class PdfAnnotation extends PdfIndirectObject<PdfDictionary<{
|
|
17
|
+
Type: PdfName;
|
|
18
|
+
Subtype: PdfName;
|
|
19
|
+
AS: PdfName;
|
|
20
|
+
Ff: PdfNumber;
|
|
21
|
+
FT: PdfName;
|
|
22
|
+
T: PdfString;
|
|
23
|
+
DV: PdfString | PdfName;
|
|
24
|
+
V: PdfString | PdfName;
|
|
25
|
+
DA: PdfString;
|
|
26
|
+
Opt: PdfArray<PdfString | PdfArray<PdfString>>;
|
|
27
|
+
MaxLen: PdfNumber;
|
|
28
|
+
Q: PdfNumber;
|
|
29
|
+
Kids: PdfArray<PdfObjectReference>;
|
|
30
|
+
Rect: PdfArray<PdfNumber>;
|
|
31
|
+
F: PdfNumber;
|
|
32
|
+
AP?: PdfAppearanceStreamDictionary;
|
|
33
|
+
P?: PdfObjectReference;
|
|
34
|
+
}>> {
|
|
35
|
+
private _annotationFlags;
|
|
36
|
+
constructor(options?: {
|
|
37
|
+
other?: PdfIndirectObject;
|
|
38
|
+
});
|
|
39
|
+
get rect(): [number, number, number, number] | null;
|
|
40
|
+
set rect(rect: [number, number, number, number] | null);
|
|
41
|
+
get annotationFlags(): number;
|
|
42
|
+
set annotationFlags(flags: number);
|
|
43
|
+
get invisible(): boolean;
|
|
44
|
+
set invisible(value: boolean);
|
|
45
|
+
get hidden(): boolean;
|
|
46
|
+
set hidden(value: boolean);
|
|
47
|
+
get print(): boolean;
|
|
48
|
+
set print(value: boolean);
|
|
49
|
+
get noZoom(): boolean;
|
|
50
|
+
set noZoom(value: boolean);
|
|
51
|
+
get noRotate(): boolean;
|
|
52
|
+
set noRotate(value: boolean);
|
|
53
|
+
get noView(): boolean;
|
|
54
|
+
set noView(value: boolean);
|
|
55
|
+
get locked(): boolean;
|
|
56
|
+
set locked(value: boolean);
|
|
57
|
+
get appearanceStreamDict(): PdfAppearanceStreamDictionary | null;
|
|
58
|
+
set appearanceStreamDict(dict: PdfAppearanceStreamDictionary | null);
|
|
59
|
+
get parentRef(): PdfObjectReference | null;
|
|
60
|
+
set parentRef(ref: PdfObjectReference | null);
|
|
61
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { PdfDictionary } from '../core/objects/pdf-dictionary.js';
|
|
2
|
+
import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
|
|
3
|
+
import { PdfObjectReference } from '../core/objects/pdf-object-reference.js';
|
|
4
|
+
import { PdfArray } from '../core/objects/pdf-array.js';
|
|
5
|
+
import { PdfNumber } from '../core/objects/pdf-number.js';
|
|
6
|
+
import { PdfAnnotationFlags } from './pdf-annotation-flags.js';
|
|
7
|
+
/**
|
|
8
|
+
* Base class for all PDF annotations.
|
|
9
|
+
*/
|
|
10
|
+
export class PdfAnnotation extends PdfIndirectObject {
|
|
11
|
+
_annotationFlags;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options?.other ??
|
|
14
|
+
new PdfIndirectObject({ content: new PdfDictionary() }));
|
|
15
|
+
const flagValue = this.content.get('F')?.as(PdfNumber)?.value ?? 0;
|
|
16
|
+
this._annotationFlags = new PdfAnnotationFlags(flagValue);
|
|
17
|
+
this.content.set('F', this._annotationFlags);
|
|
18
|
+
}
|
|
19
|
+
get rect() {
|
|
20
|
+
const rectArray = this.content.get('Rect')?.as((PdfArray));
|
|
21
|
+
if (!rectArray)
|
|
22
|
+
return null;
|
|
23
|
+
return rectArray.items.map((num) => num.value);
|
|
24
|
+
}
|
|
25
|
+
set rect(rect) {
|
|
26
|
+
if (rect === null) {
|
|
27
|
+
this.content.delete('Rect');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const rectArray = new PdfArray(rect.map((num) => new PdfNumber(num)));
|
|
31
|
+
this.content.set('Rect', rectArray);
|
|
32
|
+
}
|
|
33
|
+
get annotationFlags() {
|
|
34
|
+
return this._annotationFlags.annotationFlags;
|
|
35
|
+
}
|
|
36
|
+
set annotationFlags(flags) {
|
|
37
|
+
this._annotationFlags.annotationFlags = flags;
|
|
38
|
+
}
|
|
39
|
+
get invisible() {
|
|
40
|
+
return this._annotationFlags.invisible;
|
|
41
|
+
}
|
|
42
|
+
set invisible(value) {
|
|
43
|
+
this._annotationFlags.invisible = value;
|
|
44
|
+
}
|
|
45
|
+
get hidden() {
|
|
46
|
+
return this._annotationFlags.hidden;
|
|
47
|
+
}
|
|
48
|
+
set hidden(value) {
|
|
49
|
+
this._annotationFlags.hidden = value;
|
|
50
|
+
}
|
|
51
|
+
get print() {
|
|
52
|
+
return this._annotationFlags.print;
|
|
53
|
+
}
|
|
54
|
+
set print(value) {
|
|
55
|
+
this._annotationFlags.print = value;
|
|
56
|
+
}
|
|
57
|
+
get noZoom() {
|
|
58
|
+
return this._annotationFlags.noZoom;
|
|
59
|
+
}
|
|
60
|
+
set noZoom(value) {
|
|
61
|
+
this._annotationFlags.noZoom = value;
|
|
62
|
+
}
|
|
63
|
+
get noRotate() {
|
|
64
|
+
return this._annotationFlags.noRotate;
|
|
65
|
+
}
|
|
66
|
+
set noRotate(value) {
|
|
67
|
+
this._annotationFlags.noRotate = value;
|
|
68
|
+
}
|
|
69
|
+
get noView() {
|
|
70
|
+
return this._annotationFlags.noView;
|
|
71
|
+
}
|
|
72
|
+
set noView(value) {
|
|
73
|
+
this._annotationFlags.noView = value;
|
|
74
|
+
}
|
|
75
|
+
get locked() {
|
|
76
|
+
return this._annotationFlags.locked;
|
|
77
|
+
}
|
|
78
|
+
set locked(value) {
|
|
79
|
+
this._annotationFlags.locked = value;
|
|
80
|
+
}
|
|
81
|
+
get appearanceStreamDict() {
|
|
82
|
+
const apDict = this.content.get('AP')?.as(PdfDictionary);
|
|
83
|
+
if (!apDict)
|
|
84
|
+
return null;
|
|
85
|
+
return apDict;
|
|
86
|
+
}
|
|
87
|
+
set appearanceStreamDict(dict) {
|
|
88
|
+
if (dict === null) {
|
|
89
|
+
this.content.delete('AP');
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this.content.set('AP', dict);
|
|
93
|
+
}
|
|
94
|
+
get parentRef() {
|
|
95
|
+
const ref = this.content.get('P')?.as(PdfObjectReference);
|
|
96
|
+
return ref ?? null;
|
|
97
|
+
}
|
|
98
|
+
set parentRef(ref) {
|
|
99
|
+
if (ref === null) {
|
|
100
|
+
this.content.delete('P');
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
this.content.set('P', ref);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PdfIndirectObject } from '../core/objects/pdf-indirect-object.js';
|
|
2
|
+
import { PdfAnnotation } from './pdf-annotation.js';
|
|
3
|
+
/**
|
|
4
|
+
* Widget annotation subtype. Extends PdfAnnotation with widget-specific
|
|
5
|
+
* properties: isWidget (Type/Subtype) and AS (appearance state).
|
|
6
|
+
*/
|
|
7
|
+
export declare class PdfWidgetAnnotation extends PdfAnnotation {
|
|
8
|
+
constructor(options?: {
|
|
9
|
+
other?: PdfIndirectObject;
|
|
10
|
+
});
|
|
11
|
+
get isWidget(): boolean;
|
|
12
|
+
set isWidget(isWidget: boolean);
|
|
13
|
+
get appearanceState(): string | null;
|
|
14
|
+
set appearanceState(state: string | null);
|
|
15
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { PdfName } from '../core/objects/pdf-name.js';
|
|
2
|
+
import { PdfAnnotation } from './pdf-annotation.js';
|
|
3
|
+
/**
|
|
4
|
+
* Widget annotation subtype. Extends PdfAnnotation with widget-specific
|
|
5
|
+
* properties: isWidget (Type/Subtype) and AS (appearance state).
|
|
6
|
+
*/
|
|
7
|
+
export class PdfWidgetAnnotation extends PdfAnnotation {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(options);
|
|
10
|
+
}
|
|
11
|
+
get isWidget() {
|
|
12
|
+
const type = this.content.get('Type')?.as(PdfName)?.value;
|
|
13
|
+
const subtype = this.content.get('Subtype')?.as(PdfName)?.value;
|
|
14
|
+
return type === 'Annot' && subtype === 'Widget';
|
|
15
|
+
}
|
|
16
|
+
set isWidget(isWidget) {
|
|
17
|
+
if (isWidget) {
|
|
18
|
+
this.content.set('Type', new PdfName('Annot'));
|
|
19
|
+
this.content.set('Subtype', new PdfName('Widget'));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
this.content.delete('Type');
|
|
23
|
+
this.content.delete('Subtype');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
get appearanceState() {
|
|
27
|
+
return this.content.get('AS')?.as(PdfName)?.value ?? null;
|
|
28
|
+
}
|
|
29
|
+
set appearanceState(state) {
|
|
30
|
+
if (state === null) {
|
|
31
|
+
this.content.delete('AS');
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.content.set('AS', new PdfName(state));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -7,7 +7,7 @@ export declare class PdfArray<T extends PdfObject = PdfObject> extends PdfObject
|
|
|
7
7
|
get length(): number;
|
|
8
8
|
push(item: T): void;
|
|
9
9
|
protected tokenize(): import("../index.js").PdfToken[];
|
|
10
|
-
|
|
10
|
+
cloneImpl(): this;
|
|
11
11
|
isModified(): boolean;
|
|
12
12
|
setImmutable(immutable?: boolean): void;
|
|
13
13
|
}
|
|
@@ -33,8 +33,9 @@ export class PdfArray extends PdfObject {
|
|
|
33
33
|
new PdfEndArrayToken(),
|
|
34
34
|
];
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
cloneImpl() {
|
|
37
|
+
const cloned = new PdfArray(this.items.map((x) => x.clone()));
|
|
38
|
+
return cloned;
|
|
38
39
|
}
|
|
39
40
|
isModified() {
|
|
40
41
|
return (super.isModified() || this.items.some((item) => item.isModified()));
|
|
@@ -22,7 +22,7 @@ export declare class PdfDictionary<T extends PdfDictionaryEntries = PdfDictionar
|
|
|
22
22
|
entries(): IterableIterator<[string, PdfObject | undefined]>;
|
|
23
23
|
protected tokenize(): PdfToken[];
|
|
24
24
|
copyFrom(other: PdfDictionary<any>): void;
|
|
25
|
-
|
|
25
|
+
cloneImpl(): this;
|
|
26
26
|
isModified(): boolean;
|
|
27
27
|
setImmutable(immutable?: boolean): void;
|
|
28
28
|
}
|
|
@@ -136,12 +136,13 @@ export class PdfDictionary extends PdfObject {
|
|
|
136
136
|
}
|
|
137
137
|
this.modified = true;
|
|
138
138
|
}
|
|
139
|
-
|
|
139
|
+
cloneImpl() {
|
|
140
140
|
const clonedEntries = new Map();
|
|
141
141
|
for (const [key, value] of this.#entries) {
|
|
142
142
|
clonedEntries.set(key.clone(), value ? value.clone() : undefined);
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
const cloned = new PdfDictionary(clonedEntries);
|
|
145
|
+
return cloned;
|
|
145
146
|
}
|
|
146
147
|
isModified() {
|
|
147
148
|
return (super.isModified() ||
|
|
@@ -54,9 +54,10 @@ export class PdfHexadecimal extends PdfObject {
|
|
|
54
54
|
tokenize() {
|
|
55
55
|
return [new PdfHexadecimalToken(this.raw, this._originalBytes)];
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
cloneImpl() {
|
|
58
|
+
const cloned = new PdfHexadecimal(new Uint8Array(this.raw), 'hex', this._originalBytes
|
|
59
59
|
? new Uint8Array(this._originalBytes)
|
|
60
60
|
: undefined);
|
|
61
|
+
return cloned;
|
|
61
62
|
}
|
|
62
63
|
}
|
|
@@ -22,7 +22,7 @@ export declare class PdfIndirectObject<T extends PdfObject = PdfObject> extends
|
|
|
22
22
|
matchesReference(ref?: PdfObjectReference): boolean;
|
|
23
23
|
protected tokenize(): import("../index.js").PdfToken[];
|
|
24
24
|
copyFrom(other: PdfIndirectObject): void;
|
|
25
|
-
|
|
25
|
+
cloneImpl(): this;
|
|
26
26
|
order(): number;
|
|
27
27
|
isModified(): boolean;
|
|
28
28
|
setImmutable(immutable?: boolean): void;
|
|
@@ -94,7 +94,7 @@ export class PdfIndirectObject extends PdfObjectReference {
|
|
|
94
94
|
this.offset = other.offset.clone();
|
|
95
95
|
this.modified = true;
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
cloneImpl() {
|
|
98
98
|
return new PdfIndirectObject({
|
|
99
99
|
objectNumber: this.objectNumber,
|
|
100
100
|
generationNumber: this.generationNumber,
|
|
@@ -4,7 +4,7 @@ export declare class PdfName<T extends string = string> extends PdfObject {
|
|
|
4
4
|
value: T;
|
|
5
5
|
constructor(value: T);
|
|
6
6
|
protected tokenize(): PdfNameToken[];
|
|
7
|
-
|
|
7
|
+
cloneImpl(): this;
|
|
8
8
|
/**
|
|
9
9
|
* Escapes a PDF name according to PDF specification.
|
|
10
10
|
* PDF names can't contain spaces or certain special chars except # for escaping.
|
|
@@ -9,8 +9,9 @@ export class PdfName extends PdfObject {
|
|
|
9
9
|
tokenize() {
|
|
10
10
|
return [new PdfNameToken(PdfName.escapeName(this.value))];
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
cloneImpl() {
|
|
13
|
+
const cloned = new PdfName(this.value);
|
|
14
|
+
return cloned;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* Escapes a PDF name according to PDF specification.
|