pdfdancer-client-typescript 1.0.1 → 1.0.2

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 (38) hide show
  1. package/.github/workflows/ci.yml +37 -0
  2. package/README.md +60 -64
  3. package/dist/__tests__/assertions.d.ts +2 -0
  4. package/dist/__tests__/assertions.d.ts.map +1 -0
  5. package/dist/__tests__/assertions.js +11 -0
  6. package/dist/__tests__/assertions.js.map +1 -0
  7. package/dist/client-v1.d.ts +3 -24
  8. package/dist/client-v1.d.ts.map +1 -1
  9. package/dist/client-v1.js +6 -23
  10. package/dist/client-v1.js.map +1 -1
  11. package/dist/exceptions.d.ts +0 -3
  12. package/dist/exceptions.d.ts.map +1 -1
  13. package/dist/exceptions.js +0 -3
  14. package/dist/exceptions.js.map +1 -1
  15. package/dist/models.d.ts +7 -8
  16. package/dist/models.d.ts.map +1 -1
  17. package/dist/models.js +28 -13
  18. package/dist/models.js.map +1 -1
  19. package/dist/paragraph-builder.d.ts +0 -8
  20. package/dist/paragraph-builder.d.ts.map +1 -1
  21. package/dist/paragraph-builder.js +0 -8
  22. package/dist/paragraph-builder.js.map +1 -1
  23. package/example.ts +6 -10
  24. package/fixtures/form-xobject-example.pdf +0 -0
  25. package/jest.config.js +25 -24
  26. package/package.json +1 -1
  27. package/src/__tests__/assertions.ts +12 -0
  28. package/src/__tests__/client-v1.test.ts +6 -6
  29. package/src/__tests__/e2e/form.test.ts +42 -44
  30. package/src/__tests__/e2e/image.test.ts +97 -101
  31. package/src/__tests__/e2e/line.test.ts +115 -127
  32. package/src/__tests__/e2e/page.test.ts +3 -6
  33. package/src/__tests__/e2e/paragraph.test.ts +187 -204
  34. package/src/__tests__/e2e/path.test.ts +12 -16
  35. package/src/client-v1.ts +575 -591
  36. package/src/exceptions.ts +27 -30
  37. package/src/models.ts +382 -355
  38. package/src/paragraph-builder.ts +0 -8
