@pdfme/manipulator 5.3.8-dev.9 → 5.3.9-dev.1

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.
@@ -5,231 +5,252 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const fs_1 = __importDefault(require("fs"));
7
7
  const path_1 = __importDefault(require("path"));
8
- const index_1 = require("../src/index");
9
- const utils_1 = require("./utils");
8
+ const pdf_lib_1 = require("@pdfme/pdf-lib");
9
+ const converter_1 = require("@pdfme/converter");
10
+ const index_js_1 = require("../src/index.js");
10
11
  require("jest-image-snapshot");
12
+ const createTestPDF = async (pageCount) => {
13
+ const pdfDoc = await pdf_lib_1.PDFDocument.create();
14
+ for (let i = 0; i < pageCount; i++) {
15
+ const page = pdfDoc.addPage([500, 500]);
16
+ page.drawText(`Page ${i + 1}`, {
17
+ x: 50,
18
+ y: 450,
19
+ size: 20,
20
+ });
21
+ }
22
+ return pdfDoc.save();
23
+ };
24
+ const pdfToImages = async (pdf) => {
25
+ const arrayBuffers = await (0, converter_1.pdf2img)(pdf, { imageType: 'png' });
26
+ return arrayBuffers.map((buf) => Buffer.from(new Uint8Array(buf)));
27
+ };
28
+ const getPDFPageCount = async (pdf) => {
29
+ const pdfDoc = await pdf_lib_1.PDFDocument.load(pdf);
30
+ return pdfDoc.getPageCount();
31
+ };
11
32
  describe('merge', () => {
12
33
  test('merges multiple PDFs', async () => {
13
- const pdf1 = await (0, utils_1.createTestPDF)(2);
14
- const pdf2 = await (0, utils_1.createTestPDF)(3);
15
- const merged = await (0, index_1.merge)([pdf1, pdf2]);
16
- expect(await (0, utils_1.getPDFPageCount)(merged)).toBe(5);
34
+ const pdf1 = await createTestPDF(2);
35
+ const pdf2 = await createTestPDF(3);
36
+ const merged = await (0, index_js_1.merge)([pdf1, pdf2]);
37
+ expect(await getPDFPageCount(merged)).toBe(5);
17
38
  });
18
39
  test('throws error when no PDFs provided', async () => {
19
- await expect((0, index_1.merge)([])).rejects.toThrow('[@pdfme/manipulator] At least one PDF is required');
40
+ await expect((0, index_js_1.merge)([])).rejects.toThrow('[@pdfme/manipulator] At least one PDF is required');
20
41
  });
21
42
  });
