diff --git a/public/testWorkflow.js b/public/exampleWorkflows.js similarity index 84% rename from public/testWorkflow.js rename to public/exampleWorkflows.js index 673dfbc3..61563483 100644 --- a/public/testWorkflow.js +++ b/public/exampleWorkflows.js @@ -1,8 +1,7 @@ // JSON Representation of this Node Tree: // https://discord.com/channels/1068636748814483718/1099390571493195898/1118192754103693483 // https://cdn.discordapp.com/attachments/1099390571493195898/1118192753759764520/image.png?ex=6537dba7&is=652566a7&hm=dc46820ef7c34bc37424794966c5f66f93ba0e15a740742c364d47d31ea119a9& - -export const testWorkflow = { +export const discordWorkflow = { outputOptions: { zip: false, awaitAllDone: true @@ -45,7 +44,7 @@ export const testWorkflow = { values: { "id": 1 }, operations: [ { - type: "merge", // This gets called when the other merge-ops with the same id finish. + type: "merge", values: {}, operations: [] } @@ -57,7 +56,7 @@ export const testWorkflow = { operations: [] }, { - type: "merge", // This gets called when the other merge-ops with the same id finish. + type: "merge", values: {}, operations: [ { @@ -68,4 +67,19 @@ export const testWorkflow = { ] } ] +} + +// This will merge all input files into one giant document +export const mergeOnly = { + outputOptions: { + zip: false, + awaitAllDone: true + }, + operations: [ + { + type: "merge", + values: {}, + operations: [] + } + ] } \ No newline at end of file diff --git a/public/functions/mergePDFs.js b/public/functions/mergePDFs.js new file mode 100644 index 00000000..f243451a --- /dev/null +++ b/public/functions/mergePDFs.js @@ -0,0 +1,15 @@ +const { PDFDocument, ParseSpeeds } = PDFLib; + +export const mergePDFs = async (snapshots) => { + + const mergedPdf = await PDFDocument.create(); + + for (let i = 0; i < snapshots.length; i++) { + const pdfToMerge = await PDFDocument.load(snapshots[i]); + + const copiedPages = await mergedPdf.copyPages(pdfToMerge, pdfToMerge.getPageIndices()); + copiedPages.forEach((page) => mergedPdf.addPage(page)); + } + + return mergedPdf.save(); +}; \ No newline at end of file diff --git a/public/index.html b/public/index.html index ac937236..821533bc 100644 --- a/public/index.html +++ b/public/index.html @@ -11,7 +11,7 @@ - +