pdfdancer-client-typescript 1.0.4 → 1.0.6
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 +5 -5
- package/dist/__tests__/e2e/test-helpers.d.ts +2 -1
- package/dist/__tests__/e2e/test-helpers.d.ts.map +1 -1
- package/dist/__tests__/e2e/test-helpers.js +7 -3
- package/dist/__tests__/e2e/test-helpers.js.map +1 -1
- package/dist/client-v1.js +1 -1
- package/dist/client-v1.js.map +1 -1
- package/dist/client-v2.d.ts +129 -0
- package/dist/client-v2.d.ts.map +1 -0
- package/dist/client-v2.js +696 -0
- package/dist/client-v2.js.map +1 -0
- package/dist/image-builder.d.ts +13 -0
- package/dist/image-builder.d.ts.map +1 -0
- package/dist/image-builder.js +44 -0
- package/dist/image-builder.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/models.d.ts +5 -10
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +3 -13
- package/dist/models.js.map +1 -1
- package/dist/paragraph-builder.d.ts +19 -10
- package/dist/paragraph-builder.d.ts.map +1 -1
- package/dist/paragraph-builder.js +65 -26
- package/dist/paragraph-builder.js.map +1 -1
- package/dist/pdfdancer_v1.d.ts +202 -0
- package/dist/pdfdancer_v1.d.ts.map +1 -0
- package/dist/pdfdancer_v1.js +702 -0
- package/dist/pdfdancer_v1.js.map +1 -0
- package/dist/types.d.ts +56 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +92 -0
- package/dist/types.js.map +1 -0
- package/package.json +1 -1
- package/scripts/release.js +1 -1
- package/src/__tests__/client-v1.test.ts +46 -87
- package/src/__tests__/e2e/acroform.test.ts +60 -57
- package/src/__tests__/e2e/form_x_object.test.ts +17 -16
- package/src/__tests__/e2e/image.test.ts +53 -56
- package/src/__tests__/e2e/line.test.ts +47 -48
- package/src/__tests__/e2e/page.test.ts +37 -36
- package/src/__tests__/e2e/paragraph.test.ts +107 -101
- package/src/__tests__/e2e/path.test.ts +67 -64
- package/src/__tests__/e2e/test-helpers.ts +71 -67
- package/src/__tests__/e2e/token_from_env.test.ts +35 -0
- package/src/image-builder.ts +52 -0
- package/src/index.ts +1 -1
- package/src/models.ts +5 -21
- package/src/paragraph-builder.ts +217 -162
- package/src/{client-v1.ts → pdfdancer_v1.ts} +248 -53
- package/src/types.ts +133 -0
- package/example.ts +0 -99
|
@@ -1,104 +1,101 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* E2E tests for image operations
|
|
2
|
+
* E2E tests for image operations — new PDFDancer API
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as fs from 'fs';
|
|
6
|
-
import {
|
|
7
|
-
import {createTempPath,
|
|
8
|
-
import {expectWithin} from
|
|
6
|
+
import {PDFDancer} from '../../index';
|
|
7
|
+
import {createTempPath, getImagePath, requireEnvAndFixture} from './test-helpers';
|
|
8
|
+
import {expectWithin} from '../assertions';
|
|
9
9
|
|
|
10
|
-
describe('Image E2E Tests', () => {
|
|
11
|
-
// Tests should fail properly if environment is not configured
|
|
10
|
+
describe('Image E2E Tests (v2 API)', () => {
|
|
12
11
|
|
|
13
12
|
test('find images', async () => {
|
|
14
13
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
15
|
-
const
|
|
14
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
16
15
|
|
|
17
|
-
const images = await
|
|
16
|
+
const images = await pdf.selectImages();
|
|
18
17
|
expect(images).toHaveLength(3);
|
|
19
|
-
expect(images[0].type).toBe(
|
|
18
|
+
expect(images[0].type).toBe('IMAGE');
|
|
20
19
|
|
|
21
|
-
const
|
|
22
|
-
expect(
|
|
20
|
+
const imagesOnPage0 = await pdf.page(0).selectImages();
|
|
21
|
+
expect(imagesOnPage0).toHaveLength(2);
|
|
23
22
|
});
|
|
24
23
|
|
|
25
24
|
test('delete images', async () => {
|
|
26
25
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
27
|
-
const
|
|
26
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
28
27
|
|
|
29
|
-
const images = await
|
|
30
|
-
for (const
|
|
31
|
-
|
|
28
|
+
const images = await pdf.selectImages();
|
|
29
|
+
for (const img of images) {
|
|
30
|
+
await img.delete();
|
|
32
31
|
}
|
|
33
|
-
expect(await client.findImages()).toHaveLength(0);
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
const remaining = await pdf.selectImages();
|
|
34
|
+
expect(remaining).toHaveLength(0);
|
|
35
|
+
|
|
36
36
|
const outPath = createTempPath('deleteImage.pdf');
|
|
37
|
-
const
|
|
38
|
-
fs.writeFileSync(outPath,
|
|
37
|
+
const outData = await pdf.getPdfFile();
|
|
38
|
+
fs.writeFileSync(outPath, outData);
|
|
39
|
+
|
|
39
40
|
expect(fs.existsSync(outPath)).toBe(true);
|
|
40
41
|
expect(fs.statSync(outPath).size).toBeGreaterThan(0);
|
|
41
42
|
|
|
42
|
-
// Cleanup
|
|
43
43
|
fs.unlinkSync(outPath);
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
test('move image', async () => {
|
|
47
47
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
48
|
-
const
|
|
48
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
const position = imageRef.position;
|
|
53
|
-
expectWithin(position.boundingRect?.x, 54, 0.5);
|
|
54
|
-
expectWithin(position.boundingRect?.y, 300, 1);
|
|
50
|
+
const images = await pdf.selectImages();
|
|
51
|
+
const image = images[2];
|
|
55
52
|
|
|
56
|
-
|
|
53
|
+
expectWithin(image.position.boundingRect?.x, 54, 0.5);
|
|
54
|
+
expectWithin(image.position.boundingRect?.y, 300, 1);
|
|
57
55
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
expectWithin(
|
|
62
|
-
expectWithin(
|
|
56
|
+
await image.moveTo(50.1, 100);
|
|
57
|
+
|
|
58
|
+
const moved = (await pdf.selectImages())[2];
|
|
59
|
+
expectWithin(moved.position.boundingRect?.x, 50.1, 0.05);
|
|
60
|
+
expectWithin(moved.position.boundingRect?.y, 100, 0.05);
|
|
63
61
|
});
|
|
64
62
|
|
|
65
63
|
test('find image by position', async () => {
|
|
66
64
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
67
|
-
const
|
|
65
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
expect(
|
|
67
|
+
const none = await pdf.page(11).selectImagesAt(0, 0);
|
|
68
|
+
expect(none).toHaveLength(0);
|
|
71
69
|
|
|
72
|
-
|
|
73
|
-
expect(
|
|
74
|
-
expect(
|
|
70
|
+
const found = await pdf.page(11).selectImagesAt(55, 310);
|
|
71
|
+
expect(found).toHaveLength(1);
|
|
72
|
+
expect(found[0].internalId).toBe('IMAGE_000003');
|
|
75
73
|
});
|
|
76
74
|
|
|
77
75
|
test('add image', async () => {
|
|
78
76
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
79
|
-
const
|
|
77
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
80
78
|
|
|
81
|
-
|
|
82
|
-
expect(
|
|
79
|
+
const before = await pdf.selectImages();
|
|
80
|
+
expect(before).toHaveLength(3);
|
|
83
81
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const pos = Position.atPageCoordinates(6, 50.1, 98.0);
|
|
82
|
+
const result = await pdf.newImage()
|
|
83
|
+
.fromFile(getImagePath('logo-80.png'))
|
|
84
|
+
.at(6, 50.1, 98.0)
|
|
85
|
+
.add();
|
|
89
86
|
|
|
90
|
-
expect(
|
|
87
|
+
expect(result).toBeTruthy();
|
|
91
88
|
|
|
92
|
-
|
|
93
|
-
expect(
|
|
89
|
+
const after = await pdf.selectImages();
|
|
90
|
+
expect(after).toHaveLength(4);
|
|
94
91
|
|
|
95
|
-
const
|
|
96
|
-
expect(
|
|
92
|
+
const page6Images = await pdf.page(6).selectImages();
|
|
93
|
+
expect(page6Images).toHaveLength(1);
|
|
97
94
|
|
|
98
|
-
const
|
|
99
|
-
expect(
|
|
100
|
-
expect(
|
|
101
|
-
expectWithin(
|
|
102
|
-
expectWithin(
|
|
95
|
+
const added = page6Images[0];
|
|
96
|
+
expect(added.position.pageIndex).toBe(6);
|
|
97
|
+
expect(added.internalId).toBe('IMAGE_000004');
|
|
98
|
+
expectWithin(added.position.boundingRect?.x, 50.1, 0.05);
|
|
99
|
+
expectWithin(added.position.boundingRect?.y, 98.0, 0.05);
|
|
103
100
|
});
|
|
104
101
|
});
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* E2E tests for text line operations
|
|
2
|
+
* E2E tests for text line operations — new PDFDancer API
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import * as fs from 'fs';
|
|
6
|
-
import {
|
|
6
|
+
import {PDFDancer} from '../../index';
|
|
7
7
|
import {createTempPath, requireEnvAndFixture} from './test-helpers';
|
|
8
|
-
import {expectWithin} from
|
|
8
|
+
import {expectWithin} from '../assertions';
|
|
9
9
|
|
|
10
|
-
describe('Line E2E Tests', () => {
|
|
11
|
-
// Tests should fail properly if environment is not configured
|
|
10
|
+
describe('Text Line E2E Tests (v2 API)', () => {
|
|
12
11
|
|
|
13
12
|
test('find lines by position', async () => {
|
|
14
13
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
15
|
-
const
|
|
14
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
16
15
|
|
|
17
|
-
const lines = await
|
|
16
|
+
const lines = await pdf.selectLines();
|
|
18
17
|
expect(lines).toHaveLength(340);
|
|
19
18
|
|
|
20
19
|
const first = lines[0];
|
|
21
20
|
expect(first.internalId).toBe('LINE_000001');
|
|
22
21
|
expect(first.position).toBeDefined();
|
|
23
|
-
expectWithin(first.position.boundingRect?.x, 326, 1
|
|
22
|
+
expectWithin(first.position.boundingRect?.x, 326, 1);
|
|
24
23
|
expectWithin(first.position.boundingRect?.y, 706, 1);
|
|
25
24
|
|
|
26
25
|
const last = lines[lines.length - 1];
|
|
@@ -30,12 +29,23 @@ describe('Line E2E Tests', () => {
|
|
|
30
29
|
expectWithin(last.position.boundingRect?.y, 35, 1);
|
|
31
30
|
});
|
|
32
31
|
|
|
32
|
+
test('find lines on page', async () => {
|
|
33
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
34
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
35
|
+
|
|
36
|
+
const lines = await pdf.page(1).selectTextLines();
|
|
37
|
+
expect(lines).toHaveLength(26);
|
|
38
|
+
|
|
39
|
+
const line = lines[0];
|
|
40
|
+
expect(line.internalId).toBe('LINE_000005');
|
|
41
|
+
expect(line.position).toBeDefined();
|
|
42
|
+
});
|
|
43
|
+
|
|
33
44
|
test('find lines by text', async () => {
|
|
34
45
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
35
|
-
const
|
|
46
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
36
47
|
|
|
37
|
-
const
|
|
38
|
-
const lines = await client.findTextLines(pos);
|
|
48
|
+
const lines = await pdf.page(0).selectTextLinesStartingWith('the complete');
|
|
39
49
|
expect(lines).toHaveLength(1);
|
|
40
50
|
|
|
41
51
|
const line = lines[0];
|
|
@@ -47,76 +57,65 @@ describe('Line E2E Tests', () => {
|
|
|
47
57
|
|
|
48
58
|
test('delete line', async () => {
|
|
49
59
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
50
|
-
const
|
|
60
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
51
61
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
expect(await client.delete(ref)).toBe(true);
|
|
62
|
+
const [line] = await pdf.page(0).selectTextLinesStartingWith('The Complete');
|
|
63
|
+
await line.delete();
|
|
55
64
|
|
|
56
|
-
const
|
|
57
|
-
expect(
|
|
65
|
+
const remaining = await pdf.page(0).selectTextLinesStartingWith('The Complete');
|
|
66
|
+
expect(remaining).toHaveLength(0);
|
|
58
67
|
|
|
59
|
-
// Save PDF to verify operation
|
|
68
|
+
// Save PDF to verify operation
|
|
60
69
|
const outPath = createTempPath('deleteLine.pdf');
|
|
61
|
-
const
|
|
62
|
-
fs.writeFileSync(outPath,
|
|
70
|
+
const data = await pdf.getPdfFile();
|
|
71
|
+
fs.writeFileSync(outPath, data);
|
|
63
72
|
expect(fs.existsSync(outPath)).toBe(true);
|
|
64
73
|
expect(fs.statSync(outPath).size).toBeGreaterThan(0);
|
|
65
74
|
|
|
66
|
-
// Cleanup
|
|
67
75
|
fs.unlinkSync(outPath);
|
|
68
76
|
});
|
|
69
77
|
|
|
70
78
|
test('move line', async () => {
|
|
71
79
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
72
|
-
const
|
|
80
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
73
81
|
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
expect(await client.move(ref, newPos)).toBe(true);
|
|
82
|
+
const [line] = await pdf.page(0).selectTextLinesStartingWith('The Complete');
|
|
83
|
+
let newX = line.position!.getX()! + 100;
|
|
84
|
+
let newY = line.position!.getY()!;
|
|
85
|
+
await line.moveTo(newX, newY);
|
|
79
86
|
|
|
80
|
-
const
|
|
81
|
-
expect(
|
|
87
|
+
const movedPara = await pdf.page(0).selectParagraphsAt(newX, newY);
|
|
88
|
+
expect(movedPara.length).toBeGreaterThan(0);
|
|
82
89
|
|
|
83
|
-
// Save PDF to verify operation
|
|
84
90
|
const outPath = createTempPath('moveLine.pdf');
|
|
85
|
-
|
|
86
|
-
fs.writeFileSync(outPath, outputPdfData);
|
|
91
|
+
await pdf.save(outPath);
|
|
87
92
|
expect(fs.existsSync(outPath)).toBe(true);
|
|
88
93
|
expect(fs.statSync(outPath).size).toBeGreaterThan(0);
|
|
89
94
|
|
|
90
|
-
// Cleanup
|
|
91
95
|
fs.unlinkSync(outPath);
|
|
92
96
|
});
|
|
93
97
|
|
|
94
98
|
test('modify line', async () => {
|
|
95
99
|
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
96
|
-
const
|
|
100
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
97
101
|
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
expect(await client.modifyTextLine(ref, ' replaced ')).toBe(true);
|
|
102
|
+
const [line] = await pdf.page(0).selectTextLinesStartingWith('The Complete');
|
|
103
|
+
await line.edit().text(' replaced ').apply();
|
|
101
104
|
|
|
102
|
-
// Save PDF to verify operation
|
|
103
105
|
const outPath = createTempPath('modifyLine.pdf');
|
|
104
|
-
|
|
105
|
-
fs.writeFileSync(outPath, outputPdfData);
|
|
106
|
+
await pdf.save(outPath);
|
|
106
107
|
expect(fs.existsSync(outPath)).toBe(true);
|
|
107
108
|
expect(fs.statSync(outPath).size).toBeGreaterThan(0);
|
|
108
109
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
expect(await client.findTextLines(pos5)).toHaveLength(0);
|
|
110
|
+
const stillOld = await pdf.page(0).selectParagraphsStartingWith('The Complete');
|
|
111
|
+
expect(stillOld).toHaveLength(0);
|
|
112
112
|
|
|
113
|
-
const
|
|
114
|
-
expect(
|
|
113
|
+
const replaced = await pdf.page(0).selectParagraphsStartingWith(' replaced ');
|
|
114
|
+
expect(replaced.length).toBeGreaterThan(0);
|
|
115
115
|
|
|
116
|
-
const
|
|
117
|
-
expect(
|
|
116
|
+
const containingParas = await pdf.page(0).selectParagraphsStartingWith(' replaced ');
|
|
117
|
+
expect(containingParas.length).toBeGreaterThan(0);
|
|
118
118
|
|
|
119
|
-
// Cleanup
|
|
120
119
|
fs.unlinkSync(outPath);
|
|
121
120
|
});
|
|
122
121
|
});
|
|
@@ -2,41 +2,42 @@
|
|
|
2
2
|
* E2E tests for page operations
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import {ObjectType, PDFDancer} from '../../index';
|
|
6
|
+
import {requireEnvAndFixture} from './test-helpers';
|
|
7
7
|
|
|
8
8
|
describe('Page 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
|
-
});
|
|
9
|
+
// Tests should fail properly if environment is not configured
|
|
10
|
+
|
|
11
|
+
test('get pages', async () => {
|
|
12
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
13
|
+
const client = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
14
|
+
|
|
15
|
+
const pages = await client.pages();
|
|
16
|
+
expect(pages).toBeDefined();
|
|
17
|
+
expect(pages[0].type).toBe(ObjectType.PAGE);
|
|
18
|
+
expect(pages).toHaveLength(12);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('get page', async () => {
|
|
22
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
23
|
+
const client = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
24
|
+
|
|
25
|
+
const page = await client.page(2);
|
|
26
|
+
expect(page).toBeDefined();
|
|
27
|
+
expect(page!.position.pageIndex).toBe(2);
|
|
28
|
+
expect(page!.internalId).toBeDefined();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('delete page', async () => {
|
|
32
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('ObviouslyAwesome.pdf');
|
|
33
|
+
const client = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
34
|
+
|
|
35
|
+
expect(await client.pages()).toHaveLength(12);
|
|
36
|
+
const page3 = client.page(3);
|
|
37
|
+
expect(page3).toBeDefined();
|
|
38
|
+
expect(await page3.delete()).toBe(true);
|
|
39
|
+
|
|
40
|
+
const newPages = await client.pages();
|
|
41
|
+
expect(newPages).toHaveLength(11);
|
|
42
|
+
});
|
|
43
|
+
});
|