Stirling-PDF/public/index.js

43 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-10-16 23:11:33 +02:00
import { scaleContent } from "./functions/scaleContent.js";
import { scalePage, PageSize } from "./functions/scalePage.js";
import * as exampleWorkflows from "./exampleWorkflows.js";
2023-10-17 01:38:51 +02:00
import { traverseOperations } from "./traverseOperations.js";
import * as Functions from "./functions.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) => {
console.log("Starting...");
2023-10-17 01:31:00 +02:00
const files = Array.from(pdfFileInput.files);
console.log(files);
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())
}
}));
console.log(inputs);
2023-10-17 01:31:00 +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`);
}
pdfResults.forEach(result => {
download(result.buffer, result.fileName, "application/pdf");
});
2023-10-16 23:11:33 +02:00
});
2023-10-28 19:48:16 +02:00
})(exampleWorkflows.splitOnQR);