pdfdancer-client-typescript 1.0.15 → 1.0.17

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 (65) hide show
  1. package/README.md +6 -3
  2. package/dist/image-builder.d.ts +1 -0
  3. package/dist/image-builder.d.ts.map +1 -1
  4. package/dist/image-builder.js +4 -0
  5. package/dist/image-builder.js.map +1 -1
  6. package/dist/pdfdancer_v1.d.ts +6 -0
  7. package/dist/pdfdancer_v1.d.ts.map +1 -1
  8. package/dist/pdfdancer_v1.js +52 -3
  9. package/dist/pdfdancer_v1.js.map +1 -1
  10. package/package.json +18 -2
  11. package/.claude/commands/discuss.md +0 -4
  12. package/.eslintrc.js +0 -27
  13. package/.github/workflows/ci.yml +0 -86
  14. package/.github/workflows/daily-tests.yml +0 -54
  15. package/NOTICE +0 -8
  16. package/docs/openapi.yml +0 -2640
  17. package/fixtures/DancingScript-Regular.ttf +0 -0
  18. package/fixtures/Empty.pdf +0 -0
  19. package/fixtures/JetBrainsMono-Regular.ttf +0 -0
  20. package/fixtures/ObviouslyAwesome.pdf +0 -0
  21. package/fixtures/README.md +0 -23
  22. package/fixtures/Showcase.pdf +0 -0
  23. package/fixtures/basic-paths.pdf +0 -0
  24. package/fixtures/form-xobject-example.pdf +0 -0
  25. package/fixtures/logo-80.png +0 -0
  26. package/fixtures/mixed-form-types.pdf +0 -0
  27. package/jest.config.js +0 -27
  28. package/scripts/release.js +0 -91
  29. package/scripts/test-release.js +0 -59
  30. package/src/__tests__/assertions.ts +0 -12
  31. package/src/__tests__/client-v1.test.ts +0 -70
  32. package/src/__tests__/e2e/acroform.test.ts +0 -166
  33. package/src/__tests__/e2e/context-manager-showcase.test.ts +0 -267
  34. package/src/__tests__/e2e/create-new.test.ts +0 -133
  35. package/src/__tests__/e2e/form_x_object.test.ts +0 -87
  36. package/src/__tests__/e2e/image-showcase.test.ts +0 -133
  37. package/src/__tests__/e2e/image.test.ts +0 -147
  38. package/src/__tests__/e2e/line-showcase.test.ts +0 -113
  39. package/src/__tests__/e2e/line.test.ts +0 -189
  40. package/src/__tests__/e2e/page-showcase.test.ts +0 -154
  41. package/src/__tests__/e2e/page.test.ts +0 -47
  42. package/src/__tests__/e2e/paragraph-showcase.test.ts +0 -515
  43. package/src/__tests__/e2e/paragraph.test.ts +0 -683
  44. package/src/__tests__/e2e/path.test.ts +0 -108
  45. package/src/__tests__/e2e/pdf-assertions.ts +0 -248
  46. package/src/__tests__/e2e/pdfdancer-showcase.test.ts +0 -40
  47. package/src/__tests__/e2e/snapshot-showcase.test.ts +0 -158
  48. package/src/__tests__/e2e/snapshot.test.ts +0 -296
  49. package/src/__tests__/e2e/test-helpers.ts +0 -152
  50. package/src/__tests__/e2e/token_from_env.test.ts +0 -80
  51. package/src/__tests__/fingerprint.test.ts +0 -36
  52. package/src/__tests__/retry-mechanism.test.ts +0 -420
  53. package/src/__tests__/standard-fonts.test.ts +0 -87
  54. package/src/__tests__/url-builder.test.ts +0 -44
  55. package/src/exceptions.ts +0 -63
  56. package/src/fingerprint.ts +0 -182
  57. package/src/image-builder.ts +0 -59
  58. package/src/index.ts +0 -49
  59. package/src/models.ts +0 -1051
  60. package/src/page-builder.ts +0 -130
  61. package/src/paragraph-builder.ts +0 -644
  62. package/src/pdfdancer_v1.ts +0 -2224
  63. package/src/types.ts +0 -407
  64. package/tsconfig.json +0 -20
  65. package/update-api-spec.sh +0 -3
