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.
- package/.github/workflows/ci.yml +37 -0
- package/README.md +60 -64
- package/dist/__tests__/assertions.d.ts +2 -0
- package/dist/__tests__/assertions.d.ts.map +1 -0
- package/dist/__tests__/assertions.js +11 -0
- package/dist/__tests__/assertions.js.map +1 -0
- package/dist/client-v1.d.ts +3 -24
- package/dist/client-v1.d.ts.map +1 -1
- package/dist/client-v1.js +6 -23
- package/dist/client-v1.js.map +1 -1
- package/dist/exceptions.d.ts +0 -3
- package/dist/exceptions.d.ts.map +1 -1
- package/dist/exceptions.js +0 -3
- package/dist/exceptions.js.map +1 -1
- package/dist/models.d.ts +7 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +28 -13
- package/dist/models.js.map +1 -1
- package/dist/paragraph-builder.d.ts +0 -8
- package/dist/paragraph-builder.d.ts.map +1 -1
- package/dist/paragraph-builder.js +0 -8
- package/dist/paragraph-builder.js.map +1 -1
- package/example.ts +6 -10
- package/fixtures/form-xobject-example.pdf +0 -0
- package/jest.config.js +25 -24
- package/package.json +1 -1
- package/src/__tests__/assertions.ts +12 -0
- package/src/__tests__/client-v1.test.ts +6 -6
- package/src/__tests__/e2e/form.test.ts +42 -44
- package/src/__tests__/e2e/image.test.ts +97 -101
- package/src/__tests__/e2e/line.test.ts +115 -127
- package/src/__tests__/e2e/page.test.ts +3 -6
- package/src/__tests__/e2e/paragraph.test.ts +187 -204
- package/src/__tests__/e2e/path.test.ts +12 -16
- package/src/client-v1.ts +575 -591
- package/src/exceptions.ts +27 -30
- package/src/models.ts +382 -355
- package/src/paragraph-builder.ts +0 -8
|
@@ -2,209 +2,192 @@
|
|
|
2
2
|
* E2E tests for paragraph operations
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { requireEnvAndFixture
|
|
5
|
+
import {ClientV1, Color, Font, Position} from '../../index';
|
|
6
|
+
import {readFontFixture, requireEnvAndFixture} from './test-helpers';
|
|
7
|
+
import {expectWithin} from "../assertions";
|
|
7
8
|
|
|
8
9
|
describe('Paragraph E2E Tests', () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const client = new ClientV1(token, pdfData, baseUrl, 30000);
|
|
194
|
-
await client.init();
|
|
195
|
-
|
|
196
|
-
// Use DancingScript-Regular.ttf from fixtures directory
|
|
197
|
-
const ttfData = readFontFixture('DancingScript-Regular.ttf');
|
|
198
|
-
|
|
199
|
-
const pb = client.paragraphBuilder()
|
|
200
|
-
.fromString('Awesomely\\nObvious!')
|
|
201
|
-
.withLineSpacing(1.8)
|
|
202
|
-
.withColor(new Color(0, 0, 255))
|
|
203
|
-
.withPosition(Position.onPageCoordinates(0, 300.1, 500));
|
|
204
|
-
|
|
205
|
-
await pb.withFontFile(ttfData, 24);
|
|
206
|
-
|
|
207
|
-
expect(await client.addParagraph(pb.build())).toBe(true);
|
|
208
|
-
await assertNewParagraphExists(client);
|
|
209
|
-
});
|
|
210
|
-
});
|
|
10
|
+
// Tests should fail properly if environment is not configured
|
|
11
|
+
|
|
12
|
+
test('find paragraphs by position', async () => {
|
|
13
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
14
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
15
|
+
|
|
16
|
+
const paras = await client.findParagraphs();
|
|
17
|
+
expect(paras).toHaveLength(172);
|
|
18
|
+
|
|
19
|
+
const parasPage0 = await client.findParagraphs(Position.atPage(0));
|
|
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
|
+
|
|
35
|
+
test('find paragraphs by text', async () => {
|
|
36
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
37
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
38
|
+
|
|
39
|
+
const pos = Position.atPage(0).withTextStarts('The Complete');
|
|
40
|
+
const paras = await client.findParagraphs(pos);
|
|
41
|
+
expect(paras).toHaveLength(1);
|
|
42
|
+
|
|
43
|
+
const p = paras[0];
|
|
44
|
+
expect(p.internalId).toBe('PARAGRAPH_000004');
|
|
45
|
+
expect(p.position).toBeDefined();
|
|
46
|
+
expectWithin(p.position.boundingRect?.x, 54, 1);
|
|
47
|
+
expectWithin(p.position.boundingRect?.y, 496, 2);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('delete paragraph', async () => {
|
|
51
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
52
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
53
|
+
|
|
54
|
+
const posDel = Position.atPage(0).withTextStarts('The Complete');
|
|
55
|
+
const ref = (await client.findParagraphs(posDel))[0];
|
|
56
|
+
expect(await client.delete(ref)).toBe(true);
|
|
57
|
+
|
|
58
|
+
const posDel2 = Position.atPage(0).withTextStarts('The Complete');
|
|
59
|
+
expect(await client.findParagraphs(posDel2)).toHaveLength(0);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('move paragraph', async () => {
|
|
63
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
64
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
65
|
+
|
|
66
|
+
const posMove = Position.atPage(0).withTextStarts('The Complete');
|
|
67
|
+
const ref = (await client.findParagraphs(posMove))[0];
|
|
68
|
+
const newPos = Position.atPageCoordinates(0, 0.1, 300);
|
|
69
|
+
expect(await client.move(ref, newPos)).toBe(true);
|
|
70
|
+
|
|
71
|
+
const ref2 = (await client.findParagraphs(newPos))[0];
|
|
72
|
+
expect(ref2).toBeDefined();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
async function assertNewParagraphExists(client: ClientV1): Promise<void> {
|
|
76
|
+
// Validate via find_text_lines for text starting with 'Awesomely'
|
|
77
|
+
const pos = Position.atPage(0).withTextStarts('Awesomely');
|
|
78
|
+
const lines = await client.findTextLines(pos);
|
|
79
|
+
expect(lines.length).toBeGreaterThanOrEqual(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
test('modify paragraph', async () => {
|
|
83
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
84
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
85
|
+
|
|
86
|
+
const posMod = Position.atPage(0).withTextStarts('The Complete');
|
|
87
|
+
const ref = (await client.findParagraphs(posMod))[0];
|
|
88
|
+
|
|
89
|
+
const newParagraph = client.paragraphBuilder()
|
|
90
|
+
.fromString('Awesomely\\nObvious!')
|
|
91
|
+
.withFont(new Font('Helvetica', 14))
|
|
92
|
+
.withLineSpacing(0.7)
|
|
93
|
+
.withPosition(Position.atPageCoordinates(0, 300.1, 500))
|
|
94
|
+
.build();
|
|
95
|
+
|
|
96
|
+
expect(await client.modifyParagraph(ref, newParagraph)).toBe(true);
|
|
97
|
+
await assertNewParagraphExists(client);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('modify paragraph simple', async () => {
|
|
101
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
102
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
103
|
+
|
|
104
|
+
const posMod2 = Position.atPage(0).withTextStarts('The Complete');
|
|
105
|
+
const ref = (await client.findParagraphs(posMod2))[0];
|
|
106
|
+
expect(await client.modifyParagraph(ref, 'Awesomely\\nObvious!')).toBe(true);
|
|
107
|
+
await assertNewParagraphExists(client);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test('add paragraph with custom font - expect not found', async () => {
|
|
111
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
112
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
113
|
+
|
|
114
|
+
const pb = client.paragraphBuilder()
|
|
115
|
+
.fromString('Awesomely\\nObvious!')
|
|
116
|
+
.withFont(new Font('Roboto', 14))
|
|
117
|
+
.withLineSpacing(0.7)
|
|
118
|
+
.withPosition(Position.atPageCoordinates(0, 300.1, 500));
|
|
119
|
+
|
|
120
|
+
await expect(client.addParagraph(pb.build())).rejects.toThrow('Font not found');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('add paragraph with custom font - Roboto-Regular', async () => {
|
|
124
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
125
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
126
|
+
|
|
127
|
+
const pb = client.paragraphBuilder()
|
|
128
|
+
.fromString('Awesomely\\nObvious!')
|
|
129
|
+
.withFont(new Font('Roboto-Regular', 14))
|
|
130
|
+
.withLineSpacing(0.7)
|
|
131
|
+
.withPosition(Position.atPageCoordinates(0, 300.1, 500));
|
|
132
|
+
|
|
133
|
+
expect(await client.addParagraph(pb.build())).toBe(true);
|
|
134
|
+
await assertNewParagraphExists(client);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('add paragraph with found font', async () => {
|
|
138
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
139
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
140
|
+
|
|
141
|
+
const fonts = await client.findFonts('Roboto', 14);
|
|
142
|
+
expect(fonts.length).toBeGreaterThan(0);
|
|
143
|
+
expect(fonts[0].name).toBe('Roboto-Regular');
|
|
144
|
+
|
|
145
|
+
const roboto = fonts[0];
|
|
146
|
+
const pb = client.paragraphBuilder()
|
|
147
|
+
.fromString('Awesomely\\nObvious!')
|
|
148
|
+
.withFont(roboto)
|
|
149
|
+
.withLineSpacing(0.7)
|
|
150
|
+
.withPosition(Position.atPageCoordinates(0, 300.1, 500));
|
|
151
|
+
|
|
152
|
+
expect(await client.addParagraph(pb.build())).toBe(true);
|
|
153
|
+
await assertNewParagraphExists(client);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('add paragraph with Asimovian font', async () => {
|
|
157
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
158
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
159
|
+
|
|
160
|
+
const fonts = await client.findFonts('Asimovian', 14);
|
|
161
|
+
expect(fonts.length).toBeGreaterThan(0);
|
|
162
|
+
expect(fonts[0].name).toBe('Asimovian-Regular');
|
|
163
|
+
|
|
164
|
+
const asimovian = fonts[0];
|
|
165
|
+
const pb = client.paragraphBuilder()
|
|
166
|
+
.fromString('Awesomely\\nObvious!')
|
|
167
|
+
.withFont(asimovian)
|
|
168
|
+
.withLineSpacing(0.7)
|
|
169
|
+
.withPosition(Position.atPageCoordinates(0, 300.1, 500));
|
|
170
|
+
|
|
171
|
+
expect(await client.addParagraph(pb.build())).toBe(true);
|
|
172
|
+
await assertNewParagraphExists(client);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('add paragraph with custom TTF font', async () => {
|
|
176
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
177
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
178
|
+
|
|
179
|
+
// Use DancingScript-Regular.ttf from fixtures directory
|
|
180
|
+
const ttfData = readFontFixture('DancingScript-Regular.ttf');
|
|
181
|
+
|
|
182
|
+
const pb = client.paragraphBuilder()
|
|
183
|
+
.fromString('Awesomely\\nObvious!')
|
|
184
|
+
.withLineSpacing(1.8)
|
|
185
|
+
.withColor(new Color(0, 0, 255))
|
|
186
|
+
.withPosition(Position.atPageCoordinates(0, 300.1, 500));
|
|
187
|
+
|
|
188
|
+
await pb.withFontFile(ttfData, 24);
|
|
189
|
+
|
|
190
|
+
expect(await client.addParagraph(pb.build())).toBe(true);
|
|
191
|
+
await assertNewParagraphExists(client);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -10,8 +10,7 @@ describe('Path E2E Tests', () => {
|
|
|
10
10
|
|
|
11
11
|
test('find paths', async () => {
|
|
12
12
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('basic-paths.pdf');
|
|
13
|
-
const client =
|
|
14
|
-
await client.init();
|
|
13
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
15
14
|
|
|
16
15
|
const paths = await client.findPaths();
|
|
17
16
|
expect(paths).toHaveLength(9);
|
|
@@ -26,47 +25,44 @@ describe('Path E2E Tests', () => {
|
|
|
26
25
|
|
|
27
26
|
test('find paths by position', async () => {
|
|
28
27
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('basic-paths.pdf');
|
|
29
|
-
const client =
|
|
30
|
-
await client.init();
|
|
28
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
31
29
|
|
|
32
|
-
const paths = await client.findPaths(Position.
|
|
30
|
+
const paths = await client.findPaths(Position.atPageCoordinates(0, 80, 720));
|
|
33
31
|
expect(paths).toHaveLength(1);
|
|
34
32
|
expect(paths[0].internalId).toBe('PATH_000001');
|
|
35
33
|
});
|
|
36
34
|
|
|
37
35
|
test('delete path', async () => {
|
|
38
36
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('basic-paths.pdf');
|
|
39
|
-
const client =
|
|
40
|
-
await client.init();
|
|
37
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
41
38
|
|
|
42
|
-
let paths = await client.findPaths(Position.
|
|
39
|
+
let paths = await client.findPaths(Position.atPageCoordinates(0, 80, 720));
|
|
43
40
|
expect(paths).toHaveLength(1);
|
|
44
41
|
expect(paths[0].internalId).toBe('PATH_000001');
|
|
45
42
|
expect(await client.delete(paths[0])).toBe(true);
|
|
46
43
|
|
|
47
|
-
expect(await client.findPaths(Position.
|
|
44
|
+
expect(await client.findPaths(Position.atPageCoordinates(0, 80, 720))).toHaveLength(0);
|
|
48
45
|
expect(await client.findPaths()).toHaveLength(8);
|
|
49
46
|
});
|
|
50
47
|
|
|
51
48
|
test('move path', async () => {
|
|
52
49
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('basic-paths.pdf');
|
|
53
|
-
const client =
|
|
54
|
-
await client.init();
|
|
50
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
55
51
|
|
|
56
|
-
let paths = await client.findPaths(Position.
|
|
52
|
+
let paths = await client.findPaths(Position.atPageCoordinates(0, 80, 720));
|
|
57
53
|
const ref = paths[0];
|
|
58
54
|
const pos = ref.position;
|
|
59
55
|
expect(pos.boundingRect?.x).toBeCloseTo(80, 1);
|
|
60
56
|
expect(pos.boundingRect?.y).toBeCloseTo(720, 1);
|
|
61
57
|
|
|
62
|
-
expect(await client.move(ref, Position.
|
|
58
|
+
expect(await client.move(ref, Position.atPageCoordinates(0, 50.1, 100))).toBe(true);
|
|
63
59
|
|
|
64
|
-
expect(await client.findPaths(Position.
|
|
60
|
+
expect(await client.findPaths(Position.atPageCoordinates(0, 80, 720))).toHaveLength(0);
|
|
65
61
|
|
|
66
|
-
paths = await client.findPaths(Position.
|
|
62
|
+
paths = await client.findPaths(Position.atPageCoordinates(0, 50.1, 100));
|
|
67
63
|
const movedRef = paths[0];
|
|
68
64
|
const newPos = movedRef.position;
|
|
69
65
|
expect(newPos.boundingRect?.x).toBeCloseTo(50.1, 0.05);
|
|
70
66
|
expect(newPos.boundingRect?.y).toBeCloseTo(100, 0.05);
|
|
71
67
|
});
|
|
72
|
-
});
|
|
68
|
+
});
|