pdf-lite 1.3.2 → 1.4.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/PdfAcroForm.d.ts +63 -0
- package/dist/acroform/PdfAcroForm.js +279 -0
- package/dist/acroform/PdfFontEncodingCache.d.ts +16 -0
- package/dist/acroform/PdfFontEncodingCache.js +75 -0
- package/dist/acroform/acroform.d.ts +7 -449
- package/dist/acroform/acroform.js +5 -1612
- package/dist/acroform/appearance/PdfAppearanceStream.d.ts +15 -0
- package/dist/acroform/appearance/PdfAppearanceStream.js +32 -0
- package/dist/acroform/appearance/PdfButtonAppearanceStream.d.ts +12 -0
- package/dist/acroform/appearance/PdfButtonAppearanceStream.js +54 -0
- package/dist/acroform/appearance/PdfChoiceAppearanceStream.d.ts +15 -0
- package/dist/acroform/appearance/PdfChoiceAppearanceStream.js +48 -0
- package/dist/acroform/appearance/PdfTextAppearanceStream.d.ts +17 -0
- package/dist/acroform/appearance/PdfTextAppearanceStream.js +75 -0
- package/dist/acroform/appearance/index.d.ts +4 -0
- package/dist/acroform/appearance/index.js +4 -0
- package/dist/acroform/fields/PdfButtonFormField.d.ts +9 -0
- package/dist/acroform/fields/PdfButtonFormField.js +35 -0
- package/dist/acroform/fields/PdfChoiceFormField.d.ts +9 -0
- package/dist/acroform/fields/PdfChoiceFormField.js +46 -0
- package/dist/acroform/fields/PdfDefaultAppearance.d.ts +23 -0
- package/dist/acroform/fields/PdfDefaultAppearance.js +68 -0
- package/dist/acroform/fields/PdfFormField.d.ts +119 -0
- package/dist/acroform/fields/PdfFormField.js +499 -0
- package/dist/acroform/fields/PdfFormFieldFlags.d.ts +46 -0
- package/dist/acroform/fields/PdfFormFieldFlags.js +128 -0
- package/dist/acroform/fields/PdfSignatureFormField.d.ts +7 -0
- package/dist/acroform/fields/PdfSignatureFormField.js +12 -0
- package/dist/acroform/fields/PdfTextFormField.d.ts +10 -0
- package/dist/acroform/fields/PdfTextFormField.js +52 -0
- package/dist/acroform/fields/index.d.ts +8 -0
- package/dist/acroform/fields/index.js +8 -0
- package/dist/acroform/fields/types.d.ts +21 -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 +7 -0
- package/dist/acroform/manager.js +12 -0
- package/dist/acroform/xfa/PdfXfaData.d.ts +20 -0
- package/dist/acroform/xfa/PdfXfaData.js +68 -0
- package/dist/acroform/xfa/PdfXfaForm.d.ts +12 -0
- package/dist/acroform/xfa/PdfXfaForm.js +64 -0
- package/dist/acroform/xfa/index.d.ts +3 -0
- package/dist/acroform/xfa/index.js +2 -0
- package/dist/annotations/PdfAnnotation.d.ts +40 -0
- package/dist/annotations/PdfAnnotation.js +105 -0
- package/dist/annotations/PdfAnnotationFlags.d.ts +25 -0
- package/dist/annotations/PdfAnnotationFlags.js +94 -0
- package/dist/annotations/PdfAnnotationWriter.d.ts +20 -0
- package/dist/annotations/PdfAnnotationWriter.js +76 -0
- package/dist/annotations/PdfWidgetAnnotation.d.ts +15 -0
- package/dist/annotations/PdfWidgetAnnotation.js +37 -0
- package/dist/annotations/index.d.ts +4 -0
- package/dist/annotations/index.js +4 -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 +3 -3
- package/dist/core/objects/pdf-stream.js +39 -14
- 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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/pdf/pdf-document.d.ts +14 -11
- package/dist/pdf/pdf-document.js +36 -26
- 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/package.json +1 -1
- 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
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { PdfFormField } from './PdfFormField.js';
|
|
2
|
+
import { PdfDefaultAppearance } from './PdfDefaultAppearance.js';
|
|
3
|
+
import { PdfTextAppearanceStream } from '../appearance/PdfTextAppearanceStream.js';
|
|
4
|
+
import { PdfDictionary } from '../../core/objects/pdf-dictionary.js';
|
|
5
|
+
/**
|
|
6
|
+
* Text form field subtype.
|
|
7
|
+
*/
|
|
8
|
+
export class PdfTextFormField extends PdfFormField {
|
|
9
|
+
static {
|
|
10
|
+
PdfFormField.registerFieldType('Tx', PdfTextFormField, {
|
|
11
|
+
fallback: true,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
generateAppearance(options) {
|
|
15
|
+
const rect = this.rect;
|
|
16
|
+
if (!rect || rect.length !== 4)
|
|
17
|
+
return false;
|
|
18
|
+
const da = this.defaultAppearance;
|
|
19
|
+
if (!da)
|
|
20
|
+
return false;
|
|
21
|
+
const parsed = PdfDefaultAppearance.parse(da);
|
|
22
|
+
if (!parsed)
|
|
23
|
+
return false;
|
|
24
|
+
let fontResources;
|
|
25
|
+
const drFontValue = this.form?.defaultResources?.get('Font');
|
|
26
|
+
const drFonts = drFontValue instanceof PdfDictionary ? drFontValue : undefined;
|
|
27
|
+
if (drFonts) {
|
|
28
|
+
fontResources = new PdfDictionary();
|
|
29
|
+
fontResources.set('Font', drFonts);
|
|
30
|
+
}
|
|
31
|
+
this._appearanceStream = new PdfTextAppearanceStream({
|
|
32
|
+
rect: rect,
|
|
33
|
+
value: this.value,
|
|
34
|
+
da: parsed,
|
|
35
|
+
multiline: this.multiline,
|
|
36
|
+
comb: this.comb,
|
|
37
|
+
maxLen: this.maxLen,
|
|
38
|
+
fontResources,
|
|
39
|
+
});
|
|
40
|
+
if (options?.makeReadOnly) {
|
|
41
|
+
this.readOnly = true;
|
|
42
|
+
if (!this.print)
|
|
43
|
+
this.print = true;
|
|
44
|
+
this.noZoom = true;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
if (!this.print)
|
|
48
|
+
this.print = true;
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { PdfFormField, PdfAcroFormField } from './PdfFormField.js';
|
|
2
|
+
export { PdfFormFieldFlags } from './PdfFormFieldFlags.js';
|
|
3
|
+
export { PdfDefaultAppearance } from './PdfDefaultAppearance.js';
|
|
4
|
+
export { PdfTextFormField } from './PdfTextFormField.js';
|
|
5
|
+
export { PdfButtonFormField } from './PdfButtonFormField.js';
|
|
6
|
+
export { PdfChoiceFormField } from './PdfChoiceFormField.js';
|
|
7
|
+
export { PdfSignatureFormField } from './PdfSignatureFormField.js';
|
|
8
|
+
export { PdfFieldType, type FormContext } from './types.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { PdfFormField, PdfAcroFormField } from './PdfFormField.js';
|
|
2
|
+
export { PdfFormFieldFlags } from './PdfFormFieldFlags.js';
|
|
3
|
+
export { PdfDefaultAppearance } from './PdfDefaultAppearance.js';
|
|
4
|
+
export { PdfTextFormField } from './PdfTextFormField.js';
|
|
5
|
+
export { PdfButtonFormField } from './PdfButtonFormField.js';
|
|
6
|
+
export { PdfChoiceFormField } from './PdfChoiceFormField.js';
|
|
7
|
+
export { PdfSignatureFormField } from './PdfSignatureFormField.js';
|
|
8
|
+
export { PdfFieldType } from './types.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PdfDefaultResourcesDictionary } from '../acroform.js';
|
|
2
|
+
/**
|
|
3
|
+
* Field types for AcroForm fields
|
|
4
|
+
*/
|
|
5
|
+
export declare const PdfFieldType: {
|
|
6
|
+
readonly Text: "Tx";
|
|
7
|
+
readonly Button: "Btn";
|
|
8
|
+
readonly Choice: "Ch";
|
|
9
|
+
readonly Signature: "Sig";
|
|
10
|
+
};
|
|
11
|
+
export type PdfFieldType = keyof typeof PdfFieldType;
|
|
12
|
+
/**
|
|
13
|
+
* Interface that PdfAcroForm implements, used by PdfFormField to avoid circular imports.
|
|
14
|
+
* Uses generic field type to avoid circular dependency.
|
|
15
|
+
*/
|
|
16
|
+
export interface FormContext<TField = any> {
|
|
17
|
+
defaultResources: PdfDefaultResourcesDictionary | null;
|
|
18
|
+
defaultAppearance: string | null;
|
|
19
|
+
fontEncodingMaps: Map<string, Map<number, string>>;
|
|
20
|
+
fields: TField[];
|
|
21
|
+
}
|
package/dist/acroform/index.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export * from './manager.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './PdfAcroForm.js';
|
|
3
|
+
export * from './fields/index.js';
|
|
4
|
+
export * from './appearance/index.js';
|
|
5
|
+
export * from './xfa/index.js';
|
|
6
|
+
export { PdfFontEncodingCache } from './PdfFontEncodingCache.js';
|
package/dist/acroform/index.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export * from './manager.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './PdfAcroForm.js';
|
|
3
|
+
export * from './fields/index.js';
|
|
4
|
+
export * from './appearance/index.js';
|
|
5
|
+
export * from './xfa/index.js';
|
|
6
|
+
export { PdfFontEncodingCache } from './PdfFontEncodingCache.js';
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { PdfDocument } from '../pdf/pdf-document.js';
|
|
2
2
|
import { PdfAcroForm } from './acroform.js';
|
|
3
|
+
import { PdfXfaForm } from './xfa/PdfXfaForm.js';
|
|
3
4
|
/**
|
|
4
5
|
* Manages AcroForm fields in PDF documents.
|
|
5
6
|
* Provides methods to read and write form field values.
|
|
6
7
|
*/
|
|
7
8
|
export declare class PdfAcroFormManager {
|
|
8
9
|
private document;
|
|
10
|
+
private _xfa;
|
|
9
11
|
constructor(document: PdfDocument);
|
|
12
|
+
/**
|
|
13
|
+
* Gets the XFA form wrapper, loading it lazily on first access.
|
|
14
|
+
* @returns The PdfXfaForm or null if no XFA forms exist
|
|
15
|
+
*/
|
|
16
|
+
getXfa(): Promise<PdfXfaForm | null>;
|
|
10
17
|
/**
|
|
11
18
|
* Checks if the document contains AcroForm fields.
|
|
12
19
|
* @returns True if the document has AcroForm fields, false otherwise
|
package/dist/acroform/manager.js
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
import { PdfAcroForm } from './acroform.js';
|
|
2
|
+
import { PdfXfaForm } from './xfa/PdfXfaForm.js';
|
|
2
3
|
/**
|
|
3
4
|
* Manages AcroForm fields in PDF documents.
|
|
4
5
|
* Provides methods to read and write form field values.
|
|
5
6
|
*/
|
|
6
7
|
export class PdfAcroFormManager {
|
|
7
8
|
document;
|
|
9
|
+
_xfa = undefined;
|
|
8
10
|
constructor(document) {
|
|
9
11
|
this.document = document;
|
|
10
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Gets the XFA form wrapper, loading it lazily on first access.
|
|
15
|
+
* @returns The PdfXfaForm or null if no XFA forms exist
|
|
16
|
+
*/
|
|
17
|
+
async getXfa() {
|
|
18
|
+
if (this._xfa === undefined) {
|
|
19
|
+
this._xfa = await PdfXfaForm.fromDocument(this.document);
|
|
20
|
+
}
|
|
21
|
+
return this._xfa;
|
|
22
|
+
}
|
|
11
23
|
/**
|
|
12
24
|
* Checks if the document contains AcroForm fields.
|
|
13
25
|
* @returns True if the document has AcroForm fields, false otherwise
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PdfIndirectObject } from '../../core/objects/pdf-indirect-object.js';
|
|
2
|
+
import { PdfStream } from '../../core/objects/pdf-stream.js';
|
|
3
|
+
export interface XfaFieldData {
|
|
4
|
+
name: string;
|
|
5
|
+
value: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Wraps an XFA datasets stream as a typed PDF indirect object.
|
|
9
|
+
* Provides methods to read/write XML and update individual field values.
|
|
10
|
+
*/
|
|
11
|
+
export declare class PdfXfaData extends PdfIndirectObject<PdfStream> {
|
|
12
|
+
constructor(stream: PdfIndirectObject<PdfStream>);
|
|
13
|
+
readXml(): string;
|
|
14
|
+
writeXml(xml: string): void;
|
|
15
|
+
updateField(name: string, value: string): void;
|
|
16
|
+
updateFields(fields: XfaFieldData[]): void;
|
|
17
|
+
getFieldValue(name: string): string | null;
|
|
18
|
+
private static updateFieldValue;
|
|
19
|
+
private static escapeRegex;
|
|
20
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { PdfIndirectObject } from '../../core/objects/pdf-indirect-object.js';
|
|
2
|
+
import { PdfStream } from '../../core/objects/pdf-stream.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wraps an XFA datasets stream as a typed PDF indirect object.
|
|
5
|
+
* Provides methods to read/write XML and update individual field values.
|
|
6
|
+
*/
|
|
7
|
+
export class PdfXfaData extends PdfIndirectObject {
|
|
8
|
+
constructor(stream) {
|
|
9
|
+
super(stream);
|
|
10
|
+
}
|
|
11
|
+
readXml() {
|
|
12
|
+
const decompressed = this.content.decode();
|
|
13
|
+
return new TextDecoder().decode(decompressed);
|
|
14
|
+
}
|
|
15
|
+
writeXml(xml) {
|
|
16
|
+
this.content = PdfStream.fromString(xml);
|
|
17
|
+
}
|
|
18
|
+
updateField(name, value) {
|
|
19
|
+
let xml = this.readXml();
|
|
20
|
+
xml = PdfXfaData.updateFieldValue(xml, name, value);
|
|
21
|
+
this.writeXml(xml);
|
|
22
|
+
}
|
|
23
|
+
updateFields(fields) {
|
|
24
|
+
if (fields.length === 0)
|
|
25
|
+
return;
|
|
26
|
+
let xml = this.readXml();
|
|
27
|
+
for (const { name, value } of fields) {
|
|
28
|
+
xml = PdfXfaData.updateFieldValue(xml, name, value);
|
|
29
|
+
}
|
|
30
|
+
this.writeXml(xml);
|
|
31
|
+
}
|
|
32
|
+
getFieldValue(name) {
|
|
33
|
+
const xml = this.readXml();
|
|
34
|
+
const segments = name.split('.');
|
|
35
|
+
const leafSegment = segments[segments.length - 1];
|
|
36
|
+
const leafName = leafSegment.replace(/\[\d+\]$/, '');
|
|
37
|
+
if (leafName.startsWith('#'))
|
|
38
|
+
return null;
|
|
39
|
+
const contentRegex = new RegExp(`<${PdfXfaData.escapeRegex(leafName)}(?:\\s[^>]*)?>([\\s\\S]*?)</${PdfXfaData.escapeRegex(leafName)}\\s*>`);
|
|
40
|
+
const match = xml.match(contentRegex);
|
|
41
|
+
return match ? match[1] : null;
|
|
42
|
+
}
|
|
43
|
+
static updateFieldValue(xml, fieldName, value) {
|
|
44
|
+
const segments = fieldName.split('.');
|
|
45
|
+
const leafSegment = segments[segments.length - 1];
|
|
46
|
+
const leafName = leafSegment.replace(/\[\d+\]$/, '');
|
|
47
|
+
if (leafName.startsWith('#'))
|
|
48
|
+
return xml;
|
|
49
|
+
const escapedValue = value
|
|
50
|
+
.replace(/&/g, '&')
|
|
51
|
+
.replace(/</g, '<')
|
|
52
|
+
.replace(/>/g, '>')
|
|
53
|
+
.replace(/"/g, '"')
|
|
54
|
+
.replace(/'/g, ''');
|
|
55
|
+
const selfClosingRegex = new RegExp(`<${PdfXfaData.escapeRegex(leafName)}\\s*/>`);
|
|
56
|
+
if (selfClosingRegex.test(xml)) {
|
|
57
|
+
return xml.replace(selfClosingRegex, `<${leafName}>${escapedValue}</${leafName}>`);
|
|
58
|
+
}
|
|
59
|
+
const contentRegex = new RegExp(`(<${PdfXfaData.escapeRegex(leafName)}(?:\\s[^>]*)?>)[\\s\\S]*?(</${PdfXfaData.escapeRegex(leafName)}\\s*>)`);
|
|
60
|
+
if (contentRegex.test(xml)) {
|
|
61
|
+
return xml.replace(contentRegex, `$1${escapedValue}$2`);
|
|
62
|
+
}
|
|
63
|
+
return xml;
|
|
64
|
+
}
|
|
65
|
+
static escapeRegex(str) {
|
|
66
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PdfDocument } from '../../pdf/pdf-document.js';
|
|
2
|
+
import { PdfArray } from '../../core/objects/pdf-array.js';
|
|
3
|
+
import { PdfXfaData } from './PdfXfaData.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
|
+
write(document: PdfDocument): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
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 './PdfXfaData.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({
|
|
21
|
+
objectNumber: acroFormRef.objectNumber,
|
|
22
|
+
generationNumber: acroFormRef.generationNumber,
|
|
23
|
+
});
|
|
24
|
+
if (!acroFormObject)
|
|
25
|
+
return null;
|
|
26
|
+
acroFormDict = acroFormObject.content.as(PdfDictionary);
|
|
27
|
+
}
|
|
28
|
+
else if (acroFormRef instanceof PdfDictionary) {
|
|
29
|
+
acroFormDict = acroFormRef;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const xfaArray = acroFormDict.get('XFA');
|
|
35
|
+
if (!(xfaArray instanceof PdfArray))
|
|
36
|
+
return null;
|
|
37
|
+
const form = new PdfXfaForm(xfaArray.items.slice());
|
|
38
|
+
// Find the datasets reference in the name/ref pairs
|
|
39
|
+
const items = xfaArray.items;
|
|
40
|
+
for (let i = 0; i < items.length - 1; i += 2) {
|
|
41
|
+
const name = items[i];
|
|
42
|
+
const ref = items[i + 1];
|
|
43
|
+
if (name instanceof PdfString &&
|
|
44
|
+
name.value === 'datasets' &&
|
|
45
|
+
ref instanceof PdfObjectReference) {
|
|
46
|
+
const datasetObject = (await document.readObject({
|
|
47
|
+
objectNumber: ref.objectNumber,
|
|
48
|
+
generationNumber: ref.generationNumber,
|
|
49
|
+
allowUnindexed: true,
|
|
50
|
+
}))?.as((PdfIndirectObject));
|
|
51
|
+
if (datasetObject) {
|
|
52
|
+
form.datasets = new PdfXfaData(datasetObject);
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return form;
|
|
58
|
+
}
|
|
59
|
+
write(document) {
|
|
60
|
+
if (this.datasets?.isModified()) {
|
|
61
|
+
document.add(this.datasets);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
export type PdfAppearanceStreamDictionary = PdfDictionary<{
|
|
5
|
+
N: PdfObjectReference | PdfDictionary;
|
|
6
|
+
R?: PdfObjectReference | PdfDictionary;
|
|
7
|
+
D?: PdfObjectReference | PdfDictionary;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* Base class for all PDF annotations.
|
|
11
|
+
* Owns: Rect, annotation flags (F), AP (appearance streams), P (page reference).
|
|
12
|
+
*/
|
|
13
|
+
export declare class PdfAnnotation extends PdfIndirectObject<PdfDictionary> {
|
|
14
|
+
private _annotationFlags;
|
|
15
|
+
constructor(options?: {
|
|
16
|
+
other?: PdfIndirectObject;
|
|
17
|
+
});
|
|
18
|
+
get rect(): number[] | null;
|
|
19
|
+
set rect(rect: number[] | null);
|
|
20
|
+
get annotationFlags(): number;
|
|
21
|
+
set annotationFlags(flags: number);
|
|
22
|
+
get invisible(): boolean;
|
|
23
|
+
set invisible(value: boolean);
|
|
24
|
+
get hidden(): boolean;
|
|
25
|
+
set hidden(value: boolean);
|
|
26
|
+
get print(): boolean;
|
|
27
|
+
set print(value: boolean);
|
|
28
|
+
get noZoom(): boolean;
|
|
29
|
+
set noZoom(value: boolean);
|
|
30
|
+
get noRotate(): boolean;
|
|
31
|
+
set noRotate(value: boolean);
|
|
32
|
+
get noView(): boolean;
|
|
33
|
+
set noView(value: boolean);
|
|
34
|
+
get locked(): boolean;
|
|
35
|
+
set locked(value: boolean);
|
|
36
|
+
get appearanceStreamDict(): PdfAppearanceStreamDictionary | null;
|
|
37
|
+
set appearanceStreamDict(dict: PdfAppearanceStreamDictionary | null);
|
|
38
|
+
get parentRef(): PdfObjectReference | null;
|
|
39
|
+
set parentRef(ref: PdfObjectReference | null);
|
|
40
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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 './PdfAnnotationFlags.js';
|
|
7
|
+
/**
|
|
8
|
+
* Base class for all PDF annotations.
|
|
9
|
+
* Owns: Rect, annotation flags (F), AP (appearance streams), P (page reference).
|
|
10
|
+
*/
|
|
11
|
+
export class PdfAnnotation extends PdfIndirectObject {
|
|
12
|
+
_annotationFlags;
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super(options?.other ??
|
|
15
|
+
new PdfIndirectObject({ content: new PdfDictionary() }));
|
|
16
|
+
this._annotationFlags = new PdfAnnotationFlags(this.content);
|
|
17
|
+
}
|
|
18
|
+
get rect() {
|
|
19
|
+
const rectArray = this.content.get('Rect')?.as((PdfArray));
|
|
20
|
+
if (!rectArray)
|
|
21
|
+
return null;
|
|
22
|
+
return rectArray.items.map((num) => num.value);
|
|
23
|
+
}
|
|
24
|
+
set rect(rect) {
|
|
25
|
+
if (rect === null) {
|
|
26
|
+
this.content.delete('Rect');
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const rectArray = new PdfArray(rect.map((num) => new PdfNumber(num)));
|
|
30
|
+
this.content.set('Rect', rectArray);
|
|
31
|
+
}
|
|
32
|
+
get annotationFlags() {
|
|
33
|
+
return this._annotationFlags.annotationFlags;
|
|
34
|
+
}
|
|
35
|
+
set annotationFlags(flags) {
|
|
36
|
+
this._annotationFlags.annotationFlags = flags;
|
|
37
|
+
}
|
|
38
|
+
get invisible() {
|
|
39
|
+
return this._annotationFlags.invisible;
|
|
40
|
+
}
|
|
41
|
+
set invisible(value) {
|
|
42
|
+
this._annotationFlags.invisible = value;
|
|
43
|
+
}
|
|
44
|
+
get hidden() {
|
|
45
|
+
return this._annotationFlags.hidden;
|
|
46
|
+
}
|
|
47
|
+
set hidden(value) {
|
|
48
|
+
this._annotationFlags.hidden = value;
|
|
49
|
+
}
|
|
50
|
+
get print() {
|
|
51
|
+
return this._annotationFlags.print;
|
|
52
|
+
}
|
|
53
|
+
set print(value) {
|
|
54
|
+
this._annotationFlags.print = value;
|
|
55
|
+
}
|
|
56
|
+
get noZoom() {
|
|
57
|
+
return this._annotationFlags.noZoom;
|
|
58
|
+
}
|
|
59
|
+
set noZoom(value) {
|
|
60
|
+
this._annotationFlags.noZoom = value;
|
|
61
|
+
}
|
|
62
|
+
get noRotate() {
|
|
63
|
+
return this._annotationFlags.noRotate;
|
|
64
|
+
}
|
|
65
|
+
set noRotate(value) {
|
|
66
|
+
this._annotationFlags.noRotate = value;
|
|
67
|
+
}
|
|
68
|
+
get noView() {
|
|
69
|
+
return this._annotationFlags.noView;
|
|
70
|
+
}
|
|
71
|
+
set noView(value) {
|
|
72
|
+
this._annotationFlags.noView = value;
|
|
73
|
+
}
|
|
74
|
+
get locked() {
|
|
75
|
+
return this._annotationFlags.locked;
|
|
76
|
+
}
|
|
77
|
+
set locked(value) {
|
|
78
|
+
this._annotationFlags.locked = value;
|
|
79
|
+
}
|
|
80
|
+
get appearanceStreamDict() {
|
|
81
|
+
const apDict = this.content.get('AP')?.as(PdfDictionary);
|
|
82
|
+
if (!apDict)
|
|
83
|
+
return null;
|
|
84
|
+
return apDict;
|
|
85
|
+
}
|
|
86
|
+
set appearanceStreamDict(dict) {
|
|
87
|
+
if (dict === null) {
|
|
88
|
+
this.content.delete('AP');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
this.content.set('AP', dict);
|
|
92
|
+
}
|
|
93
|
+
get parentRef() {
|
|
94
|
+
const ref = this.content.get('P')?.as(PdfObjectReference);
|
|
95
|
+
return ref ?? null;
|
|
96
|
+
}
|
|
97
|
+
set parentRef(ref) {
|
|
98
|
+
if (ref === null) {
|
|
99
|
+
this.content.delete('P');
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.content.set('P', ref);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { PdfDictionary } from '../core/objects/pdf-dictionary.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 {
|
|
7
|
+
readonly dict: PdfDictionary;
|
|
8
|
+
constructor(dict: PdfDictionary);
|
|
9
|
+
get annotationFlags(): number;
|
|
10
|
+
set annotationFlags(flags: number);
|
|
11
|
+
get invisible(): boolean;
|
|
12
|
+
set invisible(value: boolean);
|
|
13
|
+
get hidden(): boolean;
|
|
14
|
+
set hidden(value: boolean);
|
|
15
|
+
get print(): boolean;
|
|
16
|
+
set print(value: boolean);
|
|
17
|
+
get noZoom(): boolean;
|
|
18
|
+
set noZoom(value: boolean);
|
|
19
|
+
get noRotate(): boolean;
|
|
20
|
+
set noRotate(value: boolean);
|
|
21
|
+
get noView(): boolean;
|
|
22
|
+
set noView(value: boolean);
|
|
23
|
+
get locked(): boolean;
|
|
24
|
+
set locked(value: boolean);
|
|
25
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
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 {
|
|
7
|
+
dict;
|
|
8
|
+
constructor(dict) {
|
|
9
|
+
this.dict = dict;
|
|
10
|
+
}
|
|
11
|
+
get annotationFlags() {
|
|
12
|
+
return this.dict.get('F')?.as(PdfNumber)?.value ?? 0;
|
|
13
|
+
}
|
|
14
|
+
set annotationFlags(flags) {
|
|
15
|
+
this.dict.set('F', new PdfNumber(flags));
|
|
16
|
+
}
|
|
17
|
+
get invisible() {
|
|
18
|
+
return (this.annotationFlags & 1) !== 0;
|
|
19
|
+
}
|
|
20
|
+
set invisible(value) {
|
|
21
|
+
if (value) {
|
|
22
|
+
this.annotationFlags = this.annotationFlags | 1;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.annotationFlags = this.annotationFlags & ~1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
get hidden() {
|
|
29
|
+
return (this.annotationFlags & 2) !== 0;
|
|
30
|
+
}
|
|
31
|
+
set hidden(value) {
|
|
32
|
+
if (value) {
|
|
33
|
+
this.annotationFlags = this.annotationFlags | 2;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.annotationFlags = this.annotationFlags & ~2;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
get print() {
|
|
40
|
+
return (this.annotationFlags & 4) !== 0;
|
|
41
|
+
}
|
|
42
|
+
set print(value) {
|
|
43
|
+
if (value) {
|
|
44
|
+
this.annotationFlags = this.annotationFlags | 4;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
this.annotationFlags = this.annotationFlags & ~4;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
get noZoom() {
|
|
51
|
+
return (this.annotationFlags & 8) !== 0;
|
|
52
|
+
}
|
|
53
|
+
set noZoom(value) {
|
|
54
|
+
if (value) {
|
|
55
|
+
this.annotationFlags = this.annotationFlags | 8;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.annotationFlags = this.annotationFlags & ~8;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
get noRotate() {
|
|
62
|
+
return (this.annotationFlags & 16) !== 0;
|
|
63
|
+
}
|
|
64
|
+
set noRotate(value) {
|
|
65
|
+
if (value) {
|
|
66
|
+
this.annotationFlags = this.annotationFlags | 16;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.annotationFlags = this.annotationFlags & ~16;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
get noView() {
|
|
73
|
+
return (this.annotationFlags & 32) !== 0;
|
|
74
|
+
}
|
|
75
|
+
set noView(value) {
|
|
76
|
+
if (value) {
|
|
77
|
+
this.annotationFlags = this.annotationFlags | 32;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
this.annotationFlags = this.annotationFlags & ~32;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
get locked() {
|
|
84
|
+
return (this.annotationFlags & 128) !== 0;
|
|
85
|
+
}
|
|
86
|
+
set locked(value) {
|
|
87
|
+
if (value) {
|
|
88
|
+
this.annotationFlags = this.annotationFlags | 128;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
this.annotationFlags = this.annotationFlags & ~128;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -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
|
+
}
|