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