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
|
@@ -48,19 +48,19 @@ describe('ClientV1', () => {
|
|
|
48
48
|
|
|
49
49
|
describe('Position', () => {
|
|
50
50
|
test('should create position from page index', () => {
|
|
51
|
-
const position = Position.
|
|
51
|
+
const position = Position.atPage(1);
|
|
52
52
|
expect(position.pageIndex).toBe(1);
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
test('should create position with coordinates', () => {
|
|
56
|
-
const position = Position.
|
|
56
|
+
const position = Position.atPageCoordinates(1, 100, 200);
|
|
57
57
|
expect(position.pageIndex).toBe(1);
|
|
58
58
|
expect(position.getX()).toBe(100);
|
|
59
59
|
expect(position.getY()).toBe(200);
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
test('should move position', () => {
|
|
63
|
-
const position = Position.
|
|
63
|
+
const position = Position.atPageCoordinates(1, 100, 200);
|
|
64
64
|
position.moveX(50).moveY(30);
|
|
65
65
|
expect(position.getX()).toBe(150);
|
|
66
66
|
expect(position.getY()).toBe(230);
|
|
@@ -97,15 +97,15 @@ describe('Font', () => {
|
|
|
97
97
|
|
|
98
98
|
describe('Paragraph', () => {
|
|
99
99
|
test('should create paragraph with position', () => {
|
|
100
|
-
const position = Position.
|
|
100
|
+
const position = Position.atPage(1);
|
|
101
101
|
const paragraph = new Paragraph(position);
|
|
102
102
|
expect(paragraph.getPosition()).toBe(position);
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
test('should set position', () => {
|
|
106
106
|
const paragraph = new Paragraph();
|
|
107
|
-
const position = Position.
|
|
107
|
+
const position = Position.atPage(2);
|
|
108
108
|
paragraph.setPosition(position);
|
|
109
109
|
expect(paragraph.getPosition()).toBe(position);
|
|
110
110
|
});
|
|
111
|
-
});
|
|
111
|
+
});
|
|
@@ -3,49 +3,47 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as fs from 'fs';
|
|
6
|
-
import {
|
|
7
|
-
import { requireEnvAndFixture
|
|
6
|
+
import {ClientV1, ObjectType, Position} from '../../index';
|
|
7
|
+
import {createTempPath, requireEnvAndFixture} from './test-helpers';
|
|
8
8
|
|
|
9
9
|
describe('Form E2E Tests', () => {
|
|
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
|
-
});
|
|
10
|
+
// Tests should fail properly if environment is not configured
|
|
11
|
+
|
|
12
|
+
test('delete forms', async () => {
|
|
13
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('form-xobject-example.pdf');
|
|
14
|
+
const client = await ClientV1.create(token, pdfData, baseUrl);
|
|
15
|
+
|
|
16
|
+
const forms = await client.findForms();
|
|
17
|
+
expect(forms).toHaveLength(17);
|
|
18
|
+
expect(forms[0].type).toBe(ObjectType.FORM_X_OBJECT);
|
|
19
|
+
|
|
20
|
+
// Delete all forms
|
|
21
|
+
for (const f of forms) {
|
|
22
|
+
expect(await client.delete(f)).toBe(true);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
expect(await client.findForms()).toHaveLength(0);
|
|
26
|
+
|
|
27
|
+
// Save PDF to verify operation
|
|
28
|
+
const outPath = createTempPath('forms-after-delete.pdf');
|
|
29
|
+
const outputPdfData = await client.getPdfFile();
|
|
30
|
+
fs.writeFileSync(outPath, outputPdfData);
|
|
31
|
+
expect(fs.existsSync(outPath)).toBe(true);
|
|
32
|
+
expect(fs.statSync(outPath).size).toBeGreaterThan(0);
|
|
33
|
+
|
|
34
|
+
// Cleanup
|
|
35
|
+
fs.unlinkSync(outPath);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('find form by position', async () => {
|
|
39
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('form-xobject-example.pdf');
|
|
40
|
+
const client = await ClientV1.create(token, pdfData, baseUrl);
|
|
41
|
+
|
|
42
|
+
let forms = await client.findForms(Position.atPageCoordinates(0, 0, 0));
|
|
43
|
+
expect(forms).toHaveLength(0);
|
|
44
|
+
|
|
45
|
+
forms = await client.findForms(Position.atPageCoordinates(0, 321, 601));
|
|
46
|
+
expect(forms).toHaveLength(1);
|
|
47
|
+
expect(forms[0].internalId).toBe('FORM_000005');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -3,106 +3,102 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as fs from 'fs';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import {ClientV1, Image, ObjectType, Position} from '../../index';
|
|
7
|
+
import {createTempPath, readImageFixture, requireEnvAndFixture} from './test-helpers';
|
|
8
|
+
import {expectWithin} from "../assertions";
|
|
8
9
|
|
|
9
10
|
describe('Image E2E Tests', () => {
|
|
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
|
-
expect(newImage.internalId).toBe('IMAGE_000003');
|
|
105
|
-
expect(newImage.position.boundingRect?.x).toBeCloseTo(50.1, 0.05);
|
|
106
|
-
expect(newImage.position.boundingRect?.y).toBeCloseTo(98.0, 0.05);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
11
|
+
// Tests should fail properly if environment is not configured
|
|
12
|
+
|
|
13
|
+
test('find images', async () => {
|
|
14
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
15
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
16
|
+
|
|
17
|
+
const images = await client.findImages();
|
|
18
|
+
expect(images).toHaveLength(3);
|
|
19
|
+
expect(images[0].type).toBe(ObjectType.IMAGE);
|
|
20
|
+
|
|
21
|
+
const imagesPage0 = await client.findImages(Position.atPage(0));
|
|
22
|
+
expect(imagesPage0).toHaveLength(2);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('delete images', async () => {
|
|
26
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
27
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
28
|
+
|
|
29
|
+
const images = await client.findImages();
|
|
30
|
+
for (const obj of images) {
|
|
31
|
+
expect(await client.delete(obj)).toBe(true);
|
|
32
|
+
}
|
|
33
|
+
expect(await client.findImages()).toHaveLength(0);
|
|
34
|
+
|
|
35
|
+
// Save PDF to verify operation
|
|
36
|
+
const outPath = createTempPath('deleteImage.pdf');
|
|
37
|
+
const outputPdfData = await client.getPdfFile();
|
|
38
|
+
fs.writeFileSync(outPath, outputPdfData);
|
|
39
|
+
expect(fs.existsSync(outPath)).toBe(true);
|
|
40
|
+
expect(fs.statSync(outPath).size).toBeGreaterThan(0);
|
|
41
|
+
|
|
42
|
+
// Cleanup
|
|
43
|
+
fs.unlinkSync(outPath);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('move image', async () => {
|
|
47
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
48
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
49
|
+
|
|
50
|
+
let images = await client.findImages();
|
|
51
|
+
const imageRef = images[2];
|
|
52
|
+
const position = imageRef.position;
|
|
53
|
+
expectWithin(position.boundingRect?.x, 54, 0.5);
|
|
54
|
+
expectWithin(position.boundingRect?.y, 300, 1);
|
|
55
|
+
|
|
56
|
+
expect(await client.move(imageRef, Position.atPageCoordinates(11, 50.1, 100.0))).toBe(true);
|
|
57
|
+
|
|
58
|
+
images = await client.findImages();
|
|
59
|
+
const movedImageRef = images[2];
|
|
60
|
+
const newPosition = movedImageRef.position;
|
|
61
|
+
expectWithin(newPosition.boundingRect?.x, 50.1, 0.05);
|
|
62
|
+
expectWithin(newPosition.boundingRect?.y, 100.0, 0.05);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('find image by position', async () => {
|
|
66
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
67
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
68
|
+
|
|
69
|
+
let images = await client.findImages(Position.atPageCoordinates(11, 0, 0));
|
|
70
|
+
expect(images).toHaveLength(0);
|
|
71
|
+
|
|
72
|
+
images = await client.findImages(Position.atPageCoordinates(11, 55, 310));
|
|
73
|
+
expect(images).toHaveLength(1);
|
|
74
|
+
expect(images[0].internalId).toBe('IMAGE_000003');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('add image', async () => {
|
|
78
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
79
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
80
|
+
|
|
81
|
+
let images = await client.findImages();
|
|
82
|
+
expect(images).toHaveLength(3);
|
|
83
|
+
|
|
84
|
+
// Prepare image data
|
|
85
|
+
const imageData = readImageFixture('logo-80.png');
|
|
86
|
+
const image = new Image();
|
|
87
|
+
image.data = imageData;
|
|
88
|
+
const pos = Position.atPageCoordinates(6, 50.1, 98.0);
|
|
89
|
+
|
|
90
|
+
expect(await client.addImage(image, pos)).toBe(true);
|
|
91
|
+
|
|
92
|
+
images = await client.findImages();
|
|
93
|
+
expect(images).toHaveLength(4);
|
|
94
|
+
|
|
95
|
+
const imagesPage6 = await client.findImages(Position.atPage(6));
|
|
96
|
+
expect(imagesPage6).toHaveLength(1);
|
|
97
|
+
|
|
98
|
+
const newImage = imagesPage6[0];
|
|
99
|
+
expect(newImage.position.pageIndex).toBe(6);
|
|
100
|
+
expect(newImage.internalId).toBe('IMAGE_000004');
|
|
101
|
+
expectWithin(newImage.position.boundingRect?.x, 50.1, 0.05);
|
|
102
|
+
expectWithin(newImage.position.boundingRect?.y, 98.0, 0.05);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -3,132 +3,120 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as fs from 'fs';
|
|
6
|
-
import {
|
|
7
|
-
import { requireEnvAndFixture
|
|
6
|
+
import {ClientV1, Position} from '../../index';
|
|
7
|
+
import {createTempPath, requireEnvAndFixture} from './test-helpers';
|
|
8
|
+
import {expectWithin} from "../assertions";
|
|
8
9
|
|
|
9
10
|
describe('Line E2E Tests', () => {
|
|
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
|
-
const pos6 = Position.fromPageIndex(0);
|
|
124
|
-
pos6.textStartsWith = ' replaced ';
|
|
125
|
-
expect(await client.findTextLines(pos6)).not.toHaveLength(0);
|
|
126
|
-
|
|
127
|
-
const pos7 = Position.fromPageIndex(0);
|
|
128
|
-
pos7.textStartsWith = ' replaced ';
|
|
129
|
-
expect(await client.findParagraphs(pos7)).not.toHaveLength(0);
|
|
130
|
-
|
|
131
|
-
// Cleanup
|
|
132
|
-
fs.unlinkSync(outPath);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
11
|
+
// Tests should fail properly if environment is not configured
|
|
12
|
+
|
|
13
|
+
test('find lines by position', async () => {
|
|
14
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
15
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
16
|
+
|
|
17
|
+
const lines = await client.findTextLines();
|
|
18
|
+
expect(lines).toHaveLength(340);
|
|
19
|
+
|
|
20
|
+
const first = lines[0];
|
|
21
|
+
expect(first.internalId).toBe('LINE_000001');
|
|
22
|
+
expect(first.position).toBeDefined();
|
|
23
|
+
expectWithin(first.position.boundingRect?.x, 326, 1.0);
|
|
24
|
+
expectWithin(first.position.boundingRect?.y, 706, 1);
|
|
25
|
+
|
|
26
|
+
const last = lines[lines.length - 1];
|
|
27
|
+
expect(last.internalId).toBe('LINE_000340');
|
|
28
|
+
expect(last.position).toBeDefined();
|
|
29
|
+
expectWithin(last.position.boundingRect?.x, 548, 1);
|
|
30
|
+
expectWithin(last.position.boundingRect?.y, 35, 1);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('find lines by text', async () => {
|
|
34
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
35
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
36
|
+
|
|
37
|
+
const pos = Position.atPage(0).withTextStarts("the complete");
|
|
38
|
+
const lines = await client.findTextLines(pos);
|
|
39
|
+
expect(lines).toHaveLength(1);
|
|
40
|
+
|
|
41
|
+
const line = lines[0];
|
|
42
|
+
expect(line.internalId).toBe('LINE_000002');
|
|
43
|
+
expect(line.position).toBeDefined();
|
|
44
|
+
expectWithin(line.position.boundingRect?.x, 54, 1);
|
|
45
|
+
expectWithin(line.position.boundingRect?.y, 606, 2);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('delete line', async () => {
|
|
49
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
50
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
51
|
+
|
|
52
|
+
const pos = Position.atPage(0).withTextStarts('The Complete');
|
|
53
|
+
const ref = (await client.findTextLines(pos))[0];
|
|
54
|
+
expect(await client.delete(ref)).toBe(true);
|
|
55
|
+
|
|
56
|
+
const pos2 = Position.atPage(0).withTextStarts('The Complete');
|
|
57
|
+
expect(await client.findTextLines(pos2)).toHaveLength(0);
|
|
58
|
+
|
|
59
|
+
// Save PDF to verify operation (Node.js environment)
|
|
60
|
+
const outPath = createTempPath('deleteLine.pdf');
|
|
61
|
+
const outputPdfData = await client.getPdfFile();
|
|
62
|
+
fs.writeFileSync(outPath, outputPdfData);
|
|
63
|
+
expect(fs.existsSync(outPath)).toBe(true);
|
|
64
|
+
expect(fs.statSync(outPath).size).toBeGreaterThan(0);
|
|
65
|
+
|
|
66
|
+
// Cleanup
|
|
67
|
+
fs.unlinkSync(outPath);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('move line', async () => {
|
|
71
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
72
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
73
|
+
|
|
74
|
+
const pos3 = Position.atPage(0).withTextStarts('The Complete');
|
|
75
|
+
const ref = (await client.findTextLines(pos3))[0];
|
|
76
|
+
const newPos = ref.position.copy();
|
|
77
|
+
newPos.moveX(100);
|
|
78
|
+
expect(await client.move(ref, newPos)).toBe(true);
|
|
79
|
+
|
|
80
|
+
const ref2 = (await client.findParagraphs(newPos))[0];
|
|
81
|
+
expect(ref2).toBeDefined();
|
|
82
|
+
|
|
83
|
+
// Save PDF to verify operation
|
|
84
|
+
const outPath = createTempPath('moveLine.pdf');
|
|
85
|
+
const outputPdfData = await client.getPdfFile();
|
|
86
|
+
fs.writeFileSync(outPath, outputPdfData);
|
|
87
|
+
expect(fs.existsSync(outPath)).toBe(true);
|
|
88
|
+
expect(fs.statSync(outPath).size).toBeGreaterThan(0);
|
|
89
|
+
|
|
90
|
+
// Cleanup
|
|
91
|
+
fs.unlinkSync(outPath);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('modify line', async () => {
|
|
95
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
96
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
97
|
+
|
|
98
|
+
const pos4 = Position.atPage(0).withTextStarts('The Complete');
|
|
99
|
+
const ref = (await client.findTextLines(pos4))[0];
|
|
100
|
+
expect(await client.modifyTextLine(ref, ' replaced ')).toBe(true);
|
|
101
|
+
|
|
102
|
+
// Save PDF to verify operation
|
|
103
|
+
const outPath = createTempPath('modifyLine.pdf');
|
|
104
|
+
const outputPdfData = await client.getPdfFile();
|
|
105
|
+
fs.writeFileSync(outPath, outputPdfData);
|
|
106
|
+
expect(fs.existsSync(outPath)).toBe(true);
|
|
107
|
+
expect(fs.statSync(outPath).size).toBeGreaterThan(0);
|
|
108
|
+
|
|
109
|
+
// Verify the text was replaced
|
|
110
|
+
const pos5 = Position.atPage(0).withTextStarts('The Complete');
|
|
111
|
+
expect(await client.findTextLines(pos5)).toHaveLength(0);
|
|
112
|
+
|
|
113
|
+
const pos6 = Position.atPage(0).withTextStarts(' replaced ');
|
|
114
|
+
expect(await client.findTextLines(pos6)).not.toHaveLength(0);
|
|
115
|
+
|
|
116
|
+
const pos7 = Position.atPage(0).withTextStarts(' replaced ');
|
|
117
|
+
expect(await client.findParagraphs(pos7)).not.toHaveLength(0);
|
|
118
|
+
|
|
119
|
+
// Cleanup
|
|
120
|
+
fs.unlinkSync(outPath);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -10,8 +10,7 @@ describe('Page E2E Tests', () => {
|
|
|
10
10
|
|
|
11
11
|
test('get pages', async () => {
|
|
12
12
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
13
|
-
const client =
|
|
14
|
-
await client.init();
|
|
13
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
15
14
|
|
|
16
15
|
const pages = await client.getPages();
|
|
17
16
|
expect(pages).toBeDefined();
|
|
@@ -21,8 +20,7 @@ describe('Page E2E Tests', () => {
|
|
|
21
20
|
|
|
22
21
|
test('get page', async () => {
|
|
23
22
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
24
|
-
const client =
|
|
25
|
-
await client.init();
|
|
23
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
26
24
|
|
|
27
25
|
const page = await client.getPage(2);
|
|
28
26
|
expect(page).toBeDefined();
|
|
@@ -32,8 +30,7 @@ describe('Page E2E Tests', () => {
|
|
|
32
30
|
|
|
33
31
|
test('delete page', async () => {
|
|
34
32
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
35
|
-
const client =
|
|
36
|
-
await client.init();
|
|
33
|
+
const client = await ClientV1.create(token, pdfData, baseUrl, 30000);
|
|
37
34
|
|
|
38
35
|
const page3 = await client.getPage(3);
|
|
39
36
|
expect(page3).toBeDefined();
|