@@ -0,0 +1,37 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ main, staging, develop, development, dev ]
6
+ pull_request:
7
+ branches: [ main, staging, develop, development, dev ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ node-version: [ 18.x, 20.x, 22.x, 24.x ]
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - name: Use Node.js ${{ matrix.node-version }}
21
+ uses: actions/setup-node@v4
22
+ with:
23
+ node-version: ${{ matrix.node-version }}
24
+ cache: 'npm'
25
+
26
+ - name: Install dependencies
27
+ run: npm ci
28
+
29
+ - name: Run linter
30
+ run: npm run lint
31
+
32
+ - name: Build
33
+ run: npm run build
34
+
35
+ - name: Run tests
36
+ run: npm run test:unit
37
+
package/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # PDFDancer TypeScript Client
2
2
 
3
- A TypeScript client library for the PDFDancer PDF manipulation API. This client provides a clean, TypeScript interface for PDF operations that closely mirrors the Python client structure and functionality.
3
+ A TypeScript client library for the PDFDancer PDF manipulation API. This client provides a clean, TypeScript interface
4
+ for PDF operations that closely mirrors the Python client structure and functionality.
4
5
 
5
6
  ## Features
6
7
 
@@ -21,35 +22,32 @@ npm install pdfdancer-client-typescript
21
22
  ## Basic Usage
22
23
 
23
24
  ```typescript
24
- import { ClientV1, Position, Color, Font } from 'pdfdancer-client-typescript';
25
+ import {ClientV1, Position, Color, Font} from 'pdfdancer-client-typescript';
25
26
 
26
27
  async function example() {
27
- // Load PDF data (from file upload, fetch, etc.)
28
- const pdfData = new Uint8Array(/* your PDF data */);
28
+ // Load PDF data (from file upload, fetch, etc.)
29
+ const pdfData = new Uint8Array(/* your PDF data */);
29
30
 
30
- // Create client with authentication token
31
- const client = new ClientV1('your-auth-token', pdfData);
31
+ // Create client with authentication token
32
+ const client = await ClientV1.create('your-auth-token', pdfData, undefined, 30000);
32
33
 
33
- // Initialize session (required before using the client)
34
- await client.init();
34
+ // Find all paragraphs on page 1
35
+ const paragraphs = await client.findParagraphs(Position.atPage(1));
35
36
 
36
- // Find all paragraphs on page 1
37
- const paragraphs = await client.findParagraphs(Position.fromPageIndex(1));
37
+ // Add a new paragraph
38
+ const newParagraph = client.paragraphBuilder()
39
+ .fromString('Hello, PDFDancer!', new Color(255, 0, 0))
40
+ .withFont(new Font('Arial', 12))
41
+ .withPosition(Position.atPageCoordinates(1, 100, 200))
42
+ .build();
38
43
 
39
- // Add a new paragraph
40
- const newParagraph = client.paragraphBuilder()
41
- .fromString('Hello, PDFDancer!', new Color(255, 0, 0))
42
- .withFont(new Font('Arial', 12))
43
- .withPosition(Position.onPageCoordinates(1, 100, 200))
44
- .build();
45
-
46
- await client.addParagraph(newParagraph);
44
+ await client.addParagraph(newParagraph);
47
45
 
48
- // Get the modified PDF
49
- const modifiedPdf = await client.getPdfFile();
46
+ // Get the modified PDF
47
+ const modifiedPdf = await client.getPdfFile();
50
48
 
51
- // Save PDF (browser environment)
52
- await client.savePdf('modified-document.pdf');
49
+ // Save PDF (browser environment)
50
+ await client.savePdf('modified-document.pdf');
53
51
  }
54
52
  ```
55
53
 
@@ -58,14 +56,12 @@ async function example() {
58
56
  ### Client Initialization
59
57
 
60
58
  ```typescript
61
- const client = new ClientV1(
62
- token, // Authentication token
63
- pdfData, // PDF data as Uint8Array, File, or ArrayBuffer
64
- baseUrl, // Optional: API server URL (default: http://localhost:8080)
65
- readTimeout // Optional: Request timeout in ms (default: 30000)
59
+ const client = await ClientV1.create(
60
+ token, // Authentication token
61
+ pdfData, // PDF data as Uint8Array, File, or ArrayBuffer
62
+ baseUrl, // Optional: API server URL (default: http://localhost:8080)
63
+ readTimeout // Optional: Request timeout in ms (default: 30000)
66
64
  );
67
-
68
- await client.init(); // Required before using the client
69
65
  ```
70
66
 
71
67
  ### Search Operations
@@ -90,10 +86,10 @@ const page = await client.getPage(1); // 1-based index
90
86
 
91
87
  ```typescript
92
88
  // Page-based position
93
- const pagePosition = Position.fromPageIndex(1);
89
+ const pagePosition = Position.atPage(1);
94
90
 
95
91
  // Coordinate-based position
96
- const coordPosition = Position.onPageCoordinates(1, 100, 200);
92
+ const coordPosition = Position.atPageCoordinates(1, 100, 200);
97
93
 
98
94
  // Position with movement
99
95
  const movedPosition = coordPosition.copy().moveX(50).moveY(30);
@@ -104,12 +100,12 @@ const movedPosition = coordPosition.copy().moveX(50).moveY(30);
104
100
  ```typescript
105
101
  // Add paragraph using builder pattern
106
102
  const paragraph = client.paragraphBuilder()
107
- .fromString('Your text here')
108
- .withFont(new Font('Arial', 12))
109
- .withColor(new Color(0, 0, 0))
110
- .withPosition(Position.onPageCoordinates(1, 100, 200))
111
- .withLineSpacing(1.2)
112
- .build();
103
+ .fromString('Your text here')
104
+ .withFont(new Font('Arial', 12))
105
+ .withColor(new Color(0, 0, 0))
106
+ .withPosition(Position.atPageCoordinates(1, 100, 200))
107
+ .withLineSpacing(1.2)
108
+ .build();
113
109
 
114
110
  await client.addParagraph(paragraph);
115
111
 
@@ -167,43 +163,46 @@ The client provides specific exception types for different error scenarios:
167
163
 
168
164
  ```typescript
169
165
  import {
170
- ValidationException,
171
- HttpClientException,
172
- SessionException,
173
- FontNotFoundException,
174
- PdfDancerException
166
+ ValidationException,
167
+ HttpClientException,
168
+ SessionException,
169
+ FontNotFoundException,
170
+ PdfDancerException
175
171
  } from 'pdfdancer-client-typescript';
176
172
 
177
173
  try {
178
- await client.addParagraph(paragraph);
174
+ await client.addParagraph(paragraph);
179
175
  } catch (error) {
180
- if (error instanceof ValidationException) {
181
- console.error('Invalid input:', error.message);
182
- } else if (error instanceof HttpClientException) {
183
- console.error('API error:', error.message, 'Status:', error.statusCode);
184
- } else if (error instanceof FontNotFoundException) {
185
- console.error('Font not found:', error.message);
186
- } else if (error instanceof SessionException) {
187
- console.error('Session error:', error.message);
188
- }
176
+ if (error instanceof ValidationException) {
177
+ console.error('Invalid input:', error.message);
178
+ } else if (error instanceof HttpClientException) {
179
+ console.error('API error:', error.message, 'Status:', error.statusCode);
180
+ } else if (error instanceof FontNotFoundException) {
181
+ console.error('Font not found:', error.message);
182
+ } else if (error instanceof SessionException) {
183
+ console.error('Session error:', error.message);
184
+ }
189
185
  }
190
186
  ```
191
187
 
192
188
  ## Types and Enums
193
189
 
194
190
  ### ObjectType
191
+
195
192
  - `IMAGE` - Image objects
196
- - `FORM` - Form field objects
193
+ - `FORM_X_OBJECT` - Form field objects
197
194
  - `PATH` - Vector path objects
198
195
  - `PARAGRAPH` - Paragraph objects
199
196
  - `TEXT_LINE` - Text line objects
200
197
  - `PAGE` - Page objects
201
198
 
202
199
  ### PositionMode
200
+
203
201
  - `INTERSECT` - Objects that intersect with the specified area
204
202
  - `CONTAINS` - Objects completely contained within the specified area
205
203
 
206
204
  ### ShapeType
205
+
207
206
  - `POINT` - Single point coordinate
208
207
  - `LINE` - Linear shape between two points
209
208
  - `CIRCLE` - Circular area with radius
@@ -238,19 +237,20 @@ The project includes comprehensive end-to-end tests that mirror the Python clien
238
237
  1. **Start PDFDancer server** at `http://localhost:8080` (or set `PDFDANCER_BASE_URL`)
239
238
 
240
239
  2. **Set authentication token**:
241
- - Environment variable: `export PDFDANCER_TOKEN=your-token`
242
- - Or place a `jwt-token-*.txt` file in the project root
240
+ - Environment variable: `export PDFDANCER_TOKEN=your-token`
241
+ - Or place a `jwt-token-*.txt` file in the project root
243
242
 
244
243
  3. **Add test fixtures** in the `fixtures/` directory:
245
- - `ObviouslyAwesome.pdf` - Main test document
246
- - `mixed-form-types.pdf` - Document with form fields
247
- - `basic-paths.pdf` - Document with vector paths
248
- - `logo-80.png` - Test image file
249
- - `DancingScript-Regular.ttf` - Test font file
244
+ - `ObviouslyAwesome.pdf` - Main test document
245
+ - `mixed-form-types.pdf` - Document with form fields
246
+ - `basic-paths.pdf` - Document with vector paths
247
+ - `logo-80.png` - Test image file
248
+ - `DancingScript-Regular.ttf` - Test font file
250
249
 
251
250
  4. **Run e2e tests**: `npm run test:e2e`
252
251
 
253
252
  The e2e tests cover:
253
+
254
254
  - **Paragraph operations**: Find, add, modify, delete paragraphs with custom fonts
255
255
  - **Page operations**: Get pages, delete pages
256
256
  - **Text line operations**: Find, modify, move, delete text lines
@@ -258,10 +258,6 @@ The e2e tests cover:
258
258
  - **Form operations**: Find and delete form fields
259
259
  - **Path operations**: Find, move, delete vector paths
260
260
 
261
- ## Compatibility
262
-
263
- This TypeScript client is designed to be functionally equivalent to the PDFDancer Python client, providing the same API patterns and capabilities with TypeScript type safety and modern JavaScript features.
264
-
265
261
  ## License
266
262
 
267
263
  MIT
@@ -0,0 +1,2 @@
1
+ export declare function expectWithin(actual: number | undefined, expected: number, tolerance: number): void;
2
+ //# sourceMappingURL=assertions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../../src/__tests__/assertions.ts"],"names":[],"mappings":"AAAA,wBAAgB,YAAY,CACxB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAClB,IAAI,CAON"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expectWithin = expectWithin;
4
+ function expectWithin(actual, expected, tolerance) {
5
+ if (actual === undefined) {
6
+ throw new Error(`Expected a number but got undefined`);
7
+ }
8
+ const diff = Math.abs(actual - expected);
9
+ expect(diff).toBeLessThanOrEqual(tolerance);
10
+ }
11
+ //# sourceMappingURL=assertions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertions.js","sourceRoot":"","sources":["../../src/__tests__/assertions.ts"],"names":[],"mappings":";;AAAA,oCAWC;AAXD,SAAgB,YAAY,CACxB,MAA0B,EAC1B,QAAgB,EAChB,SAAiB;IAEjB,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC;IACzC,MAAM,CAAC,IAAI,CAAC,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;AAChD,CAAC"}
@@ -4,7 +4,7 @@
4
4
  * A TypeScript client that closely mirrors the Python Client class structure and functionality.
5
5
  * Provides session-based PDF manipulation operations with strict validation.
6
6
  */
7
- import { ObjectRef, Position, ObjectType, Font, Image, Paragraph } from './models';
7
+ import { Font, Image, ObjectRef, ObjectType, Paragraph, Position } from './models';
8
8
  import { ParagraphBuilder } from './paragraph-builder';
9
9
  /**
10
10
  * REST API client for interacting with the PDFDancer PDF manipulation service.
@@ -30,10 +30,10 @@ export declare class ClientV1 {
30
30
  * Initialize the client by creating a session.
31
31
  * Must be called after constructor before using the client.
32
32
  */
33
- init(): Promise<void>;
33
+ private init;
34
+ static create(token: string, pdfData: Uint8Array, baseUrl: string, timeout?: number): Promise<ClientV1>;
34
35
  /**
35
36
  * Process PDF data from various input types with strict validation.
36
- * Equivalent to readFile() method in Python client.
37
37
  */
38
38
  private _processPdfData;
39
39
  /**
@@ -43,12 +43,10 @@ export declare class ClientV1 {
43
43
  private _extractErrorMessage;
44
44
  /**
45
45
  * Creates a new PDF processing session by uploading the PDF data.
46
- * Equivalent to createSession() method in Python client.
47
46
  */
48
47
  private _createSession;
49
48
  /**
50
49
  * Make HTTP request with session headers and error handling.
51
- * Equivalent to retrieve() method pattern in Python client.
52
50
  */
53
51
  private _makeRequest;
54
52
  /**
@@ -59,92 +57,74 @@ export declare class ClientV1 {
59
57
  find(objectType?: ObjectType, position?: Position): Promise<ObjectRef[]>;
60
58
  /**
61
59
  * Searches for paragraph objects at the specified position.
62
- * Equivalent to findParagraphs() in Python client.
63
60
  */
64
61
  findParagraphs(position?: Position): Promise<ObjectRef[]>;
65
62
  /**
66
63
  * Searches for image objects at the specified position.
67
- * Equivalent to findImages() in Python client.
68
64
  */
69
65
  findImages(position?: Position): Promise<ObjectRef[]>;
70
66
  /**
71
67
  * Searches for form field objects at the specified position.
72
- * Equivalent to findForms() in Python client.
73
68
  */
74
69
  findForms(position?: Position): Promise<ObjectRef[]>;
75
70
  /**
76
71
  * Searches for vector path objects at the specified position.
77
- * Equivalent to findPaths() in Python client.
78
72
  */
79
73
  findPaths(position?: Position): Promise<ObjectRef[]>;
80
74
  /**
81
75
  * Searches for text line objects at the specified position.
82
- * Equivalent to findTextLines() in Python client.
83
76
  */
84
77
  findTextLines(position?: Position): Promise<ObjectRef[]>;
85
78
  /**
86
79
  * Retrieves references to all pages in the PDF document.
87
- * Equivalent to getPages() in Python client.
88
80
  */
89
81
  getPages(): Promise<ObjectRef[]>;
90
82
  /**
91
83
  * Retrieves a reference to a specific page by its page index.
92
- * Equivalent to getPage() in Python client.
93
84
  */
94
85
  getPage(pageIndex: number): Promise<ObjectRef | null>;
95
86
  /**
96
87
  * Deletes a page from the PDF document.
97
- * Equivalent to deletePage() in Python client.
98
88
  */
99
89
  deletePage(pageRef: ObjectRef): Promise<boolean>;
100
90
  /**
101
91
  * Deletes the specified PDF object from the document.
102
- * Equivalent to delete() in Python client.
103
92
  */
104
93
  delete(objectRef: ObjectRef): Promise<boolean>;
105
94
  /**
106
95
  * Moves a PDF object to a new position within the document.
107
- * Equivalent to move() in Python client.
108
96
  */
109
97
  move(objectRef: ObjectRef, position: Position): Promise<boolean>;
110
98
  /**
111
99
  * Adds an image to the PDF document.
112
- * Equivalent to addImage() methods in Python client.
113
100
  */
114
101
  addImage(image: Image, position?: Position): Promise<boolean>;
115
102
  /**
116
103
  * Adds a paragraph to the PDF document.
117
- * Equivalent to addParagraph() in Python client with validation.
118
104
  */
119
105
  addParagraph(paragraph: Paragraph): Promise<boolean>;
120
106
  /**
121
107
  * Internal method to add any PDF object.
122
- * Equivalent to addObject() in Python client.
123
108
  */
124
109
  private _addObject;
125
110
  /**
126
111
  * Modifies a paragraph object or its text content.
127
- * Equivalent to modifyParagraph() methods in Python client.
128
112
  */
129
113
  modifyParagraph(objectRef: ObjectRef, newParagraph: Paragraph | string): Promise<boolean>;
130
114
  /**
131
115
  * Modifies a text line object.
132
- * Equivalent to modifyTextLine() in Python client.
133
116
  */
134
117
  modifyTextLine(objectRef: ObjectRef, newText: string): Promise<boolean>;
135
118
  /**
136
119
  * Finds available fonts matching the specified name and size.
137
- * Equivalent to findFonts() in Python client.
138
120
  */
139
121
  findFonts(fontName: string, fontSize: number): Promise<Font[]>;
140
122
  /**
141
123
  * Registers a custom font for use in PDF operations.
142
- * Equivalent to registerFont() in Python client.
143
124
  */
144
125
  registerFont(ttfFile: Uint8Array | File): Promise<string>;
145
126
  /**
146
127
  * Downloads the current state of the PDF document with all modifications applied.
147
- * Equivalent to getPDFFile() in Python client.
148
128
  */
149
129
  getPdfFile(): Promise<Uint8Array>;
150
130
  /**
@@ -162,7 +142,6 @@ export declare class ClientV1 {
162
142
  private _parsePosition;
163
143
  /**
164
144
  * Creates a new ParagraphBuilder for fluent paragraph construction.
165
- * Equivalent to paragraphBuilder() in Python client.
166
145
  */
167
146
  paragraphBuilder(): ParagraphBuilder;
168
147
  }
@@ -1 +1 @@
1
- {"version":3,"file":"client-v1.d.ts","sourceRoot":"","sources":["../src/client-v1.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,OAAO,EACL,SAAS,EACT,QAAQ,EACR,UAAU,EACV,IAAI,EACJ,KAAK,EACL,SAAS,EAUV,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;;;GAOG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,UAAU,CAAU;IAE5B;;;;OAIG;gBAED,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,UAAU,GAAG,IAAI,GAAG,WAAW,EACxC,OAAO,GAAE,MAAgC,EACzC,WAAW,GAAE,MA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-v1.js CHANGED
@@ -41,10 +41,14 @@ class ClientV1 {
41
41
  */
42
42
  async init() {
43
43
  this._sessionId = await this._createSession();
44
+ return this;
45
+ }
46
+ static async create(token, pdfData, baseUrl, timeout = 0) {
47
+ const client = new ClientV1(token, pdfData, baseUrl, timeout);
48
+ return await client.init();
44
49
  }
45
50
  /**
46
51
  * Process PDF data from various input types with strict validation.
47
- * Equivalent to readFile() method in Python client.
48
52
  */
49
53
  _processPdfData(pdfData) {
50
54
  if (!pdfData) {
@@ -120,7 +124,6 @@ class ClientV1 {
120
124
  }
121
125
  /**
122
126
  * Creates a new PDF processing session by uploading the PDF data.
123
- * Equivalent to createSession() method in Python client.
124
127
  */
125
128
  async _createSession() {
126
129
  try {
@@ -161,7 +164,6 @@ class ClientV1 {
161
164
  }
162
165
  /**
163
166
  * Make HTTP request with session headers and error handling.
164
- * Equivalent to retrieve() method pattern in Python client.
165
167
  */
166
168
  async _makeRequest(method, path, data, params) {
167
169
  const url = new URL(`${this._baseUrl}${path}`);
@@ -225,35 +227,30 @@ class ClientV1 {
225
227
  }
226
228
  /**
227
229
  * Searches for paragraph objects at the specified position.
228
- * Equivalent to findParagraphs() in Python client.
229
230
  */
230
231
  async findParagraphs(position) {
231
232
  return this.find(models_1.ObjectType.PARAGRAPH, position);
232
233
  }
233
234
  /**
234
235
  * Searches for image objects at the specified position.
235
- * Equivalent to findImages() in Python client.
236
236
  */
237
237
  async findImages(position) {
238
238
  return this.find(models_1.ObjectType.IMAGE, position);
239
239
  }
240
240
  /**
241
241
  * Searches for form field objects at the specified position.
242
- * Equivalent to findForms() in Python client.
243
242
  */
244
243
  async findForms(position) {
245
- return this.find(models_1.ObjectType.FORM, position);
244
+ return this.find(models_1.ObjectType.FORM_X_OBJECT, position);
246
245
  }
247
246
  /**
248
247
  * Searches for vector path objects at the specified position.
249
- * Equivalent to findPaths() in Python client.
250
248
  */
251
249
  async findPaths(position) {
252
250
  return this.find(models_1.ObjectType.PATH, position);
253
251
  }
254
252
  /**
255
253
  * Searches for text line objects at the specified position.
256
- * Equivalent to findTextLines() in Python client.
257
254
  */
258
255
  async findTextLines(position) {
259
256
  return this.find(models_1.ObjectType.TEXT_LINE, position);
@@ -261,7 +258,6 @@ class ClientV1 {
261
258
  // Page Operations
262
259
  /**
263
260
  * Retrieves references to all pages in the PDF document.
264
- * Equivalent to getPages() in Python client.
265
261
  */
266
262
  async getPages() {
267
263
  const response = await this._makeRequest('POST', '/pdf/page/find');
@@ -270,7 +266,6 @@ class ClientV1 {
270
266
  }
271
267
  /**
272
268
  * Retrieves a reference to a specific page by its page index.
273
- * Equivalent to getPage() in Python client.
274
269
  */
275
270
  async getPage(pageIndex) {
276
271
  if (pageIndex < 0) {
@@ -286,7 +281,6 @@ class ClientV1 {
286
281
  }
287
282
  /**
288
283
  * Deletes a page from the PDF document.
289
- * Equivalent to deletePage() in Python client.
290
284
  */
291
285
  async deletePage(pageRef) {
292
286
  if (!pageRef) {
@@ -299,7 +293,6 @@ class ClientV1 {
299
293
  // Manipulation Operations
300
294
  /**
301
295
  * Deletes the specified PDF object from the document.
302
- * Equivalent to delete() in Python client.
303
296
  */
304
297
  async delete(objectRef) {
305
298
  if (!objectRef) {
@@ -311,7 +304,6 @@ class ClientV1 {
311
304
  }
312
305
  /**
313
306
  * Moves a PDF object to a new position within the document.
314
- * Equivalent to move() in Python client.
315
307
  */
316
308
  async move(objectRef, position) {
317
309
  if (!objectRef) {
@@ -327,7 +319,6 @@ class ClientV1 {
327
319
  // Add Operations
328
320
  /**
329
321
  * Adds an image to the PDF document.
330
- * Equivalent to addImage() methods in Python client.
331
322
  */
332
323
  async addImage(image, position) {
333
324
  if (!image) {
@@ -343,7 +334,6 @@ class ClientV1 {
343
334
  }
344
335
  /**
345
336
  * Adds a paragraph to the PDF document.
346
- * Equivalent to addParagraph() in Python client with validation.
347
337
  */
348
338
  async addParagraph(paragraph) {
349
339
  if (!paragraph) {
@@ -362,7 +352,6 @@ class ClientV1 {
362
352
  }
363
353
  /**
364
354
  * Internal method to add any PDF object.
365
- * Equivalent to addObject() in Python client.
366
355
  */
367
356
  async _addObject(pdfObject) {
368
357
  const requestData = new models_1.AddRequest(pdfObject).toDict();
@@ -372,7 +361,6 @@ class ClientV1 {
372
361
  // Modify Operations
373
362
  /**
374
363
  * Modifies a paragraph object or its text content.
375
- * Equivalent to modifyParagraph() methods in Python client.
376
364
  */
377
365
  async modifyParagraph(objectRef, newParagraph) {
378
366
  if (!objectRef) {
@@ -396,7 +384,6 @@ class ClientV1 {
396
384
  }
397
385
  /**
398
386
  * Modifies a text line object.
399
- * Equivalent to modifyTextLine() in Python client.
400
387
  */
401
388
  async modifyTextLine(objectRef, newText) {
402
389
  if (!objectRef) {
@@ -412,7 +399,6 @@ class ClientV1 {
412
399
  // Font Operations
413
400
  /**
414
401
  * Finds available fonts matching the specified name and size.
415
- * Equivalent to findFonts() in Python client.
416
402
  */
417
403
  async findFonts(fontName, fontSize) {
418
404
  if (!fontName || !fontName.trim()) {
@@ -428,7 +414,6 @@ class ClientV1 {
428
414
  }
429
415
  /**
430
416
  * Registers a custom font for use in PDF operations.
431
- * Equivalent to registerFont() in Python client.
432
417
  */
433
418
  async registerFont(ttfFile) {
434
419
  if (!ttfFile) {
@@ -484,7 +469,6 @@ class ClientV1 {
484
469
  // Document Operations
485
470
  /**
486
471
  * Downloads the current state of the PDF document with all modifications applied.
487
- * Equivalent to getPDFFile() in Python client.
488
472
  */
489
473
  async getPdfFile() {
490
474
  const response = await this._makeRequest('GET', `/session/${this._sessionId}/pdf`);
@@ -548,7 +532,6 @@ class ClientV1 {
548
532
  // Builder Pattern Support
549
533
  /**
550
534
  * Creates a new ParagraphBuilder for fluent paragraph construction.
551
- * Equivalent to paragraphBuilder() in Python client.
552
535
  */
553
536
  paragraphBuilder() {
554
537
  return new paragraph_builder_1.ParagraphBuilder(this);