-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_utils.ts
30 lines (28 loc) · 1.01 KB
/
test_utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { PDFDocument } from "pdf-lib";
import { ensureDirSync } from "@std/fs";
import { join } from "@std/path";
/**
* Creates one or multiple test PDFs with a specified number of pages.
*
* @param {string | string[]} filenames - A single filename or an array of filenames.
* @param {string} [directory] - Directory to save the PDFs. Defaults to the current directory.
* @param {number} [numPages] - Number of pages in each PDF. Defaults to 1.
*
* @returns {Promise<void>} - Resolves when all PDFs are created.
*/
export async function createTestPdf(
filenames: string | string[],
directory: string = Deno.cwd(),
numPages: number = 1,
): Promise<void> {
ensureDirSync(directory);
const files = Array.isArray(filenames) ? filenames : [filenames];
for (const filename of files) {
const pdfDoc = await PDFDocument.create();
for (let i = 0; i < numPages; i++) {
pdfDoc.addPage();
}
const pdfBytes = await pdfDoc.save();
await Deno.writeFile(join(directory, filename), pdfBytes);
}
}