|
|
@ -54,6 +54,19 @@ chrome_dump_pdf <- function(url, path=NULL, overwrite=TRUE, prime=TRUE, |
|
|
|
fil_ext <- tools::file_ext(fil_nam) |
|
|
|
fil_pre <- tools::file_path_sans_ext(fil_nam) |
|
|
|
|
|
|
|
first_fil <- file.path(dir_nam, sprintf("%s.%s", fil_pre, fil_ext)) |
|
|
|
out_fil <- first_fil |
|
|
|
|
|
|
|
if (!overwrite) { |
|
|
|
|
|
|
|
moar_fils <- sprintf(file.path(dir_nam, sprintf("%s%%04d.%s", fil_pre, fil_ext)), 0:9999) |
|
|
|
fils <- c(first_fil, moar_fils) |
|
|
|
|
|
|
|
out_fil <- fils[which(!file.exists(fils))[1]] |
|
|
|
if (is.na(out_fil)) stop("Cannot create unique filename") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
td <- tempdir() |
|
|
|
|
|
|
|
setwd(td) |
|
|
@ -67,7 +80,7 @@ chrome_dump_pdf <- function(url, path=NULL, overwrite=TRUE, prime=TRUE, |
|
|
|
args <- c(args, sprintf("--user-data-dir=%s", work_dir)) |
|
|
|
args <- c(args, sprintf("--crash-dumps-dir=%s", work_dir)) |
|
|
|
args <- c(args, sprintf("--utility-allowed-dir=%s", work_dir)) |
|
|
|
args <- c(args, "--print-to-pdf", url) |
|
|
|
args <- c(args, sprintf("--print-to-pdf=%s", out_fil), url) |
|
|
|
|
|
|
|
vers <- chrome_version(quiet=TRUE) |
|
|
|
|
|
|
@ -81,21 +94,6 @@ chrome_dump_pdf <- function(url, path=NULL, overwrite=TRUE, prime=TRUE, |
|
|
|
echo = FALSE |
|
|
|
) -> res |
|
|
|
|
|
|
|
first_fil <- file.path(dir_nam, sprintf("%s.%s", fil_pre, fil_ext)) |
|
|
|
out_fil <- first_fil |
|
|
|
|
|
|
|
if (!overwrite) { |
|
|
|
|
|
|
|
moar_fils <- sprintf(file.path(dir_nam, sprintf("%s%%04d.%s", fil_pre, fil_ext)), 0:9999) |
|
|
|
fils <- c(first_fil, moar_fils) |
|
|
|
|
|
|
|
out_fil <- fils[which(!file.exists(fils))[1]] |
|
|
|
if (is.na(out_fil)) stop("Cannot create unique filename") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
file.copy(file.path(dirname(chrome_bin), "output.pdf"), out_fil, overwrite = overwrite) |
|
|
|
|
|
|
|
return(invisible(out_fil)) |
|
|
|
|
|
|
|
} |