pdfdancer-client-typescript 1.0.2 → 1.0.4
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/README.md +3 -4
- package/dist/client-v1.d.ts +15 -6
- package/dist/client-v1.d.ts.map +1 -1
- package/dist/client-v1.js +44 -9
- package/dist/client-v1.js.map +1 -1
- package/dist/exceptions.d.ts +0 -1
- package/dist/exceptions.d.ts.map +1 -1
- package/dist/exceptions.js +0 -1
- package/dist/exceptions.js.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +27 -10
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +44 -12
- package/dist/models.js.map +1 -1
- package/dist/paragraph-builder.d.ts +0 -2
- package/dist/paragraph-builder.d.ts.map +1 -1
- package/dist/paragraph-builder.js +0 -2
- package/dist/paragraph-builder.js.map +1 -1
- package/fixtures/README.md +1 -3
- package/package.json +1 -1
- package/src/__tests__/e2e/acroform.test.ts +92 -0
- package/src/__tests__/e2e/{form.test.ts → form_x_object.test.ts} +4 -4
- package/src/client-v1.ts +60 -9
- package/src/exceptions.ts +0 -1
- package/src/index.ts +2 -3
- package/src/models.ts +56 -12
- package/src/paragraph-builder.ts +1 -3
package/src/models.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Model classes for the PDFDancer TypeScript client.
|
|
3
|
-
* Closely mirrors the Python model classes with TypeScript conventions.
|
|
4
3
|
*/
|
|
5
4
|
|
|
6
|
-
/**
|
|
7
|
-
* Object type enumeration matching the Python ObjectType.
|
|
8
|
-
*/
|
|
9
5
|
export enum ObjectType {
|
|
10
6
|
IMAGE = "IMAGE",
|
|
11
7
|
FORM_X_OBJECT = "FORM_X_OBJECT",
|
|
12
8
|
PATH = "PATH",
|
|
13
9
|
PARAGRAPH = "PARAGRAPH",
|
|
14
10
|
TEXT_LINE = "TEXT_LINE",
|
|
15
|
-
PAGE = "PAGE"
|
|
11
|
+
PAGE = "PAGE",
|
|
12
|
+
FORM_FIELD = "FORM_FIELD",
|
|
13
|
+
TEXT_FIELD = "TEXT_FIELD",
|
|
14
|
+
CHECK_BOX = "CHECK_BOX",
|
|
15
|
+
RADIO_BUTTON = "RADIO_BUTTON"
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -43,7 +43,6 @@ export interface Point {
|
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Represents a bounding rectangle with position and dimensions.
|
|
46
|
-
* Matches the Python BoundingRect class.
|
|
47
46
|
*/
|
|
48
47
|
export class BoundingRect {
|
|
49
48
|
constructor(
|
|
@@ -80,9 +79,10 @@ class PositioningError extends Error {
|
|
|
80
79
|
|
|
81
80
|
/**
|
|
82
81
|
* Represents spatial positioning and location information for PDF objects.
|
|
83
|
-
* Closely mirrors the Python Position class with TypeScript conventions.
|
|
84
82
|
*/
|
|
85
83
|
export class Position {
|
|
84
|
+
public name?: string;
|
|
85
|
+
|
|
86
86
|
constructor(
|
|
87
87
|
public pageIndex?: number,
|
|
88
88
|
public shape?: ShapeType,
|
|
@@ -110,6 +110,15 @@ export class Position {
|
|
|
110
110
|
return Position.atPage(pageIndex).withTextStarts(text);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Creates a position specification for finding objects by name.
|
|
115
|
+
*/
|
|
116
|
+
static byName(name: string): Position {
|
|
117
|
+
const position = new Position();
|
|
118
|
+
position.name = name;
|
|
119
|
+
return position;
|
|
120
|
+
}
|
|
121
|
+
|
|
113
122
|
/**
|
|
114
123
|
* Sets the position to a specific point location.
|
|
115
124
|
*/
|
|
@@ -189,9 +198,11 @@ export class Position {
|
|
|
189
198
|
|
|
190
199
|
/**
|
|
191
200
|
* Lightweight reference to a PDF object providing identity and type information.
|
|
192
|
-
* Mirrors the Python ObjectRef class exactly.
|
|
193
201
|
*/
|
|
194
202
|
export class ObjectRef {
|
|
203
|
+
public name?: string;
|
|
204
|
+
public value?: string | null;
|
|
205
|
+
|
|
195
206
|
constructor(
|
|
196
207
|
public internalId: string,
|
|
197
208
|
public position: Position,
|
|
@@ -224,6 +235,22 @@ export class ObjectRef {
|
|
|
224
235
|
}
|
|
225
236
|
}
|
|
226
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Represents a form field reference with name and value properties.
|
|
240
|
+
* Extends ObjectRef to include form-specific properties.
|
|
241
|
+
*/
|
|
242
|
+
export class FormFieldRef extends ObjectRef {
|
|
243
|
+
constructor(
|
|
244
|
+
internalId: string,
|
|
245
|
+
position: Position,
|
|
246
|
+
type: ObjectType,
|
|
247
|
+
public name?: string,
|
|
248
|
+
public value?: string | null
|
|
249
|
+
) {
|
|
250
|
+
super(internalId, position, type);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
227
254
|
/**
|
|
228
255
|
* Represents an RGB color with optional alpha channel, values from 0-255.
|
|
229
256
|
*/
|
|
@@ -234,7 +261,6 @@ export class Color {
|
|
|
234
261
|
public b: number,
|
|
235
262
|
public a: number = 255 // Alpha channel, default fully opaque
|
|
236
263
|
) {
|
|
237
|
-
// Validation similar to Python client
|
|
238
264
|
for (const component of [this.r, this.g, this.b, this.a]) {
|
|
239
265
|
if (component < 0 || component > 255) {
|
|
240
266
|
throw new Error(`Color component must be between 0 and 255, got ${component}`);
|
|
@@ -259,7 +285,6 @@ export class Font {
|
|
|
259
285
|
|
|
260
286
|
/**
|
|
261
287
|
* Represents an image object in a PDF document.
|
|
262
|
-
* Matches the Python Image class structure.
|
|
263
288
|
*/
|
|
264
289
|
export class Image {
|
|
265
290
|
constructor(
|
|
@@ -282,7 +307,6 @@ export class Image {
|
|
|
282
307
|
|
|
283
308
|
/**
|
|
284
309
|
* Represents a paragraph of text in a PDF document.
|
|
285
|
-
* Structure mirrors the Python Paragraph class.
|
|
286
310
|
*/
|
|
287
311
|
export class Paragraph {
|
|
288
312
|
constructor(
|
|
@@ -477,11 +501,31 @@ export class ModifyTextRequest {
|
|
|
477
501
|
}
|
|
478
502
|
}
|
|
479
503
|
|
|
504
|
+
export class ChangeFormFieldRequest {
|
|
505
|
+
constructor(
|
|
506
|
+
public formFieldRef: FormFieldRef,
|
|
507
|
+
public newValue: string
|
|
508
|
+
) {
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
toDict(): Record<string, any> {
|
|
512
|
+
return {
|
|
513
|
+
ref: {
|
|
514
|
+
internalId: this.formFieldRef.internalId,
|
|
515
|
+
position: positionToDict(this.formFieldRef.position),
|
|
516
|
+
type: this.formFieldRef.type
|
|
517
|
+
},
|
|
518
|
+
value: this.newValue
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
480
523
|
// Helper function to convert Position to dictionary for JSON serialization
|
|
481
524
|
function positionToDict(position: Position): Record<string, any> {
|
|
482
525
|
const result: Record<string, any> = {
|
|
483
526
|
pageIndex: position.pageIndex,
|
|
484
|
-
textStartsWith: position.textStartsWith
|
|
527
|
+
textStartsWith: position.textStartsWith,
|
|
528
|
+
name: position.name
|
|
485
529
|
};
|
|
486
530
|
|
|
487
531
|
if (position.shape) {
|
package/src/paragraph-builder.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* ParagraphBuilder for the PDFDancer TypeScript client.
|
|
3
|
-
* Closely mirrors the Python ParagraphBuilder class with TypeScript conventions.
|
|
4
3
|
*/
|
|
5
4
|
|
|
6
5
|
import { ValidationException } from './exceptions';
|
|
@@ -9,7 +8,6 @@ import type { ClientV1 } from './client-v1';
|
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Builder class for constructing Paragraph objects with fluent interface.
|
|
12
|
-
* Mirrors the Python ParagraphBuilder class exactly.
|
|
13
11
|
*/
|
|
14
12
|
export class ParagraphBuilder {
|
|
15
13
|
private _paragraph: Paragraph;
|
|
@@ -173,4 +171,4 @@ export class ParagraphBuilder {
|
|
|
173
171
|
|
|
174
172
|
return lines;
|
|
175
173
|
}
|
|
176
|
-
}
|
|
174
|
+
}
|