Created
April 9, 2020 07:17
-
-
Save mrdwab/bb31f413402d0997eb86e5abebfe4077 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/r | |
suppressMessages(library(docopt)) | |
suppressMessages(library(glue)) | |
doc <- "Usage: pdf2png.r [EXT] [-h] | |
-h --help show this help text" | |
opt <- docopt(doc) | |
files <- list.files(pattern = sprintf("%s", opt$EXT), include.dirs = FALSE) | |
for (i in seq_along(files)) { | |
cmd <- glue('pdftoppm "', files[i], '" "', gsub(".pdf", "", files[i]), '" -png') | |
print(cmd) | |
system(cmd) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/r | |
suppressMessages(library(docopt)) | |
suppressMessages(library(glue)) | |
options(useFancyQuotes = FALSE) | |
doc <- "Usage: scanfix.r [EXT] [-h] [--pgs PGS] | |
-p --pgs PGS pages per sheet in output [default: 1] | |
-h --help show this help text" | |
opt <- docopt(doc) | |
files <- list.files(pattern = sprintf("%s", opt$EXT), include.dirs = FALSE) | |
individual_files <- split(files, sub(glue("-[0-9]+.*\\.", opt$EXT, "$"), "", files)) | |
for (i in seq_along(individual_files)) { | |
NAM <- names(individual_files)[i] | |
cmd1 <- glue('tiffcp ', paste(sQuote(individual_files[[i]]), collapse = " "), ' ', sQuote(sprintf("%s_combined.tiff", NAM))) | |
print(cmd1) | |
system(cmd1) | |
cmd2 <- glue('tiff2pdf ', sQuote(sprintf("%s_combined.tiff", NAM)), ' > ', sQuote(sprintf("%s.pdf", NAM))) | |
print(cmd2) | |
system(cmd2) | |
if (opt$pgs > 1) { | |
cmd3 <- glue('pdfnup --nup ', opt$pgs, 'x1 --landscape --paper letter --frame false ', sQuote(sprintf("%s.pdf", NAM))) | |
print(cmd3) | |
system(cmd3) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment