Stirling-PDF/public/index.js

59 lines
2.3 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";
2023-10-17 01:31:00 +02:00
import { testWorkflow } from "./testWorkflow.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);
const pdfBuffers = await Promise.all(files.map(async file => {
return {
originalFileName: file.name.replace(/\.[^/.]+$/, ""),
fileName: file.name.replace(/\.[^/.]+$/, ""),
buffer: new Uint8Array(await file.arrayBuffer())
}
}));
console.log(pdfBuffers);
2023-10-17 01:38:51 +02:00
await traverseOperations(workflow.operations, pdfBuffers);
2023-10-17 01:31:00 +02:00
// if(selectedElementsList[0].textContent == "mergePDFs") {
// }
// // TODO: This can also be run serverside
// if(files.length > 1) {
// files.forEach(file => {
// });
// }
// else {
// const file = files[0];
// let pdfBuffer = new Uint8Array(await file.arrayBuffer());
// if (file) {
// for (let i = 0; i < selectedElementsList.length; i++) {
// const selectedOption = selectedElementsList[i];
// // Perform actions based on the selected option using the switch statement
// switch (selectedOption.textContent) {
// case "scaleContent":
// pdfBuffer = await scaleContent(pdfBuffer, 2);
// break;
// case "changePageSize":
// pdfBuffer = await scalePage(pdfBuffer, PageSize.letter);
// break;
// default:
// // Handle any other actions or errors here
// throw new Error(`This action ${selectedOption.value} has not been implemented.`);
// }
// }
// download(pdfBuffer, file.name.replace(/\.[^/.]+$/, "") + "_mod.pdf", "application/pdf");
// }
// }
2023-10-16 23:11:33 +02:00
});
2023-10-17 01:31:00 +02:00
})(testWorkflow);