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-17 01:31:00 +02:00
|
|
|
|
|
|
|
// 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 03:40:54 +02:00
|
|
|
})(exampleWorkflows.rotateOnly);
|