pdfdancer-client-typescript 1.0.17 → 1.0.19
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 +12 -4
- package/dist/__tests__/e2e/pdf-assertions.d.ts.map +1 -1
- package/dist/__tests__/e2e/pdf-assertions.js +1 -1
- package/dist/__tests__/e2e/pdf-assertions.js.map +1 -1
- package/dist/__tests__/e2e/test-drawing-helpers.d.ts +148 -0
- package/dist/__tests__/e2e/test-drawing-helpers.d.ts.map +1 -0
- package/dist/__tests__/e2e/test-drawing-helpers.js +343 -0
- package/dist/__tests__/e2e/test-drawing-helpers.js.map +1 -0
- package/dist/__tests__/e2e/test-helpers.d.ts +10 -0
- package/dist/__tests__/e2e/test-helpers.d.ts.map +1 -1
- package/dist/__tests__/e2e/test-helpers.js +55 -0
- package/dist/__tests__/e2e/test-helpers.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +54 -2
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +115 -1
- package/dist/models.js.map +1 -1
- package/dist/path-builder.d.ts +110 -0
- package/dist/path-builder.d.ts.map +1 -0
- package/dist/path-builder.js +177 -0
- package/dist/path-builder.js.map +1 -0
- package/dist/pdfdancer_v1.d.ts +7 -0
- package/dist/pdfdancer_v1.d.ts.map +1 -1
- package/dist/pdfdancer_v1.js +40 -89
- package/dist/pdfdancer_v1.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PathBuilder = void 0;
|
|
4
|
+
const models_1 = require("./models");
|
|
5
|
+
/**
|
|
6
|
+
* Builder for creating vector paths in PDF documents.
|
|
7
|
+
*
|
|
8
|
+
* Supports creating paths with:
|
|
9
|
+
* - Lines
|
|
10
|
+
* - Bezier curves
|
|
11
|
+
* - Custom stroke and fill colors
|
|
12
|
+
* - Stroke width and dash patterns
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Create a simple line
|
|
17
|
+
* await pdf.newPath()
|
|
18
|
+
* .moveTo(100, 100)
|
|
19
|
+
* .lineTo(200, 200)
|
|
20
|
+
* .strokeColor(new Color(0, 0, 0))
|
|
21
|
+
* .strokeWidth(2)
|
|
22
|
+
* .at(0, 0, 0)
|
|
23
|
+
* .add();
|
|
24
|
+
*
|
|
25
|
+
* // Create a bezier curve
|
|
26
|
+
* await pdf.newPath()
|
|
27
|
+
* .moveTo(100, 100)
|
|
28
|
+
* .bezierTo(150, 50, 250, 150, 300, 100)
|
|
29
|
+
* .strokeColor(new Color(255, 0, 0))
|
|
30
|
+
* .at(0, 0, 0)
|
|
31
|
+
* .add();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
class PathBuilder {
|
|
35
|
+
constructor(_client, _defaultPageIndex) {
|
|
36
|
+
this._client = _client;
|
|
37
|
+
this._defaultPageIndex = _defaultPageIndex;
|
|
38
|
+
this._segments = [];
|
|
39
|
+
// Cast to the internal interface to get access
|
|
40
|
+
this._internals = this._client;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Move to a point without drawing.
|
|
44
|
+
* Sets the current point for subsequent drawing operations.
|
|
45
|
+
*/
|
|
46
|
+
moveTo(x, y) {
|
|
47
|
+
this._currentPoint = { x, y };
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Draw a line from the current point to the specified point.
|
|
52
|
+
*/
|
|
53
|
+
lineTo(x, y) {
|
|
54
|
+
if (!this._currentPoint) {
|
|
55
|
+
throw new Error("No current point set. Call moveTo() first.");
|
|
56
|
+
}
|
|
57
|
+
const line = new models_1.Line(this._currentPoint, { x, y }, undefined, // position will be set in add()
|
|
58
|
+
this._strokeColor, this._fillColor, this._strokeWidth, this._dashArray, this._dashPhase);
|
|
59
|
+
this._segments.push(line);
|
|
60
|
+
this._currentPoint = { x, y };
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Draw a cubic Bezier curve from the current point.
|
|
65
|
+
* @param cp1x First control point X
|
|
66
|
+
* @param cp1y First control point Y
|
|
67
|
+
* @param cp2x Second control point X
|
|
68
|
+
* @param cp2y Second control point Y
|
|
69
|
+
* @param x End point X
|
|
70
|
+
* @param y End point Y
|
|
71
|
+
*/
|
|
72
|
+
bezierTo(cp1x, cp1y, cp2x, cp2y, x, y) {
|
|
73
|
+
if (!this._currentPoint) {
|
|
74
|
+
throw new Error("No current point set. Call moveTo() first.");
|
|
75
|
+
}
|
|
76
|
+
const bezier = new models_1.Bezier(this._currentPoint, { x: cp1x, y: cp1y }, { x: cp2x, y: cp2y }, { x, y }, undefined, // position will be set in add()
|
|
77
|
+
this._strokeColor, this._fillColor, this._strokeWidth, this._dashArray, this._dashPhase);
|
|
78
|
+
this._segments.push(bezier);
|
|
79
|
+
this._currentPoint = { x, y };
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Add a custom path segment.
|
|
84
|
+
*/
|
|
85
|
+
addSegment(segment) {
|
|
86
|
+
this._segments.push(segment);
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Set the stroke color for subsequent path segments.
|
|
91
|
+
*/
|
|
92
|
+
strokeColor(color) {
|
|
93
|
+
this._strokeColor = color;
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Set the fill color for subsequent path segments.
|
|
98
|
+
*/
|
|
99
|
+
fillColor(color) {
|
|
100
|
+
this._fillColor = color;
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Set the stroke width for subsequent path segments.
|
|
105
|
+
*/
|
|
106
|
+
strokeWidth(width) {
|
|
107
|
+
this._strokeWidth = width;
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Set the dash pattern for subsequent path segments.
|
|
112
|
+
* @param dashArray Array of numbers specifying dash pattern (on/off lengths)
|
|
113
|
+
* @param dashPhase Offset into the dash pattern
|
|
114
|
+
*/
|
|
115
|
+
dashPattern(dashArray, dashPhase = 0) {
|
|
116
|
+
this._dashArray = dashArray;
|
|
117
|
+
this._dashPhase = dashPhase;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Set whether to use even-odd fill rule (true) or nonzero winding rule (false).
|
|
122
|
+
*/
|
|
123
|
+
evenOddFill(useEvenOdd) {
|
|
124
|
+
this._evenOddFill = useEvenOdd;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
at(pageIndexOrX, xOrY, maybeY) {
|
|
128
|
+
if (maybeY === undefined) {
|
|
129
|
+
if (this._defaultPageIndex === undefined) {
|
|
130
|
+
throw new Error('Page index must be provided when adding a path');
|
|
131
|
+
}
|
|
132
|
+
this._position = models_1.Position.atPageCoordinates(this._defaultPageIndex, pageIndexOrX, xOrY);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
this._position = models_1.Position.atPageCoordinates(pageIndexOrX, xOrY, maybeY);
|
|
136
|
+
}
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Set the position using a Position object.
|
|
141
|
+
*/
|
|
142
|
+
atPosition(position) {
|
|
143
|
+
this._position = position;
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Add the path to the PDF document.
|
|
148
|
+
*/
|
|
149
|
+
async add() {
|
|
150
|
+
if (this._segments.length === 0) {
|
|
151
|
+
throw new Error("No path segments defined. Use moveTo(), lineTo(), or bezierTo() to create path segments.");
|
|
152
|
+
}
|
|
153
|
+
if (!this._position) {
|
|
154
|
+
throw new Error("Position is not set. Use at() or atPosition() to set the position.");
|
|
155
|
+
}
|
|
156
|
+
// Apply current styling and position to all segments
|
|
157
|
+
for (const segment of this._segments) {
|
|
158
|
+
// All segments share the same position as the path
|
|
159
|
+
segment.position = this._position;
|
|
160
|
+
segment.strokeColor = this._strokeColor;
|
|
161
|
+
segment.fillColor = this._fillColor;
|
|
162
|
+
segment.strokeWidth = this._strokeWidth;
|
|
163
|
+
segment.dashArray = this._dashArray;
|
|
164
|
+
segment.dashPhase = this._dashPhase;
|
|
165
|
+
}
|
|
166
|
+
const path = new models_1.Path(this._position, this._segments, this._evenOddFill);
|
|
167
|
+
return await this._internals.addPath(path);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Alias for add(). Adds the path to the PDF document.
|
|
171
|
+
*/
|
|
172
|
+
async apply() {
|
|
173
|
+
return await this.add();
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
exports.PathBuilder = PathBuilder;
|
|
177
|
+
//# sourceMappingURL=path-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-builder.js","sourceRoot":"","sources":["../src/path-builder.ts"],"names":[],"mappings":";;;AACA,qCAAqF;AAOrF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAa,WAAW;IAYpB,YAAoB,OAAkB,EAAmB,iBAA0B;QAA/D,YAAO,GAAP,OAAO,CAAW;QAAmB,sBAAiB,GAAjB,iBAAiB,CAAS;QAX3E,cAAS,GAAkB,EAAE,CAAC;QAYlC,+CAA+C;QAC/C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAwC,CAAC;IACpE,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,CAAS,EAAE,CAAS;QACvB,IAAI,CAAC,aAAa,GAAG,EAAC,CAAC,EAAE,CAAC,EAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,CAAS,EAAE,CAAS;QACvB,IAAI,CAAC,IAA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HANGED
|
@@ -8,6 +8,7 @@ import { ParagraphBuilder } from './paragraph-builder';
|
|
|
8
8
|
import { PageBuilder } from './page-builder';
|
|
9
9
|
import { FormFieldObject, FormXObject, ImageObject, ParagraphObject, PathObject, TextLineObject } from "./types";
|
|
10
10
|
import { ImageBuilder } from "./image-builder";
|
|
11
|
+
import { PathBuilder } from "./path-builder";
|
|
11
12
|
/**
|
|
12
13
|
* Configuration for retry mechanism on REST API calls.
|
|
13
14
|
*/
|
|
@@ -80,6 +81,7 @@ declare class PageClient {
|
|
|
80
81
|
*/
|
|
81
82
|
newParagraph(pageIndex?: number): ParagraphBuilder;
|
|
82
83
|
newImage(pageIndex?: number): ImageBuilder;
|
|
84
|
+
newPath(pageIndex?: number): PathBuilder;
|
|
83
85
|
selectTextLines(): Promise<TextLineObject[]>;
|
|
84
86
|
selectTextLinesMatching(pattern: string): Promise<TextLineObject[]>;
|
|
85
87
|
selectTextLinesAt(x: number, y: number, tolerance?: number): Promise<TextLineObject[]>;
|
|
@@ -311,6 +313,10 @@ export declare class PDFDancer {
|
|
|
311
313
|
* Adds a paragraph to the PDF document.
|
|
312
314
|
*/
|
|
313
315
|
private addParagraph;
|
|
316
|
+
/**
|
|
317
|
+
* Adds a path to the PDF document.
|
|
318
|
+
*/
|
|
319
|
+
private addPath;
|
|
314
320
|
/**
|
|
315
321
|
* Adds a page to the PDF document.
|
|
316
322
|
*/
|
|
@@ -372,6 +378,7 @@ export declare class PDFDancer {
|
|
|
372
378
|
private toImageObjects;
|
|
373
379
|
newImage(pageIndex?: number): ImageBuilder;
|
|
374
380
|
newParagraph(pageIndex?: number): ParagraphBuilder;
|
|
381
|
+
newPath(pageIndex?: number): PathBuilder;
|
|
375
382
|
newPage(): PageBuilder;
|
|
376
383
|
page(pageIndex: number): PageClient;
|
|
377
384
|
pages(): Promise<PageClient[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdfdancer_v1.d.ts","sourceRoot":"","sources":["../src/pdfd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_1 = require("./paragraph-builder");
|
|
|
15
15
|
const page_builder_1 = require("./page-builder");
|
|
16
16
|
const types_1 = require("./types");
|
|
17
17
|
const image_builder_1 = require("./image-builder");
|
|
18
|
+
const path_builder_1 = require("./path-builder");
|
|
18
19
|
const fingerprint_1 = require("./fingerprint");
|
|
19
20
|
const fs_1 = __importDefault(require("fs"));
|
|
20
21
|
const node_path_1 = __importDefault(require("node:path"));
|
|
21
22
|
const DEFAULT_TOLERANCE = 0.01;
|
|
22
|
-
// Debug flag - set to true to enable timing logs
|
|
23
|
-
const DEBUG = (process.env.PDFDANCER_CLIENT_DEBUG ?? '').toLowerCase() === 'true' ||
|
|
24
|
-
(process.env.PDFDANCER_CLIENT_DEBUG ?? '') === '1' ||
|
|
25
|
-
(process.env.PDFDANCER_CLIENT_DEBUG ?? '').toLowerCase() === 'yes';
|
|
26
23
|
/**
|
|
27
24
|
* Default retry configuration
|
|
28
25
|
*/
|
|
@@ -42,7 +39,7 @@ const DEFAULT_RETRY_CONFIG = {
|
|
|
42
39
|
*/
|
|
43
40
|
async function fetchWithRetry(url,
|
|
44
41
|
// eslint-disable-next-line no-undef
|
|
45
|
-
options, retryConfig
|
|
42
|
+
options, retryConfig) {
|
|
46
43
|
let lastError = null;
|
|
47
44
|
let lastResponse = null;
|
|
48
45
|
for (let attempt = 0; attempt <= retryConfig.maxRetries; attempt++) {
|
|
@@ -54,14 +51,12 @@ options, retryConfig, context = 'request') {
|
|
|
54
51
|
// If this is not the last attempt, wait and retry
|
|
55
52
|
if (attempt < retryConfig.maxRetries) {
|
|
56
53
|
let delay;
|
|
57
|
-
let delaySource = 'exponential backoff';
|
|
58
54
|
// Check for Retry-After header if configured
|
|
59
55
|
if (retryConfig.respectRetryAfter) {
|
|
60
56
|
const retryAfterDelay = parseRetryAfter(response);
|
|
61
57
|
if (retryAfterDelay !== null) {
|
|
62
58
|
// Use Retry-After header value, but cap at maxDelay
|
|
63
59
|
delay = Math.min(retryAfterDelay, retryConfig.maxDelay);
|
|
64
|
-
delaySource = 'Retry-After header';
|
|
65
60
|
}
|
|
66
61
|
else {
|
|
67
62
|
// Fall back to exponential backoff
|
|
@@ -72,9 +67,6 @@ options, retryConfig, context = 'request') {
|
|
|
72
67
|
// Use exponential backoff
|
|
73
68
|
delay = calculateRetryDelay(attempt, retryConfig);
|
|
74
69
|
}
|
|
75
|
-
if (DEBUG) {
|
|
76
|
-
console.log(`${Date.now() / 1000}|Retry attempt ${attempt + 1}/${retryConfig.maxRetries} for ${context} after ${delay}ms (status: ${response.status}, source: ${delaySource})`);
|
|
77
|
-
}
|
|
78
70
|
await sleep(delay);
|
|
79
71
|
continue;
|
|
80
72
|
}
|
|
@@ -87,10 +79,6 @@ options, retryConfig, context = 'request') {
|
|
|
87
79
|
// Check if this is a network error and we should retry
|
|
88
80
|
if (retryConfig.retryOnNetworkError && attempt < retryConfig.maxRetries) {
|
|
89
81
|
const delay = calculateRetryDelay(attempt, retryConfig);
|
|
90
|
-
if (DEBUG) {
|
|
91
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
92
|
-
console.log(`${Date.now() / 1000}|Retry attempt ${attempt + 1}/${retryConfig.maxRetries} for ${context} after ${delay}ms (error: ${errorMessage})`);
|
|
93
|
-
}
|
|
94
82
|
await sleep(delay);
|
|
95
83
|
continue;
|
|
96
84
|
}
|
|
@@ -176,69 +164,6 @@ function generateTimestamp() {
|
|
|
176
164
|
const microseconds = milliseconds + '000';
|
|
177
165
|
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${microseconds}Z`;
|
|
178
166
|
}
|
|
179
|
-
/**
|
|
180
|
-
* Parse timestamp string, handling both microseconds and nanoseconds precision.
|
|
181
|
-
* @param timestampStr Timestamp string in format YYYY-MM-DDTHH:MM:SS.fffffffZ (with 6 or 9 fractional digits)
|
|
182
|
-
*/
|
|
183
|
-
function parseTimestamp(timestampStr) {
|
|
184
|
-
// Remove the 'Z' suffix
|
|
185
|
-
let ts = timestampStr.replace(/Z$/, '');
|
|
186
|
-
// Handle nanoseconds (9 digits) by truncating to milliseconds (3 digits)
|
|
187
|
-
// JavaScript's Date only supports millisecond precision
|
|
188
|
-
if (ts.includes('.')) {
|
|
189
|
-
const [datePart, fracPart] = ts.split('.');
|
|
190
|
-
// Truncate to 3 digits (milliseconds)
|
|
191
|
-
const truncatedFrac = fracPart.substring(0, 3);
|
|
192
|
-
ts = `${datePart}.${truncatedFrac}`;
|
|
193
|
-
}
|
|
194
|
-
return new Date(ts + 'Z');
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Check for X-Generated-At and X-Received-At headers and log timing information if DEBUG=true.
|
|
198
|
-
*
|
|
199
|
-
* Expected timestamp formats:
|
|
200
|
-
* - 2025-10-24T08:49:39.161945Z (microseconds - 6 digits)
|
|
201
|
-
* - 2025-10-24T08:58:45.468131265Z (nanoseconds - 9 digits)
|
|
202
|
-
*/
|
|
203
|
-
function logGeneratedAtHeader(response, method, path) {
|
|
204
|
-
if (!DEBUG) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
const generatedAt = response.headers.get('X-Generated-At');
|
|
208
|
-
const receivedAt = response.headers.get('X-Received-At');
|
|
209
|
-
if (generatedAt || receivedAt) {
|
|
210
|
-
try {
|
|
211
|
-
const logParts = [];
|
|
212
|
-
const currentTime = new Date();
|
|
213
|
-
// Parse and log X-Received-At
|
|
214
|
-
let receivedTime = null;
|
|
215
|
-
if (receivedAt) {
|
|
216
|
-
receivedTime = parseTimestamp(receivedAt);
|
|
217
|
-
const timeSinceReceived = (currentTime.getTime() - receivedTime.getTime()) / 1000;
|
|
218
|
-
logParts.push(`X-Received-At: ${receivedAt}, time since received on backend: ${timeSinceReceived.toFixed(3)}s`);
|
|
219
|
-
}
|
|
220
|
-
// Parse and log X-Generated-At
|
|
221
|
-
let generatedTime = null;
|
|
222
|
-
if (generatedAt) {
|
|
223
|
-
generatedTime = parseTimestamp(generatedAt);
|
|
224
|
-
const timeSinceGenerated = (currentTime.getTime() - generatedTime.getTime()) / 1000;
|
|
225
|
-
logParts.push(`X-Generated-At: ${generatedAt}, time since generated on backend: ${timeSinceGenerated.toFixed(3)}s`);
|
|
226
|
-
}
|
|
227
|
-
// Calculate processing time (X-Generated-At - X-Received-At)
|
|
228
|
-
if (receivedTime && generatedTime) {
|
|
229
|
-
const processingTime = (generatedTime.getTime() - receivedTime.getTime()) / 1000;
|
|
230
|
-
logParts.push(`processing time on backend: ${processingTime.toFixed(3)}s`);
|
|
231
|
-
}
|
|
232
|
-
if (logParts.length > 0) {
|
|
233
|
-
console.log(`${Date.now() / 1000}|${method} ${path} - ${logParts.join(', ')}`);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
catch (e) {
|
|
237
|
-
const errorMessage = e instanceof Error ? e.message : String(e);
|
|
238
|
-
console.log(`${Date.now() / 1000}|${method} ${path} - Header parse error: ${errorMessage}`);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
167
|
class PageClient {
|
|
243
168
|
constructor(client, pageIndex, pageRef) {
|
|
244
169
|
this.type = models_1.ObjectType.PAGE;
|
|
@@ -330,6 +255,10 @@ class PageClient {
|
|
|
330
255
|
const targetIndex = pageIndex ?? this.position.pageIndex;
|
|
331
256
|
return new image_builder_1.ImageBuilder(this._client, targetIndex);
|
|
332
257
|
}
|
|
258
|
+
newPath(pageIndex) {
|
|
259
|
+
const targetIndex = pageIndex ?? this.position.pageIndex;
|
|
260
|
+
return new path_builder_1.PathBuilder(this._client, targetIndex);
|
|
261
|
+
}
|
|
333
262
|
async selectTextLines() {
|
|
334
263
|
return this._internals.toTextLineObjects(await this._internals.findTextLines(models_1.Position.atPage(this._pageIndex)));
|
|
335
264
|
}
|
|
@@ -535,8 +464,7 @@ class PDFDancer {
|
|
|
535
464
|
},
|
|
536
465
|
body: JSON.stringify(createRequest.toDict()),
|
|
537
466
|
signal: resolvedTimeout > 0 ? AbortSignal.timeout(resolvedTimeout) : undefined
|
|
538
|
-
}, DEFAULT_RETRY_CONFIG
|
|
539
|
-
logGeneratedAtHeader(response, 'POST', '/session/new');
|
|
467
|
+
}, DEFAULT_RETRY_CONFIG);
|
|
540
468
|
if (!response.ok) {
|
|
541
469
|
const errorText = await response.text();
|
|
542
470
|
throw new exceptions_1.HttpClientException(`Failed to create new PDF: ${errorText}`, response);
|
|
@@ -583,7 +511,7 @@ class PDFDancer {
|
|
|
583
511
|
'X-Generated-At': generateTimestamp()
|
|
584
512
|
},
|
|
585
513
|
signal: timeout > 0 ? AbortSignal.timeout(timeout) : undefined
|
|
586
|
-
}, DEFAULT_RETRY_CONFIG
|
|
514
|
+
}, DEFAULT_RETRY_CONFIG);
|
|
587
515
|
if (!response.ok) {
|
|
588
516
|
const errorText = await response.text().catch(() => '');
|
|
589
517
|
throw new exceptions_1.HttpClientException(`Failed to obtain anonymous token: ${errorText || `HTTP ${response.status}`}`, response);
|
|
@@ -722,8 +650,7 @@ class PDFDancer {
|
|
|
722
650
|
},
|
|
723
651
|
body: formData,
|
|
724
652
|
signal: this._readTimeout > 0 ? AbortSignal.timeout(this._readTimeout) : undefined
|
|
725
|
-
}
|
|
726
|
-
logGeneratedAtHeader(response, 'POST', '/session/create');
|
|
653
|
+
});
|
|
727
654
|
if (!response.ok) {
|
|
728
655
|
const errorMessage = await this._extractErrorMessage(response);
|
|
729
656
|
if (response.status === 401 || response.status === 403) {
|
|
@@ -765,8 +692,8 @@ class PDFDancer {
|
|
|
765
692
|
*/
|
|
766
693
|
async _fetchWithRetry(url,
|
|
767
694
|
// eslint-disable-next-line no-undef
|
|
768
|
-
options
|
|
769
|
-
return fetchWithRetry(url, options, this._retryConfig
|
|
695
|
+
options) {
|
|
696
|
+
return fetchWithRetry(url, options, this._retryConfig);
|
|
770
697
|
}
|
|
771
698
|
/**
|
|
772
699
|
* Make HTTP request with session headers and error handling.
|
|
@@ -792,8 +719,7 @@ class PDFDancer {
|
|
|
792
719
|
headers,
|
|
793
720
|
body: data ? JSON.stringify(data) : undefined,
|
|
794
721
|
signal: this._readTimeout > 0 ? AbortSignal.timeout(this._readTimeout) : undefined
|
|
795
|
-
}
|
|
796
|
-
logGeneratedAtHeader(response, method, path);
|
|
722
|
+
});
|
|
797
723
|
// Handle FontNotFoundException
|
|
798
724
|
if (response.status === 404) {
|
|
799
725
|
try {
|
|
@@ -1275,6 +1201,24 @@ class PDFDancer {
|
|
|
1275
1201
|
}
|
|
1276
1202
|
return this._addObject(paragraph);
|
|
1277
1203
|
}
|
|
1204
|
+
/**
|
|
1205
|
+
* Adds a path to the PDF document.
|
|
1206
|
+
*/
|
|
1207
|
+
async addPath(path) {
|
|
1208
|
+
if (!path) {
|
|
1209
|
+
throw new exceptions_1.ValidationException("Path cannot be null");
|
|
1210
|
+
}
|
|
1211
|
+
if (!path.getPosition()) {
|
|
1212
|
+
throw new exceptions_1.ValidationException("Path position is null, you need to specify a position for the new path, using .at(x,y)");
|
|
1213
|
+
}
|
|
1214
|
+
if (path.getPosition().pageIndex === undefined) {
|
|
1215
|
+
throw new exceptions_1.ValidationException("Path position page index is null");
|
|
1216
|
+
}
|
|
1217
|
+
if (path.getPosition().pageIndex < 0) {
|
|
1218
|
+
throw new exceptions_1.ValidationException("Path position page index is less than 0");
|
|
1219
|
+
}
|
|
1220
|
+
return await this._addObject(path);
|
|
1221
|
+
}
|
|
1278
1222
|
/**
|
|
1279
1223
|
* Adds a page to the PDF document.
|
|
1280
1224
|
*/
|
|
@@ -1408,8 +1352,7 @@ class PDFDancer {
|
|
|
1408
1352
|
},
|
|
1409
1353
|
body: formData,
|
|
1410
1354
|
signal: AbortSignal.timeout(60000)
|
|
1411
|
-
}
|
|
1412
|
-
logGeneratedAtHeader(response, 'POST', '/font/register');
|
|
1355
|
+
});
|
|
1413
1356
|
if (!response.ok) {
|
|
1414
1357
|
const errorMessage = await this._extractErrorMessage(response);
|
|
1415
1358
|
throw new exceptions_1.HttpClientException(`Font registration failed: ${errorMessage}`, response);
|
|
@@ -1640,7 +1583,12 @@ class PDFDancer {
|
|
|
1640
1583
|
const elements = [];
|
|
1641
1584
|
if (Array.isArray(data.elements)) {
|
|
1642
1585
|
for (const elementData of data.elements) {
|
|
1643
|
-
|
|
1586
|
+
const element = this._parseObjectRef(elementData);
|
|
1587
|
+
// If the element's position doesn't have a pageIndex, inherit it from the page
|
|
1588
|
+
if (element.position && element.position.pageIndex === undefined) {
|
|
1589
|
+
element.position.pageIndex = pageRef.position.pageIndex;
|
|
1590
|
+
}
|
|
1591
|
+
elements.push(element);
|
|
1644
1592
|
}
|
|
1645
1593
|
}
|
|
1646
1594
|
return new models_1.PageSnapshot(pageRef, elements);
|
|
@@ -1661,6 +1609,9 @@ class PDFDancer {
|
|
|
1661
1609
|
newParagraph(pageIndex) {
|
|
1662
1610
|
return new paragraph_builder_1.ParagraphBuilder(this, pageIndex);
|
|
1663
1611
|
}
|
|
1612
|
+
newPath(pageIndex) {
|
|
1613
|
+
return new path_builder_1.PathBuilder(this, pageIndex);
|
|
1614
|
+
}
|
|
1664
1615
|
newPage() {
|
|
1665
1616
|
return new page_builder_1.PageBuilder(this);
|
|
1666
1617
|
}
|