PDF Salad with repetition allowed

This commit is contained in:
2020-12-04 20:00:54 -07:00
parent e6869bbc8f
commit ccaf0f83a5
4 changed files with 28 additions and 5 deletions

View File

@@ -1,5 +1,21 @@
(defun main []
(let [bytesIn (Fs.readFileSync "example-input/antique-phone-shop.pdf")]
(.then (PDFDocument.load bytesIn) (lambda [pdfToModify]
(.then (pdfToModify.save) (lambda [bytesOut]
(Fs.writeFileSync "out.pdf" bytesOut)))))))
(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)))))))))))