2023-10-16 23:11:33 +02:00
|
|
|
import { scaleContent } from "./functions/scaleContent.js";
|
|
|
|
import { scalePage, PageSize } from "./functions/scalePage.js";
|
2023-10-17 02:14:06 +02:00
|
|
|
import * as exampleWorkflows from "./exampleWorkflows.js";
|
2023-10-17 01:38:51 +02:00
|
|
|
import { traverseOperations } from "./traverseOperations.js";
|
2023-10-16 23:11:33 +02:00
|
|
|
|
2023-10-17 01:31:00 +02:00
|
|
|
(async (workflow) => {
|
2023-10-16 23:11:33 +02:00
|
|
|
const pdfFileInput = document.getElementById('pdfFile');
|
2023-10-17 01:31:00 +02:00
|
|
|
const doneButton = document.getElementById("doneButton");
|
2023-10-16 23:11:33 +02:00
|
|
|
|
2023-10-17 01:31:00 +02:00
|
|
|
doneButton.addEventListener('click', async (e) => {
|
|
|
|
const files = Array.from(pdfFileInput.files);
|
|
|
|
console.log(files);
|
2023-10-17 02:14:06 +02:00
|
|
|
const inputs = await Promise.all(files.map(async file => {
|
2023-10-17 01:31:00 +02:00
|
|
|
return {
|
|
|
|
originalFileName: file.name.replace(/\.[^/.]+$/, ""),
|
|
|
|
fileName: file.name.replace(/\.[^/.]+$/, ""),
|
|
|
|
buffer: new Uint8Array(await file.arrayBuffer())
|
|
|
|
}
|
|
|
|
}));
|
2023-10-17 02:14:06 +02:00
|
|
|
console.log(inputs);
|
2023-10-17 01:31:00 +02:00
|
|
|
|
2023-10-17 02:14:06 +02:00
|
|
|
// TODO: This can also be run serverside
|
|
|
|
const results = await traverseOperations(workflow.operations, inputs);
|
|
|
|
|
|
|
|
results.forEach(result => {
|
|
|
|
download(result.buffer, result.fileName, "application/pdf");
|
|
|
|
});
|
2023-10-16 23:11:33 +02:00
|
|
|
});
|
2023-10-18 01:20:31 +02:00
|
|
|
})(exampleWorkflows.imposeOnly);
|