22
43
  describe('split', () => {
23
44
  test('splits PDF into ranges', async () => {
24
- const pdf = await (0, utils_1.createTestPDF)(5);
25
- const splits = await (0, index_1.split)(pdf, [
45
+ const pdf = await createTestPDF(5);
46
+ const splits = await (0, index_js_1.split)(pdf, [
26
47
  { start: 0, end: 1 },
27
48
  { start: 2, end: 4 },
28
49
  ]);
29
50
  expect(splits.length).toBe(2);
30
- expect(await (0, utils_1.getPDFPageCount)(splits[0])).toBe(2);
31
- expect(await (0, utils_1.getPDFPageCount)(splits[1])).toBe(3);
51
+ expect(await getPDFPageCount(splits[0])).toBe(2);
52
+ expect(await getPDFPageCount(splits[1])).toBe(3);
32
53
  });
33
54
  test('throws error for invalid ranges', async () => {
34
- const pdf = await (0, utils_1.createTestPDF)(3);
35
- await expect((0, index_1.split)(pdf, [{ start: 1, end: 0 }])).rejects.toThrow('[@pdfme/manipulator] Invalid range');
55
+ const pdf = await createTestPDF(3);
56
+ await expect((0, index_js_1.split)(pdf, [{ start: 1, end: 0 }])).rejects.toThrow('[@pdfme/manipulator] Invalid range');
36
57
  });
37
58
  });
38
59
  describe('remove', () => {
39
60
  test('removes specified pages from PDF', async () => {
40
- const pdf = await (0, utils_1.createTestPDF)(5);
41
- const result = await (0, index_1.remove)(pdf, [1, 3]);
42
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(3);
61
+ const pdf = await createTestPDF(5);
62
+ const result = await (0, index_js_1.remove)(pdf, [1, 3]);
63
+ expect(await getPDFPageCount(result)).toBe(3);
43
64
  });
44
65
  test('throws error when no pages provided', async () => {
45
- const pdf = await (0, utils_1.createTestPDF)(3);
46
- await expect((0, index_1.remove)(pdf, [])).rejects.toThrow('[@pdfme/manipulator] At least one page number is required');
66
+ const pdf = await createTestPDF(3);
67
+ await expect((0, index_js_1.remove)(pdf, [])).rejects.toThrow('[@pdfme/manipulator] At least one page number is required');
47
68
  });
48
69
  test('throws error for invalid page numbers', async () => {
49
- const pdf = await (0, utils_1.createTestPDF)(3);
50
- await expect((0, index_1.remove)(pdf, [3])).rejects.toThrow('[@pdfme/manipulator] Invalid page number');
70
+ const pdf = await createTestPDF(3);
71
+ await expect((0, index_js_1.remove)(pdf, [3])).rejects.toThrow('[@pdfme/manipulator] Invalid page number');
51
72
  });
52
73
  });
53
74
  describe('insert', () => {
54
75
  test('inserts PDF at specified position', async () => {
55
- const basePdf = await (0, utils_1.createTestPDF)(3);
56
- const insertPdf = await (0, utils_1.createTestPDF)(2);
57
- const result = await (0, index_1.insert)(basePdf, [{ pdf: insertPdf, position: 1 }]);
58
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(5);
76
+ const basePdf = await createTestPDF(3);
77
+ const insertPdf = await createTestPDF(2);
78
+ const result = await (0, index_js_1.insert)(basePdf, [{ pdf: insertPdf, position: 1 }]);
79
+ expect(await getPDFPageCount(result)).toBe(5);
59
80
  });
60
81
  test('throws error for invalid position', async () => {
61
- const basePdf = await (0, utils_1.createTestPDF)(3);
62
- const insertPdf = await (0, utils_1.createTestPDF)(2);
63
- await expect((0, index_1.insert)(basePdf, [{ pdf: insertPdf, position: 4 }])).rejects.toThrow('[@pdfme/manipulator] Invalid position');
82
+ const basePdf = await createTestPDF(3);
83
+ const insertPdf = await createTestPDF(2);
84
+ await expect((0, index_js_1.insert)(basePdf, [{ pdf: insertPdf, position: 4 }])).rejects.toThrow('[@pdfme/manipulator] Invalid position');
64
85
  });
65
86
  });
66
87
  describe('rotate', () => {
67
88
  test('rotates PDF pages by specified degrees', async () => {
68
- const pdf = await (0, utils_1.createTestPDF)(2);
69
- const result = await (0, index_1.rotate)(pdf, 90);
70
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(2);
89
+ const pdf = await createTestPDF(2);
90
+ const result = await (0, index_js_1.rotate)(pdf, 90);
91
+ expect(await getPDFPageCount(result)).toBe(2);
71
92
  });
72
93
  test('throws error for non-90-degree rotation', async () => {
73
- const pdf = await (0, utils_1.createTestPDF)(2);
94
+ const pdf = await createTestPDF(2);
74
95
  // @ts-expect-error
75
- await expect((0, index_1.rotate)(pdf, 45)).rejects.toThrow('[@pdfme/manipulator] Rotation degrees must be a multiple of 90');
96
+ await expect((0, index_js_1.rotate)(pdf, 45)).rejects.toThrow('[@pdfme/manipulator] Rotation degrees must be a multiple of 90');
76
97
  });
77
98
  });
78
99
  describe('move', () => {
79
100
  test('moves page from one position to another', async () => {
80
- const pdf = await (0, utils_1.createTestPDF)(3);
81
- const result = await (0, index_1.move)(pdf, { from: 0, to: 2 });
82
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(3);
101
+ const pdf = await createTestPDF(3);
102
+ const result = await (0, index_js_1.move)(pdf, { from: 0, to: 2 });
103
+ expect(await getPDFPageCount(result)).toBe(3);
83
104
  });
84
105
  test('throws error for invalid page numbers', async () => {
85
- const pdf = await (0, utils_1.createTestPDF)(3);
86
- await expect((0, index_1.move)(pdf, { from: 3, to: 0 })).rejects.toThrow('[@pdfme/manipulator] Invalid page number: from=3, to=0, total pages=3');
106
+ const pdf = await createTestPDF(3);
107
+ await expect((0, index_js_1.move)(pdf, { from: 3, to: 0 })).rejects.toThrow('[@pdfme/manipulator] Invalid page number: from=3, to=0, total pages=3');
87
108
  });
88
109
  });
89
110
  describe('organize', () => {
90
111
  test('performs single remove operation', async () => {
91
- const pdf = await (0, utils_1.createTestPDF)(5);
92
- const result = await (0, index_1.organize)(pdf, [
112
+ const pdf = await createTestPDF(5);
113
+ const result = await (0, index_js_1.organize)(pdf, [
93
114
  { type: 'remove', data: { position: 1 } },
94
115
  { type: 'remove', data: { position: 3 } },
95
116
  ]);
96
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(3);
117
+ expect(await getPDFPageCount(result)).toBe(3);
97
118
  });
98
119
  test('performs single insert operation', async () => {
99
- const pdf = await (0, utils_1.createTestPDF)(3);
100
- const insertPdf = await (0, utils_1.createTestPDF)(2);
101
- const result = await (0, index_1.organize)(pdf, [{ type: 'insert', data: { pdf: insertPdf, position: 1 } }]);
102
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(5);
120
+ const pdf = await createTestPDF(3);
121
+ const insertPdf = await createTestPDF(2);
122
+ const result = await (0, index_js_1.organize)(pdf, [{ type: 'insert', data: { pdf: insertPdf, position: 1 } }]);
123
+ expect(await getPDFPageCount(result)).toBe(5);
103
124
  });
104
125
  test('performs single replace operation', async () => {
105
- const pdf = await (0, utils_1.createTestPDF)(3);
106
- const replacePdf = await (0, utils_1.createTestPDF)(1);
107
- const result = await (0, index_1.organize)(pdf, [
126
+ const pdf = await createTestPDF(3);
127
+ const replacePdf = await createTestPDF(1);
128
+ const result = await (0, index_js_1.organize)(pdf, [
108
129
  { type: 'replace', data: { position: 1, pdf: replacePdf } },
109
130
  ]);
110
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(3);
131
+ expect(await getPDFPageCount(result)).toBe(3);
111
132
  });
112
133
  test('performs single rotate operation', async () => {
113
- const pdf = await (0, utils_1.createTestPDF)(3);
114
- const result = await (0, index_1.organize)(pdf, [
134
+ const pdf = await createTestPDF(3);
135
+ const result = await (0, index_js_1.organize)(pdf, [
115
136
  { type: 'rotate', data: { position: 0, degrees: 90 } },
116
137
  { type: 'rotate', data: { position: 2, degrees: 90 } },
117
138
  ]);
118
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(3);
139
+ expect(await getPDFPageCount(result)).toBe(3);
119
140
  });
120
141
  test('performs multiple operations in sequence', async () => {
121
- const pdf = await (0, utils_1.createTestPDF)(5);
122
- const insertPdf = await (0, utils_1.createTestPDF)(2);
123
- const replacePdf = await (0, utils_1.createTestPDF)(1);
124
- const result = await (0, index_1.organize)(pdf, [
142
+ const pdf = await createTestPDF(5);
143
+ const insertPdf = await createTestPDF(2);
144
+ const replacePdf = await createTestPDF(1);
145
+ const result = await (0, index_js_1.organize)(pdf, [
125
146
  { type: 'remove', data: { position: 1 } },
126
- { type: 'remove', data: { position: 3 } },
127
- { type: 'insert', data: { pdf: insertPdf, position: 1 } },
128
- { type: 'replace', data: { position: 2, pdf: replacePdf } },
147
+ { type: 'remove', data: { position: 3 } }, // 5 -> 3 pages
148
+ { type: 'insert', data: { pdf: insertPdf, position: 1 } }, // 3 -> 5 pages
149
+ { type: 'replace', data: { position: 2, pdf: replacePdf } }, // Still 5 pages
129
150
  { type: 'rotate', data: { position: 0, degrees: 90 } },
130
151
  { type: 'rotate', data: { position: 3, degrees: 90 } }, // Still 5 pages
131
152
  ]);
132
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(5);
153
+ expect(await getPDFPageCount(result)).toBe(5);
133
154
  });
134
155
  test('throws error for invalid page numbers', async () => {
135
- const pdf = await (0, utils_1.createTestPDF)(3);
136
- await expect((0, index_1.organize)(pdf, [{ type: 'remove', data: { position: 3 } }])).rejects.toThrow('[@pdfme/manipulator] Invalid page number');
156
+ const pdf = await createTestPDF(3);
157
+ await expect((0, index_js_1.organize)(pdf, [{ type: 'remove', data: { position: 3 } }])).rejects.toThrow('[@pdfme/manipulator] Invalid page number');
137
158
  });
138
159
  test('throws error for invalid position', async () => {
139
- const pdf = await (0, utils_1.createTestPDF)(3);
140
- const insertPdf = await (0, utils_1.createTestPDF)(1);
141
- await expect((0, index_1.organize)(pdf, [{ type: 'insert', data: { pdf: insertPdf, position: 4 } }])).rejects.toThrow('[@pdfme/manipulator] Invalid position');
160
+ const pdf = await createTestPDF(3);
161
+ const insertPdf = await createTestPDF(1);
162
+ await expect((0, index_js_1.organize)(pdf, [{ type: 'insert', data: { pdf: insertPdf, position: 4 } }])).rejects.toThrow('[@pdfme/manipulator] Invalid position');
142
163
  });
143
164
  test('throws error for invalid rotation degrees', async () => {
144
- const pdf = await (0, utils_1.createTestPDF)(3);
165
+ const pdf = await createTestPDF(3);
145
166
  await expect(
146
167
  // @ts-expect-error
147
- (0, index_1.organize)(pdf, [{ type: 'rotate', data: { pages: [0], degrees: 45 } }])).rejects.toThrow('[@pdfme/manipulator] Rotation degrees must be a multiple of 90');
168
+ (0, index_js_1.organize)(pdf, [{ type: 'rotate', data: { pages: [0], degrees: 45 } }])).rejects.toThrow('[@pdfme/manipulator] Rotation degrees must be a multiple of 90');
148
169
  });
149
170
  test('throws error for empty actions array', async () => {
150
- const pdf = await (0, utils_1.createTestPDF)(3);
151
- await expect((0, index_1.organize)(pdf, [])).rejects.toThrow('[@pdfme/manipulator] At least one action is required');
171
+ const pdf = await createTestPDF(3);
172
+ await expect((0, index_js_1.organize)(pdf, [])).rejects.toThrow('[@pdfme/manipulator] At least one action is required');
152
173
  });
153
174
  test('throws error for unknown action type', async () => {
154
- const pdf = await (0, utils_1.createTestPDF)(3);
175
+ const pdf = await createTestPDF(3);
155
176
  // @ts-expect-error
156
- await expect((0, index_1.organize)(pdf, [{ type: 'invalid', data: { pages: [] } }])).rejects.toThrow('[@pdfme/manipulator] Unknown action type: invalid');
177
+ await expect((0, index_js_1.organize)(pdf, [{ type: 'invalid', data: { pages: [] } }])).rejects.toThrow('[@pdfme/manipulator] Unknown action type: invalid');
157
178
  });
158
179
  });
159
180
  describe('organize', () => {
160
181
  test('performs single remove operation', async () => {
161
- const pdf = await (0, utils_1.createTestPDF)(5);
162
- const result = await (0, index_1.organize)(pdf, [
182
+ const pdf = await createTestPDF(5);
183
+ const result = await (0, index_js_1.organize)(pdf, [
163
184
  { type: 'remove', data: { position: 1 } },
164
185
  { type: 'remove', data: { position: 3 } },
165
186
  ]);
166
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(3);
187
+ expect(await getPDFPageCount(result)).toBe(3);
167
188
  });
168
189
  test('performs single insert operation', async () => {
169
- const pdf = await (0, utils_1.createTestPDF)(3);
170
- const insertPdf = await (0, utils_1.createTestPDF)(2);
171
- const result = await (0, index_1.organize)(pdf, [{ type: 'insert', data: { pdf: insertPdf, position: 1 } }]);
172
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(5);
190
+ const pdf = await createTestPDF(3);
191
+ const insertPdf = await createTestPDF(2);
192
+ const result = await (0, index_js_1.organize)(pdf, [{ type: 'insert', data: { pdf: insertPdf, position: 1 } }]);
193
+ expect(await getPDFPageCount(result)).toBe(5);
173
194
  });
174
195
  test('performs single replace operation', async () => {
175
- const pdf = await (0, utils_1.createTestPDF)(3);
176
- const replacePdf = await (0, utils_1.createTestPDF)(1);
177
- const result = await (0, index_1.organize)(pdf, [
196
+ const pdf = await createTestPDF(3);
197
+ const replacePdf = await createTestPDF(1);
198
+ const result = await (0, index_js_1.organize)(pdf, [
178
199
  { type: 'replace', data: { position: 1, pdf: replacePdf } },
179
200
  ]);
180
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(3);
201
+ expect(await getPDFPageCount(result)).toBe(3);
181
202
  });
182
203
  test('performs single rotate operation', async () => {
183
- const pdf = await (0, utils_1.createTestPDF)(3);
184
- const result = await (0, index_1.organize)(pdf, [
204
+ const pdf = await createTestPDF(3);
205
+ const result = await (0, index_js_1.organize)(pdf, [
185
206
  { type: 'rotate', data: { position: 0, degrees: 90 } },
186
207
  { type: 'rotate', data: { position: 2, degrees: 90 } },
187
208
  ]);
188
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(3);
209
+ expect(await getPDFPageCount(result)).toBe(3);
189
210
  });
190
211
  test('performs multiple operations in sequence', async () => {
191
- const pdf = await (0, utils_1.createTestPDF)(5);
192
- const insertPdf = await (0, utils_1.createTestPDF)(2);
193
- const replacePdf = await (0, utils_1.createTestPDF)(1);
194
- const result = await (0, index_1.organize)(pdf, [
212
+ const pdf = await createTestPDF(5);
213
+ const insertPdf = await createTestPDF(2);
214
+ const replacePdf = await createTestPDF(1);
215
+ const result = await (0, index_js_1.organize)(pdf, [
195
216
  { type: 'remove', data: { position: 1 } },
196
- { type: 'remove', data: { position: 3 } },
197
- { type: 'insert', data: { pdf: insertPdf, position: 1 } },
198
- { type: 'replace', data: { position: 2, pdf: replacePdf } },
217
+ { type: 'remove', data: { position: 3 } }, // 5 -> 3 pages
218
+ { type: 'insert', data: { pdf: insertPdf, position: 1 } }, // 3 -> 5 pages
219
+ { type: 'replace', data: { position: 2, pdf: replacePdf } }, // Still 5 pages
199
220
  { type: 'rotate', data: { position: 0, degrees: 90 } },
200
221
  { type: 'rotate', data: { position: 3, degrees: 90 } }, // Still 5 pages
201
222
  ]);
202
- expect(await (0, utils_1.getPDFPageCount)(result)).toBe(5);
223
+ expect(await getPDFPageCount(result)).toBe(5);
203
224
  });
204
225
  test('throws error for invalid page numbers', async () => {
205
- const pdf = await (0, utils_1.createTestPDF)(3);
206
- await expect((0, index_1.organize)(pdf, [{ type: 'remove', data: { position: 3 } }])).rejects.toThrow('[@pdfme/manipulator] Invalid page number');
226
+ const pdf = await createTestPDF(3);
227
+ await expect((0, index_js_1.organize)(pdf, [{ type: 'remove', data: { position: 3 } }])).rejects.toThrow('[@pdfme/manipulator] Invalid page number');
207
228
  });
208
229
  test('throws error for invalid position', async () => {
209
- const pdf = await (0, utils_1.createTestPDF)(3);
210
- const insertPdf = await (0, utils_1.createTestPDF)(1);
211
- await expect((0, index_1.organize)(pdf, [{ type: 'insert', data: { pdf: insertPdf, position: 4 } }])).rejects.toThrow('[@pdfme/manipulator] Invalid position');
230
+ const pdf = await createTestPDF(3);
231
+ const insertPdf = await createTestPDF(1);
232
+ await expect((0, index_js_1.organize)(pdf, [{ type: 'insert', data: { pdf: insertPdf, position: 4 } }])).rejects.toThrow('[@pdfme/manipulator] Invalid position');
212
233
  });
213
234
  test('throws error for invalid rotation degrees', async () => {
214
- const pdf = await (0, utils_1.createTestPDF)(3);
235
+ const pdf = await createTestPDF(3);
215
236
  await expect(
216
237
  // @ts-expect-error
217
- (0, index_1.organize)(pdf, [{ type: 'rotate', data: { pages: [0], degrees: 45 } }])).rejects.toThrow('[@pdfme/manipulator] Rotation degrees must be a multiple of 90');
238
+ (0, index_js_1.organize)(pdf, [{ type: 'rotate', data: { pages: [0], degrees: 45 } }])).rejects.toThrow('[@pdfme/manipulator] Rotation degrees must be a multiple of 90');
218
239
  });
219
240
  test('throws error for empty actions array', async () => {
220
- const pdf = await (0, utils_1.createTestPDF)(3);
221
- await expect((0, index_1.organize)(pdf, [])).rejects.toThrow('[@pdfme/manipulator] At least one action is required');
241
+ const pdf = await createTestPDF(3);
242
+ await expect((0, index_js_1.organize)(pdf, [])).rejects.toThrow('[@pdfme/manipulator] At least one action is required');
222
243
  });
223
244
  test('throws error for unknown action type', async () => {
224
- const pdf = await (0, utils_1.createTestPDF)(3);
245
+ const pdf = await createTestPDF(3);
225
246
  // @ts-expect-error
226
- await expect((0, index_1.organize)(pdf, [{ type: 'invalid', data: { pages: [] } }])).rejects.toThrow('[@pdfme/manipulator] Unknown action type: invalid');
247
+ await expect((0, index_js_1.organize)(pdf, [{ type: 'invalid', data: { pages: [] } }])).rejects.toThrow('[@pdfme/manipulator] Unknown action type: invalid');
227
248
  });
228
249
  });
229
250
  describe('PDF manipulator E2E Tests with real PDF files', () => {
230
251
  const assetPath = (fileName) => path_1.default.join(__dirname, 'assets/pdfs', fileName);
231
252
  function toArrayBuffer(buf) {
232
- return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
253
+ return new Uint8Array(buf);
233
254
  }
234
255
  const fiveP = toArrayBuffer(fs_1.default.readFileSync(assetPath('5p.pdf')));
235
256
  const aPdf = toArrayBuffer(fs_1.default.readFileSync(assetPath('a.pdf')));
@@ -239,8 +260,8 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
239
260
  // merge
240
261
  //
241
262
  test('merge: merge a.pdf, b.pdf, c.pdf in order', async () => {
242
- const mergedBuffer = await (0, index_1.merge)([aPdf, bPdf, cPdf]);
243
- const images = await (0, utils_1.pdfToImages)(mergedBuffer);
263
+ const mergedBuffer = await (0, index_js_1.merge)([aPdf, bPdf, cPdf]);
264
+ const images = await pdfToImages(mergedBuffer);
244
265
  for (let i = 0; i < images.length; i++) {
245
266
  expect(images[i]).toMatchImageSnapshot({
246
267
  customSnapshotIdentifier: `merge-abc-page${i + 1}`,
@@ -251,12 +272,12 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
251
272
  // split
252
273
  //
253
274
  test('split: split 5p.pdf into pages 1-2 and 3-5', async () => {
254
- const [split12, split35] = await (0, index_1.split)(fiveP, [
255
- { start: 0, end: 1 },
275
+ const [split12, split35] = await (0, index_js_1.split)(fiveP, [
276
+ { start: 0, end: 1 }, // pages 1-2
256
277
  { start: 2, end: 4 }, // pages 3-5
257
278
  ]);
258
- const images12 = await (0, utils_1.pdfToImages)(split12);
259
- const images35 = await (0, utils_1.pdfToImages)(split35);
279
+ const images12 = await pdfToImages(split12);
280
+ const images35 = await pdfToImages(split35);
260
281
  for (let i = 0; i < images12.length; i++) {
261
282
  expect(images12[i]).toMatchImageSnapshot({
262
283
  customSnapshotIdentifier: `split-5p-1-2-page${i + 1}`,
@@ -272,8 +293,8 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
272
293
  // remove
273
294
  //
274
295
  test('remove: remove the 1st page of 5p.pdf', async () => {
275
- const removed = await (0, index_1.remove)(fiveP, [0]);
276
- const images = await (0, utils_1.pdfToImages)(removed);
296
+ const removed = await (0, index_js_1.remove)(fiveP, [0]);
297
+ const images = await pdfToImages(removed);
277
298
  for (let i = 0; i < images.length; i++) {
278
299
  expect(images[i]).toMatchImageSnapshot({
279
300
  customSnapshotIdentifier: `remove-5p-page1-result-page${i + 1}`,
@@ -282,8 +303,8 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
282
303
  });
283
304
  test('remove: remove the 1st and 3rd pages of 5p.pdf', async () => {
284
305
  // Note: This assumes removing all at once, not one by one with index shifting
285
- const removed = await (0, index_1.remove)(fiveP, [0, 2]);
286
- const images = await (0, utils_1.pdfToImages)(removed);
306
+ const removed = await (0, index_js_1.remove)(fiveP, [0, 2]);
307
+ const images = await pdfToImages(removed);
287
308
  for (let i = 0; i < images.length; i++) {
288
309
  expect(images[i]).toMatchImageSnapshot({
289
310
  customSnapshotIdentifier: `remove-5p-pages1-3-result-page${i + 1}`,
@@ -294,8 +315,8 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
294
315
  // insert
295
316
  //
296
317
  test('insert: insert a.pdf at position 0 in 5p.pdf', async () => {
297
- const inserted = await (0, index_1.insert)(fiveP, [{ pdf: aPdf, position: 0 }]);
298
- const images = await (0, utils_1.pdfToImages)(inserted);
318
+ const inserted = await (0, index_js_1.insert)(fiveP, [{ pdf: aPdf, position: 0 }]);
319
+ const images = await pdfToImages(inserted);
299
320
  for (let i = 0; i < images.length; i++) {
300
321
  expect(images[i]).toMatchImageSnapshot({
301
322
  customSnapshotIdentifier: `insert-5p-a-at-0-result-page${i + 1}`,
@@ -304,11 +325,11 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
304
325
  });
305
326
  test('insert: insert a.pdf at position 0 and 2 in 5p.pdf', async () => {
306
327
  // Note: the second insert is done in the same buffer, so the offset changes after the first insert
307
- const inserted = await (0, index_1.insert)(fiveP, [
328
+ const inserted = await (0, index_js_1.insert)(fiveP, [
308
329
  { pdf: aPdf, position: 0 },
309
330
  { pdf: aPdf, position: 2 }, // The PDF is 6 pages after the first insert
310
331
  ]);
311
- const images = await (0, utils_1.pdfToImages)(inserted);
332
+ const images = await pdfToImages(inserted);
312
333
  for (let i = 0; i < images.length; i++) {
313
334
  expect(images[i]).toMatchImageSnapshot({
314
335
  customSnapshotIdentifier: `insert-5p-a-at-0-and-2-result-page${i + 1}`,
@@ -319,8 +340,8 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
319
340
  // rotate
320
341
  //
321
342
  test('rotate: rotate all pages of 5p.pdf by 90 degrees', async () => {
322
- const rotated = await (0, index_1.rotate)(fiveP, 90);
323
- const images = await (0, utils_1.pdfToImages)(rotated);
343
+ const rotated = await (0, index_js_1.rotate)(fiveP, 90);
344
+ const images = await pdfToImages(rotated);
324
345
  for (let i = 0; i < images.length; i++) {
325
346
  expect(images[i]).toMatchImageSnapshot({
326
347
  customSnapshotIdentifier: `rotate-5p-90deg-all-result-page${i + 1}`,
@@ -329,8 +350,8 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
329
350
  });
330
351
  test('rotate: rotate only the 2nd page of 5p.pdf by 180 degrees', async () => {
331
352
  // pageNumbers=[1] -> only the 2nd page is rotated by 180 degrees
332
- const rotated = await (0, index_1.rotate)(fiveP, 180, [1]);
333
- const images = await (0, utils_1.pdfToImages)(rotated);
353
+ const rotated = await (0, index_js_1.rotate)(fiveP, 180, [1]);
354
+ const images = await pdfToImages(rotated);
334
355
  for (let i = 0; i < images.length; i++) {
335
356
  expect(images[i]).toMatchImageSnapshot({
336
357
  customSnapshotIdentifier: `rotate-5p-180deg-page1-result-page${i + 1}`,
@@ -339,8 +360,8 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
339
360
  });
340
361
  test('rotate: rotate pages 2 and 4 of 5p.pdf by 270 degrees', async () => {
341
362
  // Rotate the 2nd and 4th pages by 270 degrees
342
- const rotated = await (0, index_1.rotate)(fiveP, 270, [1, 3]);
343
- const images = await (0, utils_1.pdfToImages)(rotated);
363
+ const rotated = await (0, index_js_1.rotate)(fiveP, 270, [1, 3]);
364
+ const images = await pdfToImages(rotated);
344
365
  for (let i = 0; i < images.length; i++) {
345
366
  expect(images[i]).toMatchImageSnapshot({
346
367
  customSnapshotIdentifier: `rotate-5p-270deg-pages1-3-result-page${i + 1}`,
@@ -351,8 +372,8 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
351
372
  // move
352
373
  //
353
374
  test('move: move the 1st page (index:0) of 5p.pdf to the 3rd position (index:2)', async () => {
354
- const moved = await (0, index_1.move)(fiveP, { from: 0, to: 2 });
355
- const images = await (0, utils_1.pdfToImages)(moved);
375
+ const moved = await (0, index_js_1.move)(fiveP, { from: 0, to: 2 });
376
+ const images = await pdfToImages(moved);
356
377
  for (let i = 0; i < images.length; i++) {
357
378
  expect(images[i]).toMatchImageSnapshot({
358
379
  customSnapshotIdentifier: `move-5p-page0-to-2-result-page${i + 1}`,
@@ -363,8 +384,8 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
363
384
  // organize (single operation)
364
385
  //
365
386
  test('organize: single remove (remove the 2nd page)', async () => {
366
- const result = await (0, index_1.organize)(fiveP, [{ type: 'remove', data: { position: 1 } }]);
367
- const images = await (0, utils_1.pdfToImages)(result);
387
+ const result = await (0, index_js_1.organize)(fiveP, [{ type: 'remove', data: { position: 1 } }]);
388
+ const images = await pdfToImages(result);
368
389
  for (let i = 0; i < images.length; i++) {
369
390
  expect(images[i]).toMatchImageSnapshot({
370
391
  customSnapshotIdentifier: `organize-remove-only-result-page${i + 1}`,
@@ -372,8 +393,8 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
372
393
  }
373
394
  });
374
395
  test('organize: single insert (insert a.pdf at page 1)', async () => {
375
- const result = await (0, index_1.organize)(fiveP, [{ type: 'insert', data: { pdf: aPdf, position: 0 } }]);
376
- const images = await (0, utils_1.pdfToImages)(result);
396
+ const result = await (0, index_js_1.organize)(fiveP, [{ type: 'insert', data: { pdf: aPdf, position: 0 } }]);
397
+ const images = await pdfToImages(result);
377
398
  for (let i = 0; i < images.length; i++) {
378
399
  expect(images[i]).toMatchImageSnapshot({
379
400
  customSnapshotIdentifier: `organize-insert-only-result-page${i + 1}`,
@@ -381,8 +402,8 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
381
402
  }
382
403
  });
383
404
  test('organize: single replace (replace 2nd page with a.pdf)', async () => {
384
- const result = await (0, index_1.organize)(fiveP, [{ type: 'replace', data: { pdf: aPdf, position: 1 } }]);
385
- const images = await (0, utils_1.pdfToImages)(result);
405
+ const result = await (0, index_js_1.organize)(fiveP, [{ type: 'replace', data: { pdf: aPdf, position: 1 } }]);
406
+ const images = await pdfToImages(result);
386
407
  for (let i = 0; i < images.length; i++) {
387
408
  expect(images[i]).toMatchImageSnapshot({
388
409
  customSnapshotIdentifier: `organize-replace-only-result-page${i + 1}`,
@@ -390,11 +411,11 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
390
411
  }
391
412
  });
392
413
  test('organize: single rotate (rotate pages 1 and 3 by 90 degrees)', async () => {
393
- const result = await (0, index_1.organize)(fiveP, [
414
+ const result = await (0, index_js_1.organize)(fiveP, [
394
415
  { type: 'rotate', data: { position: 0, degrees: 90 } },
395
416
  { type: 'rotate', data: { position: 2, degrees: 90 } },
396
417
  ]);
397
- const images = await (0, utils_1.pdfToImages)(result);
418
+ const images = await pdfToImages(result);
398
419
  for (let i = 0; i < images.length; i++) {
399
420
  expect(images[i]).toMatchImageSnapshot({
400
421
  customSnapshotIdentifier: `organize-rotate-only-result-page${i + 1}`,
@@ -404,15 +425,15 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
404
425
  test('organize: multiple operations (remove -> remove -> insert -> replace -> rotate -> rotate)', async () => {
405
426
  const insertPdf = aPdf;
406
427
  const replacePdf = bPdf;
407
- const result = await (0, index_1.organize)(fiveP, [
428
+ const result = await (0, index_js_1.organize)(fiveP, [
408
429
  { type: 'remove', data: { position: 1 } },
409
- { type: 'remove', data: { position: 3 } },
410
- { type: 'insert', data: { pdf: insertPdf, position: 1 } },
411
- { type: 'replace', data: { position: 2, pdf: replacePdf } },
430
+ { type: 'remove', data: { position: 3 } }, // 5 -> 3 pages
431
+ { type: 'insert', data: { pdf: insertPdf, position: 1 } }, // 3 -> 4 pages
432
+ { type: 'replace', data: { position: 2, pdf: replacePdf } }, // still 4 pages
412
433
  { type: 'rotate', data: { position: 0, degrees: 90 } },
413
434
  { type: 'rotate', data: { position: 3, degrees: 90 } },
414
435
  ]);
415
- const images = await (0, utils_1.pdfToImages)(result);
436
+ const images = await pdfToImages(result);
416
437
  for (let i = 0; i < images.length; i++) {
417
438
  expect(images[i]).toMatchImageSnapshot({
418
439
  customSnapshotIdentifier: `organize-multiple-ops-result-page${i + 1}`,
@@ -426,12 +447,12 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
426
447
  // Remove the 2nd page (index:1) => 4 pages
427
448
  // Insert a.pdf at the 2nd page (index:1) => 5 pages
428
449
  // Move the newly inserted page (index:1) to the 1st page (index:0) => 5 pages
429
- const result = await (0, index_1.organize)(fiveP, [
450
+ const result = await (0, index_js_1.organize)(fiveP, [
430
451
  { type: 'remove', data: { position: 1 } },
431
452
  { type: 'insert', data: { pdf: aPdf, position: 1 } },
432
453
  { type: 'move', data: { from: 1, to: 0 } },
433
454
  ]);
434
- const images = await (0, utils_1.pdfToImages)(result);
455
+ const images = await pdfToImages(result);
435
456
  for (let i = 0; i < images.length; i++) {
436
457
  expect(images[i]).toMatchImageSnapshot({
437
458
  customSnapshotIdentifier: `organize-composite-1-result-page${i + 1}`,
@@ -442,12 +463,12 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
442
463
  // Replace the 3rd page with a.pdf => 5 pages
443
464
  // Rotate the 3rd page by 180 => 5 pages
444
465
  // Remove the 1st page => 4 pages
445
- const result = await (0, index_1.organize)(fiveP, [
466
+ const result = await (0, index_js_1.organize)(fiveP, [
446
467
  { type: 'replace', data: { pdf: aPdf, position: 2 } },
447
468
  { type: 'rotate', data: { position: 2, degrees: 180 } },
448
469
  { type: 'remove', data: { position: 0 } },
449
470
  ]);
450
- const images = await (0, utils_1.pdfToImages)(result);
471
+ const images = await pdfToImages(result);
451
472
  for (let i = 0; i < images.length; i++) {
452
473
  expect(images[i]).toMatchImageSnapshot({
453
474
  customSnapshotIdentifier: `organize-composite-2-result-page${i + 1}`,
@@ -459,13 +480,13 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
459
480
  // Insert b.pdf at the start (index:0) => 7 pages
460
481
  // Move the 3rd page (index:2) to the 6th page (index:5) => 7 pages
461
482
  // Move the 4th page (index:3) to the 2nd page (index:1) => 7 pages
462
- const result = await (0, index_1.organize)(fiveP, [
483
+ const result = await (0, index_js_1.organize)(fiveP, [
463
484
  { type: 'insert', data: { pdf: aPdf, position: 5 } },
464
485
  { type: 'insert', data: { pdf: bPdf, position: 0 } },
465
486
  { type: 'move', data: { from: 2, to: 5 } },
466
487
  { type: 'move', data: { from: 3, to: 1 } },
467
488
  ]);
468
- const images = await (0, utils_1.pdfToImages)(result);
489
+ const images = await pdfToImages(result);
469
490
  for (let i = 0; i < images.length; i++) {
470
491
  expect(images[i]).toMatchImageSnapshot({
471
492
  customSnapshotIdentifier: `organize-composite-3-result-page${i + 1}`,
@@ -476,13 +497,13 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
476
497
  // Rotate the 2nd and 4th pages by 90 => 5 pages
477
498
  // Rotate the 3rd page by 270 => 5 pages
478
499
  // Remove the 1st page => 4 pages
479
- const result = await (0, index_1.organize)(fiveP, [
500
+ const result = await (0, index_js_1.organize)(fiveP, [
480
501
  { type: 'rotate', data: { position: 1, degrees: 90 } },
481
502
  { type: 'rotate', data: { position: 3, degrees: 90 } },
482
503
  { type: 'rotate', data: { position: 2, degrees: 270 } },
483
504
  { type: 'remove', data: { position: 0 } },
484
505
  ]);
485
- const images = await (0, utils_1.pdfToImages)(result);
506
+ const images = await pdfToImages(result);
486
507
  for (let i = 0; i < images.length; i++) {
487
508
  expect(images[i]).toMatchImageSnapshot({
488
509
  customSnapshotIdentifier: `organize-composite-4-result-page${i + 1}`,
@@ -494,13 +515,13 @@ describe('PDF manipulator E2E Tests with real PDF files', () => {
494
515
  // Insert a.pdf at the 2nd page (index:1) => 5 pages
495
516
  // Remove the 1st page (index:0) => 4 pages
496
517
  // Insert b.pdf at the end (index:4) => 5 pages
497
- const result = await (0, index_1.organize)(fiveP, [
518
+ const result = await (0, index_js_1.organize)(fiveP, [
498
519
  { type: 'remove', data: { position: 4 } },
499
520
  { type: 'insert', data: { pdf: aPdf, position: 1 } },
500
521
  { type: 'remove', data: { position: 0 } },
501
522
  { type: 'insert', data: { pdf: bPdf, position: 4 } },
502
523
  ]);
503
- const images = await (0, utils_1.pdfToImages)(result);
524
+ const images = await pdfToImages(result);
504
525
  for (let i = 0; i < images.length; i++) {
505
526
  expect(images[i]).toMatchImageSnapshot({
506
527
  customSnapshotIdentifier: `organize-composite-5-result-page${i + 1}`,