Files
kiss-vscode/projects/pdf-salad/src/Main.kiss

21 lines
1.1 KiB
Plaintext

(defun main []
(let [[sourceDir numPages] (Sys.args)]
(.then
(Promise.all
(for file (Fs.readdirSync sourceDir)
(PDFDocument.load (Fs.readFileSync (+ sourceDir "/" file)))))
(lambda [inputPdfs]
// TODO make an awaitLet macro that .thens a promise or all() of promises into a binding
(.then (PDFDocument.create) (lambda [saladPdf]
(.then
(Promise.all
(for _ #|0... Std.parseInt(numPages)|#
(let [:PDFDocument pdf (nth inputPdfs (Std.random inputPdfs.length))
page (Std.random (pdf.getPageCount))]
(saladPdf.copyPages pdf [page]))))
(lambda [pages]
(doFor page pages (saladPdf.addPage (first page)))
(.then (saladPdf.save) (lambda [bytesOut]
(Fs.writeFileSync "out.pdf" bytesOut)))))))))))