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-26 14:42:18 +02:00
|
|
|
import * as Functions from "./pdf-operations.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) => {
|
2023-10-22 01:11:17 +02:00
|
|
|
console.log("Starting...");
|
|
|
|
|
2023-10-17 01:31:00 +02:00
|
|
|
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-22 01:11:17 +02:00
|
|
|
const traverse = traverseOperations(workflow.operations, inputs, Functions);
|
|
|
|
|
|
|
|
let pdfResults;
|
|
|
|
let iteration;
|
|
|
|
while (true) {
|
|
|
|
iteration = await traverse.next();
|
|
|
|
if (iteration.done) {
|
|
|
|
pdfResults = iteration.value;
|
|
|
|
console.log(`data: processing done\n\n`);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
console.log(`data: ${iteration.value}\n\n`);
|
|
|
|
}
|
2023-10-17 02:14:06 +02:00
|
|
|
|
2023-10-22 01:11:17 +02:00
|
|
|
pdfResults.forEach(result => {
|
2023-10-17 02:14:06 +02:00
|
|
|
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);
|