@@ -1,683 +0,0 @@
1
- /**
2
- * E2E tests for paragraph operations — new PDFDancer API
3
- */
4
-
5
- import {Color, FontType, PDFDancer, StandardFonts} from '../../index';
6
- import {getFontPath, readFontFixture, requireEnvAndFixture} from './test-helpers';
7
- import {expectWithin} from '../assertions';
8
- import {PDFAssertions} from './pdf-assertions';
9
-
10
- describe('Paragraph E2E Tests (v2 API)', () => {
11
-
12
- test('find paragraphs by position', async () => {
13
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
14
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
15
-
16
- const paras = await pdf.selectParagraphs();
17
- expect(paras).toHaveLength(172);
18
-
19
- const parasPage0 = await pdf.page(0).selectParagraphs();
20
- expect(parasPage0).toHaveLength(2);
21
-
22
- const first = parasPage0[0];
23
- expect(first.internalId).toBe('PARAGRAPH_000003');
24
- expect(first.position).toBeDefined();
25
- expectWithin(first.position.boundingRect?.x, 326, 1);
26
- expectWithin(first.position.boundingRect?.y, 706, 1);
27
-
28
- const last = parasPage0[parasPage0.length - 1];
29
- expect(last.internalId).toBe('PARAGRAPH_000004');
30
- expect(last.position).toBeDefined();
31
- expectWithin(last.position.boundingRect?.x, 54, 1);
32
- expectWithin(last.position.boundingRect?.y, 496, 2);
33
-
34
- expect(last.objectRef().status).toBeDefined();
35
- expect(last.objectRef().status?.getFontType()).toBe(FontType.EMBEDDED);
36
- expect(last.objectRef().status?.isModified()).toBe(false);
37
- });
38
-
39
- test('find paragraphs by text', async () => {
40
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
41
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
42
-
43
- const paras = await pdf.page(0).selectParagraphsStartingWith('The Complete');
44
- expect(paras).toHaveLength(1);
45
-
46
- const p = paras[0];
47
- expect(p.internalId).toBe('PARAGRAPH_000004');
48
- expect(p.position).toBeDefined();
49
- expectWithin(p.position.boundingRect?.x, 54, 1);
50
- expectWithin(p.position.boundingRect?.y, 496, 2);
51
- });
52
-
53
- test('find paragraphs by pattern', async () => {
54
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
55
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
56
-
57
- const paras = await pdf.page(0).selectParagraphsMatching('.*Complete.*');
58
- expect(paras).toHaveLength(1);
59
- const p = paras[0];
60
- expect(p.internalId).toBe('PARAGRAPH_000004');
61
-
62
- const paras2 = await pdf.page(0).selectParagraphsMatching('.*NOT FOUND.*');
63
- expect(paras2).toHaveLength(0);
64
-
65
- const paras3 = await pdf.page(0).selectParagraphsMatching('.*');
66
- expect(paras3).toHaveLength(2);
67
- });
68
-
69
- test('delete paragraph', async () => {
70
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
71
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
72
-
73
- const [target] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
74
- await target.delete();
75
-
76
- const remaining = await pdf.page(0).selectParagraphsStartingWith('The Complete');
77
- expect(remaining).toHaveLength(0);
78
- });
79
-
80
- test('move paragraph', async () => {
81
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
82
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
83
-
84
- const [para] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
85
- await para.moveTo(0.1, 300);
86
-
87
- const moved = await pdf.page(0).selectParagraphsAt(0.1, 300, 1);
88
- expect(moved.length).toBeGreaterThan(0);
89
- });
90
-
91
- async function assertNewParagraphExists(pdf: PDFDancer) {
92
- const lines = await pdf.page(0).selectTextLinesStartingWith('Awesomely');
93
- expect(lines.length).toBeGreaterThanOrEqual(1);
94
- }
95
-
96
- test('modify paragraph', async () => {
97
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
98
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
99
-
100
- const [para] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
101
-
102
- await para.edit().replace('Awesomely\nObvious!')
103
- .font("Helvetica", 12)
104
- .lineSpacing(0.7)
105
- .moveTo(300.1, 500)
106
- .apply()
107
-
108
- await assertNewParagraphExists(pdf);
109
-
110
- const movedParas = await pdf.page(0).selectParagraphsAt(300.1, 500);
111
- expect(movedParas.length).toBeGreaterThan(0);
112
- const moved = movedParas[0];
113
- expect(moved.objectRef().status).toBeDefined();
114
- expect(moved.objectRef().status?.getFontType()).toBe(FontType.STANDARD);
115
- expect(moved.objectRef().status?.isModified()).toBe(true);
116
-
117
- const assertions = await PDFAssertions.create(pdf);
118
- await assertions.assertTextlineHasFont('Awesomely', 'Helvetica', 12, 0);
119
- await assertions.assertTextlineHasFont('Obvious!', 'Helvetica', 12, 0);
120
- await assertions.assertTextlineHasColor('Awesomely', new Color(255, 255, 255), 0);
121
- await assertions.assertTextlineHasColor('Obvious!', new Color(255, 255, 255), 0);
122
- await assertions.assertParagraphIsAt('Awesomely', 300.1, 500, 0);
123
- });
124
-
125
- test('modify paragraph (simple)', async () => {
126
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
127
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
128
-
129
- const [para] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
130
- const result = await para.edit().replace('Awesomely\nObvious!').apply();
131
-
132
- // This should issue a warning about an embedded font modification
133
- expect(typeof result).toBe('object');
134
- expect((result as any).warning).toBeDefined();
135
- expect((result as any).warning).toBe("Text is not encodable with your current font, we are using 'Poppins-Bold' as a fallback font instead.");
136
-
137
- await assertNewParagraphExists(pdf);
138
-
139
- const modifiedParas = await pdf.page(0).selectParagraphsStartingWith('Awesomely');
140
- expect(modifiedParas.length).toBeGreaterThan(0);
141
- const modified = modifiedParas[0];
142
- expect(modified.objectRef().status).toBeDefined();
143
- expect(modified.objectRef().status?.getFontType()).toBe(FontType.EMBEDDED);
144
- expect(modified.objectRef().status?.isModified()).toBe(true);
145
-
146
- const assertions = await PDFAssertions.create(pdf);
147
- await assertions.assertTextlineHasFontMatching('Awesomely', 'Poppins-Bold', 45, 0);
148
- await assertions.assertTextlineHasFontMatching('Obvious!', 'Poppins-Bold', 45, 0);
149
- await assertions.assertTextlineHasColor('Awesomely', new Color(255, 255, 255), 0);
150
- await assertions.assertTextlineHasColor('Obvious!', new Color(255, 255, 255), 0);
151
- });
152
-
153
- test('add paragraph with missing font (expect error)', async () => {
154
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
155
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
156
-
157
- await expect(
158
- pdf.page(0).newParagraph()
159
- .text('Awesomely\nObvious!')
160
- .font('Roboto', 14)
161
- .lineSpacing(0.7)
162
- .at(300.1, 500)
163
- .apply()
164
- ).rejects.toThrow('Font not found');
165
- });
166
-
167
- test('add paragraph with known font', async () => {
168
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
169
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
170
-
171
- const success = await pdf.page(0).newParagraph()
172
- .text('Awesomely\nObvious!')
173
- .font('Roboto-Regular', 14)
174
- .lineSpacing(0.7)
175
- .at(300.1, 500)
176
- .apply()
177
-
178
- expect(success).toBe(true);
179
- await assertNewParagraphExists(pdf);
180
- });
181
-
182
- test('add paragraph using font lookup', async () => {
183
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
184
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
185
-
186
- const fonts = await pdf.findFonts('Roboto', 14);
187
- expect(fonts.length).toBeGreaterThan(0);
188
- const roboto = fonts[0];
189
-
190
- const success = await pdf.page(0).newParagraph()
191
- .text('Awesomely\nObvious!')
192
- .font(roboto)
193
- .lineSpacing(0.7)
194
- .at(300.1, 500)
195
- .apply();
196
-
197
- expect(success).toBe(true);
198
- await assertNewParagraphExists(pdf);
199
- });
200
-
201
- test('add paragraph with Asimovian font', async () => {
202
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
203
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
204
-
205
- const fonts = await pdf.findFonts('Asimovian', 14);
206
- expect(fonts.length).toBeGreaterThan(0);
207
- const asimovian = fonts[0];
208
-
209
- const success = await pdf.page(0).newParagraph()
210
- .text('Awesomely\nObvious!')
211
- .font(asimovian)
212
- .lineSpacing(0.7)
213
- .at(300.1, 500)
214
- .apply();
215
-
216
- expect(success).toBe(true);
217
- await assertNewParagraphExists(pdf);
218
- });
219
-
220
- test('add paragraph with custom TTF font', async () => {
221
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
222
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
223
-
224
- const ttf = readFontFixture('DancingScript-Regular.ttf');
225
-
226
- const success = await pdf.page(0).newParagraph()
227
- .text('Awesomely\nObvious!')
228
- .fontFile(ttf, 24)
229
- .lineSpacing(1.8)
230
- .color(new Color(0, 0, 255))
231
- .at(300.1, 500)
232
- .apply();
233
-
234
- expect(success).toBe(true);
235
- await assertNewParagraphExists(pdf);
236
- });
237
-
238
- test('add paragraph with custom TTF font from filename', async () => {
239
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
240
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
241
-
242
- const pathToFontFile = getFontPath('DancingScript-Regular.ttf');
243
-
244
- const success = await pdf.page(0).newParagraph()
245
- .text('Awesomely\nObvious!')
246
- .fontFile(pathToFontFile, 24)
247
- .lineSpacing(1.8)
248
- .color(new Color(0, 0, 255))
249
- .at(300.1, 500)
250
- .apply();
251
-
252
- expect(success).toBe(true);
253
- await assertNewParagraphExists(pdf);
254
- });
255
-
256
- test('add paragraph with standard font - Helvetica', async () => {
257
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
258
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
259
-
260
- const success = await pdf.page(0).newParagraph()
261
- .text('Standard Font Test\nHelvetica')
262
- .font(StandardFonts.HELVETICA, 14)
263
- .lineSpacing(1.2)
264
- .at(100, 600)
265
- .apply();
266
-
267
- expect(success).toBe(true);
268
- const lines = await pdf.page(0).selectTextLinesStartingWith('Standard Font Test');
269
- expect(lines.length).toBeGreaterThanOrEqual(1);
270
- });
271
-
272
- test('add paragraph with standard font - Times Bold', async () => {
273
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
274
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
275
-
276
- const success = await pdf.page(0).newParagraph()
277
- .text('Times Bold Test')
278
- .font(StandardFonts.TIMES_BOLD, 16)
279
- .color(new Color(255, 0, 0))
280
- .at(100, 550)
281
- .apply();
282
-
283
- expect(success).toBe(true);
284
- const lines = await pdf.page(0).selectTextLinesStartingWith('Times Bold Test');
285
- expect(lines.length).toBeGreaterThanOrEqual(1);
286
- });
287
-
288
- test('add paragraph with standard font - Courier', async () => {
289
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
290
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
291
-
292
- const success = await pdf.page(0).newParagraph()
293
- .text('Courier Monospace\nCode Example')
294
- .font(StandardFonts.COURIER, 12)
295
- .lineSpacing(1.5)
296
- .at(100, 500)
297
- .apply();
298
-
299
- expect(success).toBe(true);
300
- const lines = await pdf.page(0).selectTextLinesStartingWith('Courier Monospace');
301
- expect(lines.length).toBeGreaterThanOrEqual(1);
302
- });
303
-
304
-
305
- test('modify paragraph without position', async () => {
306
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
307
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
308
-
309
- const [para] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
310
- let originalX = para.position.getX();
311
- let originalY = para.position.getY();
312
-
313
- await para.edit()
314
- .replace('Modified with\nStandard Font')
315
- .font(StandardFonts.HELVETICA_BOLD, 14)
316
- .lineSpacing(1.3)
317
- .apply();
318
-
319
- const [newPara] = await pdf.page(0).selectParagraphsStartingWith('Modified with');
320
- // TODO should be at the original position
321
- expect(newPara.position.getX()).toBe(originalX);
322
- expect(newPara.position.getY()).toBe(originalY);
323
- });
324
-
325
- test('modify paragraph without position and lineSpacing', async () => {
326
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
327
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
328
-
329
- const [para] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
330
- let originalX = para.position.getX();
331
- let originalY = para.position.getY();
332
-
333
- await para.edit()
334
- .replace('Modified with\nStandard Font')
335
- .font(StandardFonts.HELVETICA_BOLD, 14)
336
- .apply();
337
-
338
- const [newPara] = await pdf.page(0).selectParagraphsStartingWith('Modified with');
339
- // TODO should be at the original position
340
- expect(newPara.position.getX()).toBe(originalX);
341
- expect(newPara.position.getY()).toBe(originalY);
342
- });
343
-
344
- test('modify paragraph only change font', async () => {
345
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
346
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
347
-
348
- const [para] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
349
- let originalX = para.position.getX();
350
- let originalY = para.position.getY();
351
-
352
- await para.edit()
353
- .font(StandardFonts.HELVETICA_BOLD, 28)
354
- .apply();
355
-
356
- const [newPara] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
357
- // TODO should be at the original position
358
- expect(newPara.position.getX()).toBe(originalX);
359
- expect(newPara.position.getY()).toBe(originalY);
360
- });
361
-
362
- test('add paragraph without position', async () => {
363
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
364
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
365
-
366
- await expect(pdf.page(0).newParagraph()
367
- .text('Courier Monospace\nCode Example')
368
- .font(StandardFonts.COURIER, 12)
369
- .lineSpacing(1.5)
370
- .apply())
371
- .rejects
372
- .toThrow("Paragraph position is null, you need to specify a position for the new paragraph, using .at(x,y)");
373
- });
374
-
375
- test('modify paragraph to use standard font', async () => {
376
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
377
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
378
-
379
- const [para] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
380
-
381
- await para.edit()
382
- .replace('Modified with\nStandard Font')
383
- .font(StandardFonts.HELVETICA_BOLD, 14)
384
- .lineSpacing(1.3)
385
- .moveTo(100, 400)
386
- .apply();
387
-
388
- const lines = await pdf.page(0).selectTextLinesStartingWith('Modified with');
389
- expect(lines.length).toBeGreaterThanOrEqual(1);
390
- });
391
-
392
- test('use all Times family standard fonts', async () => {
393
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
394
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
395
-
396
- const timesFonts = [
397
- StandardFonts.TIMES_ROMAN,
398
- StandardFonts.TIMES_BOLD,
399
- StandardFonts.TIMES_ITALIC,
400
- StandardFonts.TIMES_BOLD_ITALIC
401
- ];
402
-
403
- for (let i = 0; i < timesFonts.length; i++) {
404
- const success = await pdf.page(0).newParagraph()
405
- .text(`Times Font ${i}`)
406
- .font(timesFonts[i], 12)
407
- .at(50, 700 - (i * 30))
408
- .apply();
409
- expect(success).toBe(true);
410
- }
411
-
412
- const lines = await pdf.page(0).selectTextLinesStartingWith('Times Font');
413
- expect(lines.length).toBe(4);
414
- });
415
-
416
- test('use all Helvetica family standard fonts', async () => {
417
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
418
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
419
-
420
- const helveticaFonts = [
421
- StandardFonts.HELVETICA,
422
- StandardFonts.HELVETICA_BOLD,
423
- StandardFonts.HELVETICA_OBLIQUE,
424
- StandardFonts.HELVETICA_BOLD_OBLIQUE
425
- ];
426
-
427
- for (let i = 0; i < helveticaFonts.length; i++) {
428
- const success = await pdf.page(0).newParagraph()
429
- .text(`Helvetica Font ${i}`)
430
- .font(helveticaFonts[i], 12)
431
- .at(200, 700 - (i * 30))
432
- .apply();
433
- expect(success).toBe(true);
434
- }
435
-
436
- const lines = await pdf.page(0).selectTextLinesStartingWith('Helvetica Font');
437
- expect(lines.length).toBe(4);
438
- });
439
-
440
-
441
- test('modify paragraph with assertions', async () => {
442
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
443
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
444
-
445
- const [para] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
446
-
447
- await para.edit().replace('Awesomely\nObvious!')
448
- .font("Helvetica", 12)
449
- .lineSpacing(0.7)
450
- .moveTo(300.1, 500)
451
- .apply();
452
-
453
- const assertions = await PDFAssertions.create(pdf);
454
- await assertions.assertTextlineHasFont('Awesomely', 'Helvetica', 12, 0);
455
- await assertions.assertTextlineHasFont('Obvious!', 'Helvetica', 12, 0);
456
- await assertions.assertTextlineHasColor('Awesomely', new Color(255, 255, 255), 0);
457
- await assertions.assertTextlineHasColor('Obvious!', new Color(255, 255, 255), 0);
458
- await assertions.assertParagraphIsAt('Awesomely', 300.1, 500, 0);
459
- });
460
-
461
- test('modify paragraph without position', async () => {
462
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
463
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
464
-
465
- const [para] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
466
- let originalX = para.position.getX();
467
- let originalY = para.position.getY();
468
-
469
- await para.edit()
470
- .replace('Awesomely\nObvious!')
471
- .font('Helvetica', 12)
472
- .lineSpacing(0.7)
473
- .apply();
474
-
475
- const assertions = await PDFAssertions.create(pdf);
476
- await assertions.assertTextlineHasFont('Awesomely', 'Helvetica', 12, 0);
477
- await assertions.assertTextlineHasFont('Obvious!', 'Helvetica', 12, 0);
478
- await assertions.assertTextlineHasColor('Awesomely', new Color(255, 255, 255), 0);
479
- await assertions.assertTextlineHasColor('Obvious!', new Color(255, 255, 255), 0);
480
- await assertions.assertParagraphIsAt('Awesomely', originalX!, originalY!, 0);
481
- });
482
-
483
- test('modify paragraph without position and spacing', async () => {
484
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
485
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
486
-
487
- const [para] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
488
- let originalX = para.position.getX();
489
- let originalY = para.position.getY();
490
-
491
- await para.edit()
492
- .replace('Awesomely\nObvious!')
493
- .font('Helvetica', 12)
494
- .apply();
495
-
496
- const assertions = await PDFAssertions.create(pdf);
497
- await assertions.assertTextlineHasFont('Awesomely', 'Helvetica', 12, 0);
498
- await assertions.assertTextlineHasFont('Obvious!', 'Helvetica', 12, 0);
499
- await assertions.assertTextlineHasColor('Awesomely', new Color(255, 255, 255), 0);
500
- await assertions.assertTextlineHasColor('Obvious!', new Color(255, 255, 255), 0);
501
- await assertions.assertParagraphIsAt('Awesomely', originalX!, originalY!, 0);
502
- });
503
-
504
- test('modify paragraph only font', async () => {
505
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
506
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
507
-
508
- const [para] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
509
-
510
- await para.edit()
511
- .font('Helvetica', 28)
512
- .apply();
513
-
514
- const assertions = await PDFAssertions.create(pdf);
515
- await assertions.assertTextlineHasFont('The Complete', 'Helvetica', 28, 0);
516
- await assertions.assertTextlineHasColor('The Complete', new Color(255, 255, 255), 0);
517
- });
518
-
519
- test('modify paragraph only move', async () => {
520
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
521
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
522
-
523
- const [para] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
524
-
525
- await para.edit()
526
- .moveTo(40, 40)
527
- .apply();
528
-
529
- const assertions = await PDFAssertions.create(pdf);
530
- await assertions.assertTextlineHasFont('The Complete', 'IXKSWR+Poppins-Bold', 45, 0);
531
- await assertions.assertParagraphIsAt('The Complete', 40, 40, 0, 0.22);
532
- await assertions.assertTextlineHasColor('The Complete', new Color(255, 255, 255), 0);
533
- });
534
-
535
- test('modify paragraph simple', async () => {
536
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
537
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
538
-
539
- const [para] = await pdf.page(0).selectParagraphsStartingWith('The Complete');
540
- await para.edit().replace('Awesomely\nObvious!').apply();
541
-
542
- const assertions = await PDFAssertions.create(pdf);
543
- await assertions.assertTextlineHasFontMatching('Awesomely', 'Poppins-Bold', 45, 0);
544
- await assertions.assertTextlineHasFontMatching('Obvious!', 'Poppins-Bold', 45, 0);
545
- await assertions.assertTextlineHasColor('Awesomely', new Color(255, 255, 255), 0);
546
- await assertions.assertTextlineHasColor('Obvious!', new Color(255, 255, 255), 0);
547
- });
548
-
549
- test('add paragraph with standard font Times Roman', async () => {
550
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
551
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
552
-
553
- await pdf.page(0).newParagraph()
554
- .text('Times Roman Test')
555
- .font(StandardFonts.TIMES_ROMAN, 14)
556
- .at(150, 150)
557
- .apply();
558
-
559
- const assertions = await PDFAssertions.create(pdf);
560
- await assertions.assertTextHasFont('Times Roman Test', StandardFonts.TIMES_ROMAN, 14, 0);
561
- await assertions.assertParagraphIsAt('Times Roman Test', 150, 150, 0);
562
- });
563
-
564
- test('add paragraph with standard font Courier Bold', async () => {
565
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
566
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
567
-
568
- await pdf.page(0).newParagraph()
569
- .text('Courier Monospace\nCode Example')
570
- .font(StandardFonts.COURIER_BOLD, 12)
571
- .lineSpacing(1.5)
572
- .at(200, 200)
573
- .apply();
574
-
575
- const assertions = await PDFAssertions.create(pdf);
576
- await assertions.assertTextHasFont('Courier Monospace', StandardFonts.COURIER_BOLD, 12, 0);
577
- await assertions.assertParagraphIsAt('Courier Monospace', 200, 200, 0);
578
- });
579
-
580
- test('paragraph color reading', async () => {
581
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
582
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
583
-
584
- await pdf.page(0).newParagraph()
585
- .text('Red Color Test')
586
- .font(StandardFonts.HELVETICA, 14)
587
- .color(new Color(255, 0, 0))
588
- .at(100, 100)
589
- .apply();
590
-
591
- await pdf.page(0).newParagraph()
592
- .text('Blue Color Test')
593
- .font(StandardFonts.HELVETICA, 14)
594
- .color(new Color(0, 0, 255))
595
- .at(100, 120)
596
- .apply();
597
-
598
- const assertions = await PDFAssertions.create(pdf);
599
- await assertions.assertTextlineHasColor('Blue Color Test', new Color(0, 0, 255), 0);
600
- await assertions.assertTextlineHasColor('Red Color Test', new Color(255, 0, 0), 0);
601
- });
602
-
603
- test('add paragraph to new page', async () => {
604
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('Empty.pdf');
605
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
606
-
607
- await pdf.page(0).newParagraph()
608
- .text('Awesome')
609
- .font('Roboto-Regular', 14)
610
- .at(50, 100)
611
- .apply();
612
-
613
- const assertions = await PDFAssertions.create(pdf);
614
- await assertions.assertTextlineHasFontMatching('Awesome', 'Roboto-Regular', 14, 0);
615
- await assertions.assertTextlineHasColor('Awesome', new Color(0, 0, 0), 0);
616
- await assertions.assertParagraphIsAt('Awesome', 50, 100, 0);
617
- });
618
-
619
- test('Symbol and ZapfDingbats fonts are available as standard fonts', () => {
620
- expect(StandardFonts.SYMBOL).toBe('Symbol');
621
- expect(StandardFonts.ZAPF_DINGBATS).toBe('ZapfDingbats');
622
- });
623
-
624
- // Tests for singular select methods
625
- test('selectParagraph returns first paragraph or null', async () => {
626
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
627
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
628
-
629
- // Test with results
630
- const para = await pdf.page(0).selectParagraph();
631
- expect(para).not.toBeNull();
632
- expect(para!.internalId).toBe('PARAGRAPH_000003');
633
-
634
- // Test with PDFDancer class
635
- const paraFromPdf = await pdf.selectParagraph();
636
- expect(paraFromPdf).not.toBeNull();
637
- expect(paraFromPdf!.internalId).toBe('PARAGRAPH_000003');
638
- });
639
-
640
- test('selectParagraphStartingWith returns first match or null', async () => {
641
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
642
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
643
-
644
- const para = await pdf.page(0).selectParagraphStartingWith('The Complete');
645
- expect(para).not.toBeNull();
646
- expect(para!.internalId).toBe('PARAGRAPH_000004');
647
-
648
- // Test with no match
649
- const noMatch = await pdf.page(0).selectParagraphStartingWith('NoMatch');
650
- expect(noMatch).toBeNull();
651
- });
652
-
653
- test('selectParagraphMatching returns first match or null', async () => {
654
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
655
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
656
-
657
- const para = await pdf.page(0).selectParagraphMatching('.*Complete.*');
658
- expect(para).not.toBeNull();
659
- expect(para!.internalId).toBe('PARAGRAPH_000004');
660
-
661
- // Test with PDFDancer class
662
- const paraFromPdf = await pdf.selectParagraphMatching('.*Complete.*');
663
- expect(paraFromPdf).not.toBeNull();
664
-
665
- // Test with no match
666
- const noMatch = await pdf.page(0).selectParagraphMatching('.*NOT FOUND.*');
667
- expect(noMatch).toBeNull();
668
- });
669
-
670
- test('selectParagraphAt returns first paragraph at position or null', async () => {
671
- const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
672
- const pdf = await PDFDancer.open(pdfData, token, baseUrl);
673
-
674
- const para = await pdf.page(0).selectParagraphAt(54, 496, 10);
675
- expect(para).not.toBeNull();
676
- expect(para!.internalId).toBe('PARAGRAPH_000004');
677
-
678
- // Test with no match
679
- const noMatch = await pdf.page(0).selectParagraphAt(1000, 1000, 1);
680
- expect(noMatch).toBeNull();
681
- });
682
-
683
- });