pdfdancer-client-typescript 1.0.12 → 1.0.13
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 +1 -1
- package/README.md +1 -1
- package/dist/__tests__/e2e/pdf-assertions.d.ts +1 -0
- package/dist/__tests__/e2e/pdf-assertions.d.ts.map +1 -1
- package/dist/__tests__/e2e/pdf-assertions.js +9 -3
- package/dist/__tests__/e2e/pdf-assertions.js.map +1 -1
- package/dist/fingerprint.d.ts +12 -0
- package/dist/fingerprint.d.ts.map +1 -0
- package/dist/fingerprint.js +196 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/image-builder.d.ts +4 -2
- package/dist/image-builder.d.ts.map +1 -1
- package/dist/image-builder.js +12 -3
- 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 +75 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +179 -21
- package/dist/models.js.map +1 -1
- package/dist/page-builder.d.ts +24 -0
- package/dist/page-builder.d.ts.map +1 -0
- package/dist/page-builder.js +107 -0
- package/dist/page-builder.js.map +1 -0
- package/dist/paragraph-builder.d.ts +48 -54
- package/dist/paragraph-builder.d.ts.map +1 -1
- package/dist/paragraph-builder.js +408 -135
- package/dist/paragraph-builder.js.map +1 -1
- package/dist/pdfdancer_v1.d.ts +90 -9
- package/dist/pdfdancer_v1.d.ts.map +1 -1
- package/dist/pdfdancer_v1.js +535 -50
- package/dist/pdfdancer_v1.js.map +1 -1
- package/dist/types.d.ts +24 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +117 -2
- package/dist/types.js.map +1 -1
- package/docs/openapi.yml +2076 -0
- package/fixtures/Showcase.pdf +0 -0
- package/package.json +1 -1
- package/src/__tests__/e2e/acroform.test.ts +5 -5
- package/src/__tests__/e2e/context-manager-showcase.test.ts +267 -0
- package/src/__tests__/e2e/form_x_object.test.ts +1 -1
- package/src/__tests__/e2e/image-showcase.test.ts +133 -0
- package/src/__tests__/e2e/image.test.ts +1 -1
- package/src/__tests__/e2e/line-showcase.test.ts +118 -0
- package/src/__tests__/e2e/line.test.ts +1 -16
- package/src/__tests__/e2e/page-showcase.test.ts +154 -0
- package/src/__tests__/e2e/paragraph-showcase.test.ts +523 -0
- package/src/__tests__/e2e/paragraph.test.ts +8 -8
- package/src/__tests__/e2e/pdf-assertions.ts +10 -3
- package/src/__tests__/e2e/pdfdancer-showcase.test.ts +40 -0
- package/src/__tests__/e2e/snapshot-showcase.test.ts +158 -0
- package/src/__tests__/e2e/snapshot.test.ts +296 -0
- package/src/__tests__/fingerprint.test.ts +36 -0
- package/src/fingerprint.ts +169 -0
- package/src/image-builder.ts +13 -6
- package/src/index.ts +6 -1
- package/src/models.ts +208 -24
- package/src/page-builder.ts +130 -0
- package/src/paragraph-builder.ts +517 -159
- package/src/pdfdancer_v1.ts +630 -51
- package/src/types.ts +145 -2
- package/update-api-spec.sh +3 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import {ObjectType, Orientation, PDFDancer, STANDARD_PAGE_SIZES} from '../../index';
|
|
2
|
+
import {requireEnvAndFixture} from './test-helpers';
|
|
3
|
+
import {PDFAssertions} from './pdf-assertions';
|
|
4
|
+
|
|
5
|
+
describe('Page E2E Tests (Showcase)', () => {
|
|
6
|
+
test('get all elements', async () => {
|
|
7
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
8
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
9
|
+
|
|
10
|
+
const elements = await pdf.selectElements();
|
|
11
|
+
expect(elements.length).toBe(99);
|
|
12
|
+
|
|
13
|
+
let total = 0;
|
|
14
|
+
for (const page of await pdf.pages()) {
|
|
15
|
+
const pageElements = await page.selectElements();
|
|
16
|
+
total += pageElements.length;
|
|
17
|
+
}
|
|
18
|
+
expect(total).toBe(99);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('get pages', async () => {
|
|
22
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
23
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
24
|
+
|
|
25
|
+
const pages = await pdf.pages();
|
|
26
|
+
expect(pages).toBeDefined();
|
|
27
|
+
expect(pages.length).toBe(7);
|
|
28
|
+
expect(pages[0].type).toBe(ObjectType.PAGE);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('get page', async () => {
|
|
32
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
33
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
34
|
+
|
|
35
|
+
const page = pdf.page(2);
|
|
36
|
+
expect(page).toBeDefined();
|
|
37
|
+
expect(page.position.pageIndex).toBe(2);
|
|
38
|
+
expect(page.internalId).toBeDefined();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('delete page', async () => {
|
|
42
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
43
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
44
|
+
|
|
45
|
+
const page3 = pdf.page(3);
|
|
46
|
+
await page3.delete();
|
|
47
|
+
|
|
48
|
+
const pagesAfter = await pdf.pages();
|
|
49
|
+
expect(pagesAfter.length).toBe(6);
|
|
50
|
+
|
|
51
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
52
|
+
await assertions.assertNumberOfPages(6);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('move page', async () => {
|
|
56
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
57
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
58
|
+
|
|
59
|
+
const pagesBefore = await pdf.pages();
|
|
60
|
+
expect(pagesBefore.length).toBe(7);
|
|
61
|
+
|
|
62
|
+
const result = await pdf.movePage(0, 6);
|
|
63
|
+
expect(result.position.pageIndex).toBe(6);
|
|
64
|
+
|
|
65
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
66
|
+
await assertions.assertParagraphExists('This is regular Sans text showing alignment and styles.', 6);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('add page', async () => {
|
|
70
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
71
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
72
|
+
|
|
73
|
+
const pagesBefore = await pdf.pages();
|
|
74
|
+
expect(pagesBefore.length).toBe(7);
|
|
75
|
+
|
|
76
|
+
await pdf.newPage().add();
|
|
77
|
+
|
|
78
|
+
const pagesAfter = await pdf.pages();
|
|
79
|
+
expect(pagesAfter.length).toBe(8);
|
|
80
|
+
expect(pagesAfter[7].position.pageIndex).toBe(7);
|
|
81
|
+
expect(pagesAfter[7].internalId).toBeDefined();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('add page with builder default', async () => {
|
|
85
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
86
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
87
|
+
|
|
88
|
+
expect((await pdf.pages()).length).toBe(7);
|
|
89
|
+
|
|
90
|
+
const pageRef = await pdf.newPage().add();
|
|
91
|
+
expect(pageRef.position.pageIndex).toBe(7);
|
|
92
|
+
expect((await pdf.pages()).length).toBe(8);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('add page with builder A4 portrait', async () => {
|
|
96
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
97
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
98
|
+
|
|
99
|
+
expect((await pdf.pages()).length).toBe(7);
|
|
100
|
+
|
|
101
|
+
const pageRef = await pdf.newPage().a4().portrait().add();
|
|
102
|
+
expect(pageRef.position.pageIndex).toBe(7);
|
|
103
|
+
expect((await pdf.pages()).length).toBe(8);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('add page with builder letter landscape', async () => {
|
|
107
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
108
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
109
|
+
|
|
110
|
+
expect((await pdf.pages()).length).toBe(7);
|
|
111
|
+
|
|
112
|
+
const pageRef = await pdf.newPage().letter().landscape().add();
|
|
113
|
+
expect(pageRef.position.pageIndex).toBe(7);
|
|
114
|
+
expect((await pdf.pages()).length).toBe(8);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('add page with builder at index', async () => {
|
|
118
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
119
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
120
|
+
|
|
121
|
+
expect((await pdf.pages()).length).toBe(7);
|
|
122
|
+
|
|
123
|
+
const pageRef = await pdf.newPage().atIndex(5).a5().landscape().add();
|
|
124
|
+
expect(pageRef.position.pageIndex).toBe(5);
|
|
125
|
+
expect((await pdf.pages()).length).toBe(8);
|
|
126
|
+
|
|
127
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
128
|
+
const a5 = STANDARD_PAGE_SIZES.A5;
|
|
129
|
+
await assertions.assertPageDimension(a5.width, a5.height, Orientation.PORTRAIT, 5);
|
|
130
|
+
await assertions.assertTotalNumberOfElements(0, 5);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('add page with builder custom size', async () => {
|
|
134
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
135
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
136
|
+
|
|
137
|
+
expect((await pdf.pages()).length).toBe(7);
|
|
138
|
+
|
|
139
|
+
const pageRef = await pdf.newPage().customSize(400, 600).landscape().add();
|
|
140
|
+
expect(pageRef.position.pageIndex).toBe(7);
|
|
141
|
+
expect((await pdf.pages()).length).toBe(8);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('add page with builder all options', async () => {
|
|
145
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
146
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl, 30000);
|
|
147
|
+
|
|
148
|
+
expect((await pdf.pages()).length).toBe(7);
|
|
149
|
+
|
|
150
|
+
const pageRef = await pdf.newPage().atIndex(3).pageSize('A3').orientation(Orientation.LANDSCAPE).add();
|
|
151
|
+
expect(pageRef.position.pageIndex).toBe(3);
|
|
152
|
+
expect((await pdf.pages()).length).toBe(8);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
import {Color, FontType, PDFDancer, StandardFonts} from '../../index';
|
|
2
|
+
import {getFontPath, requireEnvAndFixture} from './test-helpers';
|
|
3
|
+
import {expectWithin} from '../assertions';
|
|
4
|
+
import {PDFAssertions} from './pdf-assertions';
|
|
5
|
+
|
|
6
|
+
const SAMPLE_PARAGRAPH = 'This is regular Sans text showing alignment and styles.';
|
|
7
|
+
|
|
8
|
+
describe('Paragraph E2E Tests (Showcase)', () => {
|
|
9
|
+
test('find paragraphs by position', async () => {
|
|
10
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
11
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
12
|
+
|
|
13
|
+
const allParagraphs = await pdf.selectParagraphs();
|
|
14
|
+
expect(allParagraphs).toHaveLength(24);
|
|
15
|
+
|
|
16
|
+
const firstPageParas = await pdf.page(0).selectParagraphs();
|
|
17
|
+
expect(firstPageParas).toHaveLength(4);
|
|
18
|
+
|
|
19
|
+
const first = firstPageParas[0];
|
|
20
|
+
expect(first.internalId).toBe('PARAGRAPH_000005');
|
|
21
|
+
expectWithin(first.position.getX(), 180, 1);
|
|
22
|
+
expectWithin(first.position.getY(), 755.2, 1);
|
|
23
|
+
|
|
24
|
+
const last = firstPageParas[firstPageParas.length - 1];
|
|
25
|
+
expect(last.internalId).toBe('PARAGRAPH_000008');
|
|
26
|
+
expectWithin(last.position.getX(), 69.3, 1);
|
|
27
|
+
expectWithin(last.position.getY(), 46.7, 2);
|
|
28
|
+
|
|
29
|
+
const status = last.objectRef().status;
|
|
30
|
+
expect(status).toBeDefined();
|
|
31
|
+
expect(status?.isEncodable()).toBe(true);
|
|
32
|
+
expect(status?.getFontType()).toBe(FontType.EMBEDDED);
|
|
33
|
+
expect(status?.isModified()).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('find paragraphs by text', async () => {
|
|
37
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
38
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
39
|
+
|
|
40
|
+
const paragraphs = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
41
|
+
expect(paragraphs).toHaveLength(1);
|
|
42
|
+
|
|
43
|
+
const paragraph = paragraphs[0];
|
|
44
|
+
expect(paragraph.internalId).toBe('PARAGRAPH_000006');
|
|
45
|
+
expectWithin(paragraph.position.getX(), 64.7, 1);
|
|
46
|
+
expectWithin(paragraph.position.getY(), 661.2, 2);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('select paragraphs matching document level', async () => {
|
|
50
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
51
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
52
|
+
|
|
53
|
+
const all = await pdf.selectParagraphs();
|
|
54
|
+
expect(all.length).toBeGreaterThan(0);
|
|
55
|
+
|
|
56
|
+
expect((await pdf.selectParagraphsMatching('\\w+')).length).toBeGreaterThanOrEqual(1);
|
|
57
|
+
expect((await pdf.selectParagraphsMatching('.')).length).toBeGreaterThanOrEqual(1);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('select paragraphs matching with special characters', async () => {
|
|
61
|
+
const [baseUrl, token] = (await requireEnvAndFixture('Showcase.pdf')).slice(0, 2) as [string, string];
|
|
62
|
+
const pdf = await PDFDancer.new({initialPageCount: 1}, token, baseUrl);
|
|
63
|
+
|
|
64
|
+
await pdf.newParagraph().text('Invoice #12345').font(StandardFonts.HELVETICA, 12).at(0, 100, 100).add();
|
|
65
|
+
await pdf.newParagraph().text('Date: 2024-01-15').font(StandardFonts.HELVETICA, 12).at(0, 100, 200).add();
|
|
66
|
+
await pdf.newParagraph().text('Total: $99.99').font(StandardFonts.HELVETICA, 12).at(0, 100, 300).add();
|
|
67
|
+
await pdf.newParagraph().text('Email: test@example.com').font(StandardFonts.HELVETICA, 12).at(0, 100, 400).add();
|
|
68
|
+
|
|
69
|
+
const invoiceMatches = await pdf.selectParagraphsMatching('Invoice #[0-9]+');
|
|
70
|
+
expect(invoiceMatches).toHaveLength(1);
|
|
71
|
+
expect(invoiceMatches[0].getText()).toContain('Invoice #12345');
|
|
72
|
+
|
|
73
|
+
const dateMatches = await pdf.selectParagraphsMatching('[0-9]{4}-[0-9]{2}-[0-9]{2}');
|
|
74
|
+
expect(dateMatches).toHaveLength(1);
|
|
75
|
+
expect(dateMatches[0].getText()).toContain('2024-01-15');
|
|
76
|
+
|
|
77
|
+
const dollarMatches = await pdf.selectParagraphsMatching('\\$[0-9]+\\.[0-9]+');
|
|
78
|
+
expect(dollarMatches).toHaveLength(1);
|
|
79
|
+
expect(dollarMatches[0].getText()).toContain('$99.99');
|
|
80
|
+
|
|
81
|
+
const emailMatches = await pdf.selectParagraphsMatching('[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z]+');
|
|
82
|
+
expect(emailMatches).toHaveLength(1);
|
|
83
|
+
expect(emailMatches[0].getText()).toContain('test@example.com');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('select paragraphs matching multiple pages', async () => {
|
|
87
|
+
const [baseUrl, token] = (await requireEnvAndFixture('Showcase.pdf')).slice(0, 2) as [string, string];
|
|
88
|
+
const pdf = await PDFDancer.new({initialPageCount: 3}, token, baseUrl);
|
|
89
|
+
|
|
90
|
+
await pdf.newParagraph().text('Chapter 1: Introduction').font(StandardFonts.HELVETICA, 14).at(0, 100, 100).add();
|
|
91
|
+
await pdf.newParagraph().text('Section 1.1').font(StandardFonts.HELVETICA, 12).at(0, 100, 200).add();
|
|
92
|
+
await pdf.newParagraph().text('Chapter 2: Methods').font(StandardFonts.HELVETICA, 14).at(1, 100, 100).add();
|
|
93
|
+
await pdf.newParagraph().text('Section 2.1').font(StandardFonts.HELVETICA, 12).at(1, 100, 200).add();
|
|
94
|
+
await pdf.newParagraph().text('Chapter 3: Results').font(StandardFonts.HELVETICA, 14).at(2, 100, 100).add();
|
|
95
|
+
await pdf.newParagraph().text('Section 3.1').font(StandardFonts.HELVETICA, 12).at(2, 100, 200).add();
|
|
96
|
+
|
|
97
|
+
expect((await pdf.selectParagraphsMatching('^Chapter [0-9]+:')).length).toBe(3);
|
|
98
|
+
expect((await pdf.selectParagraphsMatching('^Section [0-9]+\\.[0-9]+')).length).toBe(3);
|
|
99
|
+
|
|
100
|
+
const chaptersPage1 = await pdf.page(1).selectParagraphsMatching('^Chapter [0-9]+:');
|
|
101
|
+
expect(chaptersPage1.length).toBe(1);
|
|
102
|
+
expect(chaptersPage1[0].getText()).toContain('Chapter 2');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('select paragraphs matching empty results', async () => {
|
|
106
|
+
const [baseUrl, token] = (await requireEnvAndFixture('Showcase.pdf')).slice(0, 2) as [string, string];
|
|
107
|
+
const pdf = await PDFDancer.new({initialPageCount: 1}, token, baseUrl);
|
|
108
|
+
|
|
109
|
+
await pdf.newParagraph().text('Hello World').font(StandardFonts.HELVETICA, 12).at(0, 100, 100).add();
|
|
110
|
+
await pdf.newParagraph().text('Goodbye Moon').font(StandardFonts.HELVETICA, 12).at(0, 100, 200).add();
|
|
111
|
+
|
|
112
|
+
expect((await pdf.selectParagraphsMatching('[0-9]{5}')).length).toBe(0);
|
|
113
|
+
expect((await pdf.selectParagraphsMatching('^Nonexistent')).length).toBe(0);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('select paragraphs matching case sensitivity', async () => {
|
|
117
|
+
const [baseUrl, token] = (await requireEnvAndFixture('Showcase.pdf')).slice(0, 2) as [string, string];
|
|
118
|
+
const pdf = await PDFDancer.new({initialPageCount: 1}, token, baseUrl);
|
|
119
|
+
|
|
120
|
+
await pdf.newParagraph().text('UPPERCASE TEXT').font(StandardFonts.HELVETICA, 12).at(0, 100, 100).add();
|
|
121
|
+
await pdf.newParagraph().text('lowercase text').font(StandardFonts.HELVETICA, 12).at(0, 100, 200).add();
|
|
122
|
+
await pdf.newParagraph().text('MixedCase Text').font(StandardFonts.HELVETICA, 12).at(0, 100, 300).add();
|
|
123
|
+
|
|
124
|
+
expect((await pdf.selectParagraphsMatching('UPPERCASE')).length).toBe(1);
|
|
125
|
+
expect((await pdf.selectParagraphsMatching('lowercase')).length).toBe(1);
|
|
126
|
+
expect((await pdf.selectParagraphsMatching('(?i)text')).length).toBe(3);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('move paragraph retains formatting', async () => {
|
|
130
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
131
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
132
|
+
|
|
133
|
+
const [paragraph] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
134
|
+
const result = await paragraph.edit().moveTo(40, 40).apply();
|
|
135
|
+
expect(result).toBe(true);
|
|
136
|
+
|
|
137
|
+
const [moved] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
138
|
+
const status = moved.objectRef().status;
|
|
139
|
+
expect(status).toBeDefined();
|
|
140
|
+
expect(status?.isEncodable()).toBe(true);
|
|
141
|
+
expect(status?.getFontType()).toBe(FontType.EMBEDDED);
|
|
142
|
+
expect(status?.isModified()).toBe(false);
|
|
143
|
+
|
|
144
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
145
|
+
await assertions.assertTextlineHasFont(SAMPLE_PARAGRAPH, 'AAAZPH+Roboto-Regular', 12, 0);
|
|
146
|
+
await assertions.assertTextlineHasColor(SAMPLE_PARAGRAPH, new Color(0, 0, 0), 0);
|
|
147
|
+
await assertions.assertParagraphIsAt(SAMPLE_PARAGRAPH, 40, 40, 0);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('add paragraph with styling on Showcase', async () => {
|
|
151
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
152
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
153
|
+
|
|
154
|
+
const success = await pdf.page(0).newParagraph()
|
|
155
|
+
.text('Showcase Heading\nIn Two Lines')
|
|
156
|
+
.font(StandardFonts.HELVETICA_BOLD, 18)
|
|
157
|
+
.color(new Color(32, 64, 96))
|
|
158
|
+
.lineSpacing(1.5)
|
|
159
|
+
.at(300, 520)
|
|
160
|
+
.apply();
|
|
161
|
+
|
|
162
|
+
expect(success).toBe(true);
|
|
163
|
+
|
|
164
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
165
|
+
await assertions.assertTextlineHasFont('Showcase Heading', 'Helvetica-Bold', 18, 0);
|
|
166
|
+
await assertions.assertTextlineHasColor('Showcase Heading', new Color(32, 64, 96), 0);
|
|
167
|
+
await assertions.assertParagraphIsAt('Showcase Heading', 300, 520, 0);
|
|
168
|
+
});
|
|
169
|
+
test('modify paragraph full workflow', async () => {
|
|
170
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
171
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
172
|
+
|
|
173
|
+
const [paragraph] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
174
|
+
await paragraph.edit()
|
|
175
|
+
.replace('Awesomely\nObvious!')
|
|
176
|
+
.font('Helvetica', 12)
|
|
177
|
+
.lineSpacing(0.7)
|
|
178
|
+
.moveTo(300.1, 500)
|
|
179
|
+
.apply();
|
|
180
|
+
|
|
181
|
+
const moved = (await pdf.page(0).selectParagraphsAt(300.1, 500))[0];
|
|
182
|
+
const status = moved.objectRef().status;
|
|
183
|
+
expect(status).toBeDefined();
|
|
184
|
+
expect(status?.isEncodable()).toBe(true);
|
|
185
|
+
expect(status?.getFontType()).toBe(FontType.STANDARD);
|
|
186
|
+
expect(status?.isModified()).toBe(true);
|
|
187
|
+
|
|
188
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
189
|
+
await assertions.assertTextlineHasFont('Awesomely', 'Helvetica', 12);
|
|
190
|
+
await assertions.assertTextlineHasFont('Obvious!', 'Helvetica', 12);
|
|
191
|
+
await assertions.assertTextlineHasColor('Awesomely', new Color(0, 0, 0));
|
|
192
|
+
await assertions.assertTextlineHasColor('Obvious!', new Color(0, 0, 0));
|
|
193
|
+
await assertions.assertParagraphIsAt('Awesomely', 300.1, 500, 0);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('modify paragraph without position', async () => {
|
|
197
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
198
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
199
|
+
|
|
200
|
+
const [paragraph] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
201
|
+
const originalX = paragraph.position.getX()!;
|
|
202
|
+
const originalY = paragraph.position.getY()!;
|
|
203
|
+
|
|
204
|
+
await paragraph.edit()
|
|
205
|
+
.replace('Awesomely\nObvious!')
|
|
206
|
+
.font('Helvetica', 12)
|
|
207
|
+
.lineSpacing(0.7)
|
|
208
|
+
.apply();
|
|
209
|
+
|
|
210
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
211
|
+
await assertions.assertTextlineHasFont('Awesomely', 'Helvetica', 12);
|
|
212
|
+
await assertions.assertTextlineHasFont('Obvious!', 'Helvetica', 12);
|
|
213
|
+
await assertions.assertParagraphIsAt('Awesomely', originalX, originalY, 0);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('modify paragraph without position and spacing', async () => {
|
|
217
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
218
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
219
|
+
|
|
220
|
+
const [paragraph] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
221
|
+
const originalX = paragraph.position.getX()!;
|
|
222
|
+
const originalY = paragraph.position.getY()!;
|
|
223
|
+
|
|
224
|
+
await paragraph.edit()
|
|
225
|
+
.replace('Awesomely\nObvious!')
|
|
226
|
+
.font('Helvetica', 12)
|
|
227
|
+
.apply();
|
|
228
|
+
|
|
229
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
230
|
+
await assertions.assertTextlineHasFont('Awesomely', 'Helvetica', 12);
|
|
231
|
+
await assertions.assertTextlineHasFont('Obvious!', 'Helvetica', 12);
|
|
232
|
+
await assertions.assertParagraphIsAt('Awesomely', originalX, originalY, 0);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test('modify paragraph no-op', async () => {
|
|
236
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
237
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
238
|
+
|
|
239
|
+
const [paragraph] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
240
|
+
await paragraph.edit().apply();
|
|
241
|
+
|
|
242
|
+
const [updated] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
243
|
+
const status = updated.objectRef().status;
|
|
244
|
+
expect(status).toBeDefined();
|
|
245
|
+
expect(status?.isEncodable()).toBe(true);
|
|
246
|
+
expect(status?.getFontType()).toBe(FontType.EMBEDDED);
|
|
247
|
+
expect(status?.isModified()).toBe(false);
|
|
248
|
+
|
|
249
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
250
|
+
await assertions.assertTextlineHasFont(SAMPLE_PARAGRAPH, 'AAAZPH+Roboto-Regular', 12);
|
|
251
|
+
await assertions.assertTextlineHasColor(SAMPLE_PARAGRAPH, new Color(0, 0, 0));
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('modify paragraph text only', async () => {
|
|
255
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
256
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
257
|
+
|
|
258
|
+
const [paragraph] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
259
|
+
await paragraph.edit().replace('lorem\nipsum\nCaesar').apply();
|
|
260
|
+
|
|
261
|
+
const [updated] = await pdf.page(0).selectParagraphsStartingWith('lorem');
|
|
262
|
+
const status = updated.objectRef().status;
|
|
263
|
+
expect(status).toBeDefined();
|
|
264
|
+
expect(status?.isEncodable()).toBe(true);
|
|
265
|
+
expect(status?.getFontType()).toBe(FontType.EMBEDDED);
|
|
266
|
+
expect(status?.isModified()).toBe(true);
|
|
267
|
+
|
|
268
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
269
|
+
await assertions.assertTextlineDoesNotExist(SAMPLE_PARAGRAPH);
|
|
270
|
+
await assertions.assertTextlineHasColor('lorem', new Color(0, 0, 0));
|
|
271
|
+
await assertions.assertTextlineHasColor('ipsum', new Color(0, 0, 0));
|
|
272
|
+
await assertions.assertTextlineHasColor('Caesar', new Color(0, 0, 0));
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test('modify paragraph font only', async () => {
|
|
276
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
277
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
278
|
+
|
|
279
|
+
const [paragraph] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
280
|
+
await paragraph.edit().font('Helvetica', 28).apply();
|
|
281
|
+
|
|
282
|
+
const [updated] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
283
|
+
const status = updated.objectRef().status;
|
|
284
|
+
expect(status).toBeDefined();
|
|
285
|
+
expect(status?.isEncodable()).toBe(true);
|
|
286
|
+
expect(status?.getFontType()).toBe(FontType.STANDARD);
|
|
287
|
+
expect(status?.isModified()).toBe(true);
|
|
288
|
+
|
|
289
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
290
|
+
await assertions.assertTextlineHasFont(SAMPLE_PARAGRAPH, 'Helvetica', 28);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test('modify paragraph move only', async () => {
|
|
294
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
295
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
296
|
+
|
|
297
|
+
const [paragraph] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
298
|
+
await paragraph.edit().moveTo(40, 40).apply();
|
|
299
|
+
|
|
300
|
+
const [updated] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
301
|
+
const status = updated.objectRef().status;
|
|
302
|
+
expect(status).toBeDefined();
|
|
303
|
+
expect(status?.isEncodable()).toBe(true);
|
|
304
|
+
expect(status?.getFontType()).toBe(FontType.EMBEDDED);
|
|
305
|
+
expect(status?.isModified()).toBe(false);
|
|
306
|
+
|
|
307
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
308
|
+
await assertions.assertTextlineHasFont(SAMPLE_PARAGRAPH, 'AAAZPH+Roboto-Regular', 12);
|
|
309
|
+
await assertions.assertParagraphIsAt(SAMPLE_PARAGRAPH, 40, 40, 0);
|
|
310
|
+
await assertions.assertTextlineHasColor(SAMPLE_PARAGRAPH, new Color(0, 0, 0));
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test.skip('modify paragraph simple', async () => {
|
|
314
|
+
// Pending parity; Python suite skips because backend raises exception.
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test('add paragraph with custom font not found', async () => {
|
|
318
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
319
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
320
|
+
|
|
321
|
+
await expect(
|
|
322
|
+
pdf.newParagraph()
|
|
323
|
+
.text('Awesomely\nObvious!')
|
|
324
|
+
.font('Roboto', 14)
|
|
325
|
+
.lineSpacing(0.7)
|
|
326
|
+
.at(0, 300.1, 500)
|
|
327
|
+
.add()
|
|
328
|
+
).rejects.toThrow();
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
test('add paragraph with custom font via name', async () => {
|
|
332
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
333
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
334
|
+
|
|
335
|
+
await pdf.newParagraph()
|
|
336
|
+
.text('Awesomely\nObvious!')
|
|
337
|
+
.font('Roboto-Regular', 14)
|
|
338
|
+
.lineSpacing(0.7)
|
|
339
|
+
.at(0, 300.1, 500)
|
|
340
|
+
.add();
|
|
341
|
+
|
|
342
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
343
|
+
await assertions.assertTextlineHasFontMatching('Awesomely', 'Roboto-Regular', 14);
|
|
344
|
+
await assertions.assertTextlineHasFontMatching('Obvious!', 'Roboto-Regular', 14);
|
|
345
|
+
await assertions.assertTextlineHasColor('Awesomely', new Color(0, 0, 0));
|
|
346
|
+
await assertions.assertParagraphIsAt('Awesomely', 300.1, 500, 0);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
test('add paragraph with custom font via page builder', async () => {
|
|
350
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
351
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
352
|
+
|
|
353
|
+
await pdf.page(0).newParagraph()
|
|
354
|
+
.text('Awesomely\nObvious!')
|
|
355
|
+
.font('Roboto-Regular', 14)
|
|
356
|
+
.lineSpacing(0.7)
|
|
357
|
+
.at(300.1, 500)
|
|
358
|
+
.add();
|
|
359
|
+
|
|
360
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
361
|
+
await assertions.assertTextlineHasFontMatching('Awesomely', 'Roboto-Regular', 14);
|
|
362
|
+
await assertions.assertParagraphIsAt('Awesomely', 300.1, 500, 0);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test('add paragraph using findFonts result', async () => {
|
|
366
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
367
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
368
|
+
|
|
369
|
+
const fonts = await pdf.findFonts('Roboto', 14);
|
|
370
|
+
expect(fonts.length).toBeGreaterThan(0);
|
|
371
|
+
|
|
372
|
+
const roboto = fonts[0];
|
|
373
|
+
await pdf.newParagraph()
|
|
374
|
+
.text('Awesomely\nObvious!')
|
|
375
|
+
.font(roboto.name, roboto.size)
|
|
376
|
+
.lineSpacing(0.7)
|
|
377
|
+
.at(0, 300.1, 500)
|
|
378
|
+
.add();
|
|
379
|
+
|
|
380
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
381
|
+
await assertions.assertTextlineHasFontMatching('Awesomely', 'Roboto', 14);
|
|
382
|
+
await assertions.assertTextlineHasFontMatching('Obvious!', 'Roboto', 14);
|
|
383
|
+
await assertions.assertParagraphIsAt('Awesomely', 300.1, 500, 0);
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
test('add paragraph with custom font Asimovian', async () => {
|
|
387
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
388
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
389
|
+
|
|
390
|
+
const fonts = await pdf.findFonts('Asimovian', 14);
|
|
391
|
+
expect(fonts.length).toBeGreaterThan(0);
|
|
392
|
+
|
|
393
|
+
const asimov = fonts[0];
|
|
394
|
+
await pdf.newParagraph()
|
|
395
|
+
.text('Awesomely\nObvious!')
|
|
396
|
+
.font(asimov.name, asimov.size)
|
|
397
|
+
.lineSpacing(0.7)
|
|
398
|
+
.at(0, 300.1, 500)
|
|
399
|
+
.add();
|
|
400
|
+
|
|
401
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
402
|
+
await assertions.assertTextlineHasFontMatching('Awesomely', 'Asimovian-Regular', 14);
|
|
403
|
+
await assertions.assertParagraphIsAt('Awesomely', 300.1, 500, 0);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
test('add paragraph with font file', async () => {
|
|
407
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
408
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
409
|
+
|
|
410
|
+
const ttfPath = getFontPath('DancingScript-Regular.ttf');
|
|
411
|
+
await pdf.newParagraph()
|
|
412
|
+
.text('Awesomely\nObvious!')
|
|
413
|
+
.fontFile(ttfPath, 24)
|
|
414
|
+
.lineSpacing(1.8)
|
|
415
|
+
.color(new Color(0, 0, 255))
|
|
416
|
+
.at(0, 300.1, 500)
|
|
417
|
+
.add();
|
|
418
|
+
|
|
419
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
420
|
+
await assertions.assertTextlineHasFontMatching('Awesomely', 'DancingScript-Regular', 24);
|
|
421
|
+
await assertions.assertTextlineHasFontMatching('Obvious!', 'DancingScript-Regular', 24);
|
|
422
|
+
await assertions.assertTextlineHasColor('Awesomely', new Color(0, 0, 255));
|
|
423
|
+
await assertions.assertTextlineHasColor('Obvious!', new Color(0, 0, 255));
|
|
424
|
+
await assertions.assertParagraphIsAt('Awesomely', 300.1, 500, 0);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
test('add paragraph with standard font times', async () => {
|
|
428
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
429
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
430
|
+
|
|
431
|
+
await pdf.newParagraph()
|
|
432
|
+
.text('Times Roman Test')
|
|
433
|
+
.font(StandardFonts.TIMES_ROMAN, 14)
|
|
434
|
+
.at(0, 150, 150)
|
|
435
|
+
.add();
|
|
436
|
+
|
|
437
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
438
|
+
await assertions.assertTextHasFont('Times Roman Test', StandardFonts.TIMES_ROMAN, 14);
|
|
439
|
+
await assertions.assertParagraphIsAt('Times Roman Test', 150, 150, 0);
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
test('add paragraph with standard font courier', async () => {
|
|
443
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
444
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
445
|
+
|
|
446
|
+
await pdf.newParagraph()
|
|
447
|
+
.text('Courier MonospacenCode Example')
|
|
448
|
+
.font(StandardFonts.COURIER_BOLD, 12)
|
|
449
|
+
.lineSpacing(1.5)
|
|
450
|
+
.at(0, 200, 200)
|
|
451
|
+
.add();
|
|
452
|
+
|
|
453
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
454
|
+
await assertions.assertTextHasFont('Courier Monospace', StandardFonts.COURIER_BOLD, 12, 0);
|
|
455
|
+
await assertions.assertParagraphIsAt('Courier Monospace', 200, 200, 0);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
test('paragraph color reading', async () => {
|
|
459
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
460
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
461
|
+
|
|
462
|
+
await pdf.newParagraph()
|
|
463
|
+
.text('Red Color Test')
|
|
464
|
+
.font(StandardFonts.HELVETICA, 14)
|
|
465
|
+
.color(new Color(255, 0, 0))
|
|
466
|
+
.at(0, 100, 100)
|
|
467
|
+
.add();
|
|
468
|
+
|
|
469
|
+
await pdf.newParagraph()
|
|
470
|
+
.text('Blue Color Test')
|
|
471
|
+
.font(StandardFonts.HELVETICA, 14)
|
|
472
|
+
.color(new Color(0, 0, 255))
|
|
473
|
+
.at(0, 100, 120)
|
|
474
|
+
.add();
|
|
475
|
+
|
|
476
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
477
|
+
await assertions.assertTextlineHasColor('Blue Color Test', new Color(0, 0, 255), 0);
|
|
478
|
+
await assertions.assertTextlineHasColor('Red Color Test', new Color(255, 0, 0), 0);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
test('add paragraph to new page', async () => {
|
|
482
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Empty.pdf');
|
|
483
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
484
|
+
|
|
485
|
+
await pdf.page(0).newParagraph()
|
|
486
|
+
.text('Awesome')
|
|
487
|
+
.font('Roboto-Regular', 14)
|
|
488
|
+
.at(50, 100)
|
|
489
|
+
.add();
|
|
490
|
+
|
|
491
|
+
const assertions = await PDFAssertions.create(pdf);
|
|
492
|
+
await assertions.assertTextlineHasFontMatching('Awesome', 'Roboto-Regular', 14);
|
|
493
|
+
await assertions.assertTextlineHasColor('Awesome', new Color(0, 0, 0));
|
|
494
|
+
await assertions.assertParagraphIsAt('Awesome', 50, 100, 0);
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
test('delete paragraph', async () => {
|
|
498
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
499
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
500
|
+
|
|
501
|
+
const [paragraph] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
502
|
+
await paragraph.delete();
|
|
503
|
+
|
|
504
|
+
const remaining = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
505
|
+
expect(remaining).toHaveLength(0);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
test('move paragraph via moveTo', async () => {
|
|
509
|
+
const [baseUrl, token, pdfData] = await requireEnvAndFixture('Showcase.pdf');
|
|
510
|
+
const pdf = await PDFDancer.open(pdfData, token, baseUrl);
|
|
511
|
+
|
|
512
|
+
const [paragraph] = await pdf.page(0).selectParagraphsStartingWith(SAMPLE_PARAGRAPH);
|
|
513
|
+
await paragraph.moveTo(0.1, 300);
|
|
514
|
+
|
|
515
|
+
const moved = await pdf.page(0).selectParagraphsAt(0.1, 300);
|
|
516
|
+
expect(moved.length).toBeGreaterThan(0);
|
|
517
|
+
|
|
518
|
+
const status = moved[0].objectRef().status;
|
|
519
|
+
expect(status).toBeDefined();
|
|
520
|
+
expect(status?.isEncodable()).toBe(true);
|
|
521
|
+
expect(status?.getFontType()).toBe(FontType.EMBEDDED);
|
|
522
|
+
expect(status?.isModified()).toBe(false);
|
|
523
|
+
});
|