From e348ec20e8e302e6a4c84681dbdd6e1c70c25125 Mon Sep 17 00:00:00 2001 From: howardbaek Date: Fri, 2 Jun 2023 14:58:14 -0700 Subject: [PATCH 1/6] Moved `pptx_notes()` to ari --- R/pptx_notes.R | 189 ------------------------------------------------- 1 file changed, 189 deletions(-) delete mode 100644 R/pptx_notes.R diff --git a/R/pptx_notes.R b/R/pptx_notes.R deleted file mode 100644 index daf2ec5..0000000 --- a/R/pptx_notes.R +++ /dev/null @@ -1,189 +0,0 @@ -#' Get Notes from XML -#' -#' @param file XML file from a PPTX -#' @param collapse_text should text be collapsed by spaces? -#' @param xpath \code{xpath} to pass to [xml2::xml_find_all()] -#' -#' @return A character vector -#' @export -#' -#' @importFrom xml2 read_xml xml_text xml_find_all -xml_notes = function(file, collapse_text = TRUE, xpath = "//a:r//a:t") { - xdoc = xml2::read_xml(file) - # probably need to a:p//a:t and collapse all text within a a:p - txt = xml2::xml_find_all(x = xdoc, xpath = xpath) - txt = xml2::xml_text(txt) - if (collapse_text) { - txt = paste(txt, collapse = " ") - } - return(txt) -} - - - -#' Get Notes from a PowerPoint (usually from Google Slides) -#' -#' @param file Character. Path for `PPTX` file -#' @param ... additional arguments to pass to \code{\link{xml_notes}}, -#' particularly \code{xpath} -#' -#' @return Either a character vector or `NULL` -#' @export -#' -#' @importFrom utils unzip -#' @examples -#' ex_file = system.file("extdata", "example.pptx", -#' package = "ariExtra") -#' pptx_notes(ex_file) -#' pptx_slide_note_df(ex_file) -#' pptx_slide_text_df(ex_file) -pptx_notes = function(file, ...) { - - df = pptx_slide_note_df(file, ...) - if (is.null(df)) { - return(NULL) - } - # need factor because they can be dumb with characters - # and numerics and the file naming of PPTX files - fac = basename(df$file) - fac = factor(fac, levels = unique(fac)) - ss = split(df, fac) - res = sapply(ss, function(x) { - paste(x$text, collapse = " ") - }) - if (any(trimws(res) %in% "")) { - warning("Slides with no notes exists") - } - res[ res == ""] = ";" - return(res) -} - -#' @export -#' @rdname pptx_notes -pptx_slide_text_df = function(file, ...) { - - L = unzip_pptx(file) - slides = L$slides - - if (length(slides) > 0) { - # in case empty notes - res = lapply(slides, function(x) { - xx = xml_notes(x, collapse_text = FALSE, ...) - if (length(xx) == 0) { - return(NULL) - } - snum = sub("[.]xml", "", sub("slide", "", basename(x))) - snum = as.numeric(snum) - data.frame( - file = x, - slide = snum, - text = xx, - index = 1:length(xx), - stringsAsFactors = FALSE) - }) - res = do.call(rbind, res) - return(res) - } else { - return(NULL) - } -} - -#' @export -#' @rdname pptx_notes -pptx_slide_note_df = function(file, ...) { - - L = unzip_pptx(file) - notes = L$notes - slides = L$slides - note_dir = L$note_dir - - if (length(notes) > 0) { - # in case empty notes - assoc_notes = sub("slide", "", basename(slides)) - assoc_notes = paste0("notesSlide", assoc_notes) - assoc_notes = file.path(note_dir, assoc_notes) - no_fe = !file.exists(assoc_notes) - if (any(no_fe)) { - file.create(assoc_notes[no_fe]) - notes = assoc_notes - } - res = lapply(notes, function(x) { - if (file.size(x) == 0) { - xx = "" - } else { - xx = xml_notes(x, collapse_text = FALSE, ...) - } - if (length(xx) == 0) { - xx = "" - } - snum = sub("[.]xml", "", sub("notesSlide", "", basename(x))) - snum = as.numeric(snum) - data.frame( - file = x, - slide = snum, - text = xx, - index = 1:length(xx), - stringsAsFactors = FALSE) - }) - res = do.call(rbind, res) - return(res) - } else { - return(NULL) - } -} - - -pptx_reorder_xml = function(files) { - if (length(files) == 0) { - return(files) - } - nums = basename(files) - # nums = gsub(pattern = paste0(pattern, "(\\d*)[.]xml"), - # replacement = "\\1", nums) - nums = sub("[[:alpha:]]*(\\d.*)[.].*", "\\1", nums) - nums = as.numeric(nums) - if (any(is.na(nums))) { - warning(paste0("Trying to parse set of files (example: ", files[1], - ") from PPTX, failed")) - return(files) - } - files = files[order(nums)] -} - -#' @export -#' @rdname pptx_notes -unzip_pptx = function(file) { - tdir = tempfile() - dir.create(tdir) - res = unzip(file, exdir = tdir) - rm(res) - slide_dir = file.path(tdir, "ppt", "slides") - slides = list.files(path = slide_dir, pattern = "[.]xml$", - full.names = TRUE) - slides = pptx_reorder_xml(slides) - - note_dir = file.path(tdir, "ppt", "notesSlides") - notes = list.files(path = note_dir, pattern = "[.]xml$", - full.names = TRUE) - notes = pptx_reorder_xml(notes) - - tdir = normalizePath(tdir) - props_dir = file.path(tdir, "docProps") - props_file = file.path(props_dir, "core.xml") - ari_core_file = system.file("extdata", "docProps", - "core.xml", package = "ariExtra") - if (!dir.exists(props_file)) { - dir.create(props_dir, recursive = TRUE) - file.copy(ari_core_file, props_file, - overwrite = TRUE) - } - - L = list(slides = slides, - notes = notes, - slide_dir = slide_dir, - note_dir = note_dir, - props_dir = props_dir, - props_file = props_file, - root_dir = tdir) - return(L) -} From 6282c4031710600e8638ba35b0a8f6132ec8f64f Mon Sep 17 00:00:00 2001 From: howardbaek Date: Fri, 2 Jun 2023 14:58:42 -0700 Subject: [PATCH 2/6] Moved `download_gs_file()` and its accompanying functions to ari --- R/gs_ari.R | 59 ++++++------------------------------------------------ 1 file changed, 6 insertions(+), 53 deletions(-) diff --git a/R/gs_ari.R b/R/gs_ari.R index f0f63a0..4311c89 100644 --- a/R/gs_ari.R +++ b/R/gs_ari.R @@ -5,55 +5,6 @@ quick_arg_check = function(args) { } } -#' Download Google Slides File -#' -#' @param id Identifier of Google slides presentation, passed to -#' \code{\link{get_slide_id}} -#' @param out_type output type of file to download. Usually -#' `pdf` or `pptx` -#' -#' @note This downloads presentations if they are public and also try to make -#' sure it does not fail on large files -#' @return Downloaded file (in temporary directory) -#' @export -download_gs_file = function(id, out_type = "pptx") { - id = as.character(id) - id = get_slide_id(id) - url = type_url(id = id, page_id = NULL, type = out_type) - tfile = tempfile(fileext = paste0(".", out_type)) - - result = httr::GET(url, httr::write_disk(tfile)) - warn_them = FALSE - fr_header = result$headers$`x-frame-options` - if (!is.null(fr_header)) { - if (all(fr_header == "DENY")) { - warn_them = TRUE - } - } - if (httr::status_code(result) >= 300) { - warn_them = TRUE - } - # Don't write something if not really a pptx - ctype = result$headers$`content-type` - if (httr::status_code(result) >= 400 && - !is.null(ctype) && grepl("html", ctype)) { - file.remove(tfile) - } - if (grepl("ServiceLogin", result$url)) { - warn_them = TRUE - } - # if (result$times["redirect"] > 0) { - # warn_them = TRUE - # } - if (warn_them) { - warning( - paste0( - "This presentation may not be available, ", - "did you turn link sharing on?") - ) - } - tfile -} # Extract Script from PPTX and write to a text file get_pptx_script = function(path, @@ -64,7 +15,7 @@ get_pptx_script = function(path, if (verbose) { message("Getting Notes from PPTX") } - res = pptx_notes(path, ...) + res = ari::pptx_notes(path, ...) script = tempfile(fileext = ".txt") if (verbose > 1) { message(paste0("script is at: ", script)) @@ -82,6 +33,7 @@ get_pptx_script = function(path, #' #' @return The output from [make_ari_document] #' @importFrom httr GET write_disk +#' @importFrom ari download_gs_file #' @export #' @examples #' \donttest{ @@ -105,7 +57,7 @@ gs_to_ari = function (path, if (verbose) { message("Downloading PPTX") } - pptx_file = download_gs_file(id = path, out_type = "pptx") + pptx_file = ari::download_gs_file(id = path, out_type = "pptx") if (verbose > 1) { message(paste0("pptx is at: ", pptx_file)) } @@ -117,7 +69,7 @@ gs_to_ari = function (path, if (verbose) { message("Downloading PDF") } - pdf_file = download_gs_file(id = path, out_type = "pdf") + pdf_file = ari::download_gs_file(id = path, out_type = "pdf") if (verbose > 1) { message(paste0("PDF is at: ", pdf_file)) } @@ -129,6 +81,7 @@ gs_to_ari = function (path, #' @export #' @param ... additional arguments to \code{\link{pptx_notes}} +#' @importFrom ari download_gs_file #' @rdname gs_to_ari gs_pptx_notes = function( path, @@ -138,7 +91,7 @@ gs_pptx_notes = function( if (verbose) { message("Downloading PPTX") } - pptx_file = download_gs_file(id = path, out_type = "pptx") + pptx_file = ari::download_gs_file(id = path, out_type = "pptx") if (verbose > 1) { message(paste0("pptx is at: ", pptx_file)) } From 9793f59649a7520edd0f21e3e634c214e7d9a775 Mon Sep 17 00:00:00 2001 From: howardbaek Date: Fri, 2 Jun 2023 15:00:03 -0700 Subject: [PATCH 3/6] Use the `package::function()` syntax for functions that are moved to ari --- R/rewrite_slides.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/rewrite_slides.R b/R/rewrite_slides.R index 01e126a..5991d87 100644 --- a/R/rewrite_slides.R +++ b/R/rewrite_slides.R @@ -5,12 +5,12 @@ pptx_rewriter = function( replace_df, type = c("slides", "notes") ) { - L = unzip_pptx(file) + L = ari::unzip_pptx(file) root_dir = L$root_dir runners = L[[type]] type = match.arg(type) - func = switch(slides = pptx_slide_text_df, - notes = pptx_slide_note_df) + func = switch(slides = ari::pptx_slide_text_df, + notes = ari::pptx_slide_note_df) df = func(file) stopifnot(nrow(df) == nrow(replace_df)) From aedbd92b5f608917d3a2b27323c3232fc892cb9b Mon Sep 17 00:00:00 2001 From: howardbaek Date: Fri, 2 Jun 2023 15:00:21 -0700 Subject: [PATCH 4/6] Moved functions to ari --- DESCRIPTION | 2 +- NAMESPACE | 15 +----- R/aaa_utils.R | 140 -------------------------------------------------- 3 files changed, 2 insertions(+), 155 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 147a4f1..5063408 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -42,5 +42,5 @@ Type: Package VignetteBuilder: knitr URL: https://github.com/jhudsl/ariExtra BugReports: https://github.com/jhudsl/ariExtra/issues -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.3 Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 43c0b62..56f568d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,33 +2,24 @@ export("%>%") export(ari_document) -export(download_gs_file) -export(get_folder_id) -export(get_slide_id) export(gs_pptx_notes) export(gs_to_ari) export(html_to_ari) export(images_to_ari) export(make_ari_document) -export(make_slide_url) export(pdf_to_ari) export(pdf_to_pngs) export(pngs_to_ari) -export(pptx_notes) -export(pptx_slide_note_df) -export(pptx_slide_text_df) export(pptx_to_ari) export(pptx_to_pdf) export(pptx_to_pngs) export(rmd_to_ari) export(to_ari) -export(unzip_pptx) -export(xml_notes) importFrom(ari,ari_spin) +importFrom(ari,download_gs_file) importFrom(docxtractr,convert_to_pdf) importFrom(httr,GET) importFrom(httr,write_disk) -importFrom(jsonlite,fromJSON) importFrom(magrittr,"%>%") importFrom(pdftools,pdf_convert) importFrom(pdftools,pdf_info) @@ -41,9 +32,5 @@ importFrom(stats,na.omit) importFrom(tools,file_ext) importFrom(tools,file_path_sans_ext) importFrom(utils,file.edit) -importFrom(utils,unzip) importFrom(xml2,read_html) -importFrom(xml2,read_xml) -importFrom(xml2,xml_find_all) -importFrom(xml2,xml_text) importFrom(yaml,as.yaml) diff --git a/R/aaa_utils.R b/R/aaa_utils.R index c324fcc..10e3cd2 100644 --- a/R/aaa_utils.R +++ b/R/aaa_utils.R @@ -218,101 +218,6 @@ sys_type <- function() { } } -# Constructs an URL to export an image file from a Google Slides -type_url <- function(id, page_id = NULL, type = "png") { - url <- paste0("https://docs.google.com/presentation/d/", - id, "/export/", type, "?id=", id) - if (!is.null(page_id)) { - url = paste0(url, "&pageid=", page_id) - } - url -} - -png_url = type_url - -# Constructs an URL to export to pptx -pptx_url = function(id) { - type_url(id, page_id = NULL, type = "pptx") -} - -# Constructs an URL to export to pdf -pdf_url = function(id) { - type_url(id, page_id = NULL, type = "pdf") -} - -# Extract page IDs of slides in a Google Slides presentation -#' @importFrom jsonlite fromJSON -get_page_ids = function(id) { - id = get_slide_id(id) - url = paste0("https://docs.google.com/presentation/d/", id) - tfile = tempfile(fileext = ".html") - res = httr::GET(url, httr::write_disk(tfile)) - httr::stop_for_status(res) - cr = httr::content(res) - script = rvest::html_nodes(cr, xpath ="//script") - script = rvest::html_text(script) - script = unique(script) - script = gsub("DOCS_modelChunk = undefined;", "", script) - script = script[ grepl("DOCS_modelChunk\\s=\\s\\[", x = script)] - - all_types = c("PREDEFINED_LAYOUT_UNSPECIFIED", - "BLANK", - "CAPTION_ONLY", - "TITLE", - "TITLE_AND_BODY", - "TITLE_AND_TWO_COLUMNS", - "TITLE_ONLY", - "SECTION_HEADER", - "SECTION_TITLE_AND_DESCRIPTION", - "ONE_COLUMN_TEXT", - "MAIN_POINT", - "BIG_NUMBER", - paste0("CUSTOM_", 1:100)) - types = paste0(all_types, collapse = "|") - # script = script[grepl(types, script)] - ss = strsplit(script, "; DOC") - ss = lapply(ss, trimws) - ss = lapply(ss, function(x) { - x[!grepl("^DOC", x)] = paste0(" DOC", x[!grepl("^DOC", x)]) - x - }) - ss = lapply(ss, function(x) { - x = x[grepl("^DOCS_modelChunk\\s=\\s\\[", x)] - x = x[ !x %in% "DOCS_modelChunk = undefined"] - x = sub("^DOCS_modelChunk\\s=\\s\\[", "[", x) - x - }) - ss = unlist(ss) - pages = lapply(ss, jsonlite::fromJSON) - pages = sapply(pages, function(x) { - x = x[sapply(x, function(r) any(unlist(r) %in% all_types))] - x = x[length(x)] - x - }) - pages = sapply(pages, function(x) { - if (length(x) < 2) { - if (length(x) == 0) { - return(NA) - } - x = x[[1]] - if (length(x) < 2) { - return(NA) - } - } - x[[2]] - }) - pages = pages[ !is.na(pages) ] - if (length(pages) >= 2) { - pages = c(pages[1], grep("^g", pages[2:length(pages)], value = TRUE)) - } - if (pages[1] != "p") { - pages = unique(c("p", pages)) - } - urls = type_url(id = id, page_id = pages) - pages = pages[check_png_urls(urls)] - pages -} - # Check if vector of URLs is valid (Status Code = 200) check_png_urls <- function(urls) { res = vapply(urls, function(url) { @@ -335,49 +240,4 @@ download_png_urls = function(urls) { -#' Get Slide ID from URL -#' -#' @param x URL of slide -#' -#' @return A character vector -#' @export -#' -#' @examples -#' x = paste0("https://docs.google.com/presentation/d/", -#' "1Tg-GTGnUPduOtZKYuMoelqUNZnUp3vvg_7TtpUPL7e8", -#' "/edit#slide=id.g154aa4fae2_0_58") -#' get_slide_id(x) -get_slide_id <- function(x) { - x = sub(".*presentation/", "", x) - x = sub("/d/e", "/d", x) # if you publish by accident - x = sub("^(d|e)/", "", x) - x = strsplit(x, "/")[[1]] - x = x[ !grepl("^(edit|pub|export|png)", x)] - x = x[ nchar(x) > 5] - x -} -#' @export -#' @rdname get_slide_id -make_slide_url <- function(x) { - x = get_slide_id(x) - x = paste0("https://docs.google.com/presentation/d/",x) - x -} - -#' @rdname get_slide_id -#' @export -#' @examples -#' x = "https://drive.google.com/drive/folders/1pXBQQdd1peI56GtQT-jEZ59xSmhqQlFC?usp=sharing" -#' get_folder_id(x) -#' x = "1pXBQQdd1peI56GtQT-jEZ59xSmhqQlFC" -#' get_folder_id(x) -get_folder_id = function(x) { - res = httr::parse_url(x) - x = res$path - x = sub(".*folders/", "", x) - x = sub("[?].*", "", x) - x = x[ nchar(x) > 5] - x = trimws(x) - x -} From 0741c5cf2eb450389c7f4dfa57d7a534b46263a9 Mon Sep 17 00:00:00 2001 From: howardbaek Date: Fri, 2 Jun 2023 15:00:29 -0700 Subject: [PATCH 5/6] Update documentation --- man/download_gs_file.Rd | 25 ------------------------- man/get_slide_id.Rd | 33 --------------------------------- man/pptx_notes.Rd | 36 ------------------------------------ man/xml_notes.Rd | 21 --------------------- 4 files changed, 115 deletions(-) delete mode 100644 man/download_gs_file.Rd delete mode 100644 man/get_slide_id.Rd delete mode 100644 man/pptx_notes.Rd delete mode 100644 man/xml_notes.Rd diff --git a/man/download_gs_file.Rd b/man/download_gs_file.Rd deleted file mode 100644 index 9b5ce26..0000000 --- a/man/download_gs_file.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/gs_ari.R -\name{download_gs_file} -\alias{download_gs_file} -\title{Download Google Slides File} -\usage{ -download_gs_file(id, out_type = "pptx") -} -\arguments{ -\item{id}{Identifier of Google slides presentation, passed to -\code{\link{get_slide_id}}} - -\item{out_type}{output type of file to download. Usually -\code{pdf} or \code{pptx}} -} -\value{ -Downloaded file (in temporary directory) -} -\description{ -Download Google Slides File -} -\note{ -This downloads presentations if they are public and also try to make -sure it does not fail on large files -} diff --git a/man/get_slide_id.Rd b/man/get_slide_id.Rd deleted file mode 100644 index 7fe4654..0000000 --- a/man/get_slide_id.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/aaa_utils.R -\name{get_slide_id} -\alias{get_slide_id} -\alias{make_slide_url} -\alias{get_folder_id} -\title{Get Slide ID from URL} -\usage{ -get_slide_id(x) - -make_slide_url(x) - -get_folder_id(x) -} -\arguments{ -\item{x}{URL of slide} -} -\value{ -A character vector -} -\description{ -Get Slide ID from URL -} -\examples{ -x = paste0("https://docs.google.com/presentation/d/", -"1Tg-GTGnUPduOtZKYuMoelqUNZnUp3vvg_7TtpUPL7e8", -"/edit#slide=id.g154aa4fae2_0_58") -get_slide_id(x) -x = "https://drive.google.com/drive/folders/1pXBQQdd1peI56GtQT-jEZ59xSmhqQlFC?usp=sharing" -get_folder_id(x) -x = "1pXBQQdd1peI56GtQT-jEZ59xSmhqQlFC" -get_folder_id(x) -} diff --git a/man/pptx_notes.Rd b/man/pptx_notes.Rd deleted file mode 100644 index fffd986..0000000 --- a/man/pptx_notes.Rd +++ /dev/null @@ -1,36 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/pptx_notes.R -\name{pptx_notes} -\alias{pptx_notes} -\alias{pptx_slide_text_df} -\alias{pptx_slide_note_df} -\alias{unzip_pptx} -\title{Get Notes from a PowerPoint (usually from Google Slides)} -\usage{ -pptx_notes(file, ...) - -pptx_slide_text_df(file, ...) - -pptx_slide_note_df(file, ...) - -unzip_pptx(file) -} -\arguments{ -\item{file}{Character. Path for \code{PPTX} file} - -\item{...}{additional arguments to pass to \code{\link{xml_notes}}, -particularly \code{xpath}} -} -\value{ -Either a character vector or \code{NULL} -} -\description{ -Get Notes from a PowerPoint (usually from Google Slides) -} -\examples{ -ex_file = system.file("extdata", "example.pptx", -package = "ariExtra") -pptx_notes(ex_file) -pptx_slide_note_df(ex_file) -pptx_slide_text_df(ex_file) -} diff --git a/man/xml_notes.Rd b/man/xml_notes.Rd deleted file mode 100644 index 4efae39..0000000 --- a/man/xml_notes.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/pptx_notes.R -\name{xml_notes} -\alias{xml_notes} -\title{Get Notes from XML} -\usage{ -xml_notes(file, collapse_text = TRUE, xpath = "//a:r//a:t") -} -\arguments{ -\item{file}{XML file from a PPTX} - -\item{collapse_text}{should text be collapsed by spaces?} - -\item{xpath}{\code{xpath} to pass to \code{\link[xml2:xml_find_all]{xml2::xml_find_all()}}} -} -\value{ -A character vector -} -\description{ -Get Notes from XML -} From 8ddbeafa3174df8ec9ff6ecdacf303d443baf32d Mon Sep 17 00:00:00 2001 From: howardbaek Date: Fri, 2 Jun 2023 15:11:03 -0700 Subject: [PATCH 6/6] Move `pdf_to_pngs()` to ari --- NAMESPACE | 1 - R/gs_ari.R | 30 ++---------------------------- man/gs_to_ari.Rd | 3 --- 3 files changed, 2 insertions(+), 32 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 56f568d..880eed8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,7 +8,6 @@ export(html_to_ari) export(images_to_ari) export(make_ari_document) export(pdf_to_ari) -export(pdf_to_pngs) export(pngs_to_ari) export(pptx_to_ari) export(pptx_to_pdf) diff --git a/R/gs_ari.R b/R/gs_ari.R index 4311c89..8eafdea 100644 --- a/R/gs_ari.R +++ b/R/gs_ari.R @@ -136,7 +136,7 @@ pptx_to_pngs = function(path, verbose = TRUE, dpi = 600) { ", see pdftools::pdf_convert for options") ) } - pdf_to_pngs( + ari::pdf_to_pngs( path = pdf_file, verbose = verbose, dpi = dpi) @@ -213,7 +213,7 @@ pdf_to_ari = function( stopifnot(!is.null(script)) args = list(...) quick_arg_check(args) - pngs = pdf_to_pngs(path = path, dpi = dpi, verbose = verbose) + pngs = ari::pdf_to_pngs(path = path, dpi = dpi, verbose = verbose) make_ari_document(pngs, script = script, ..., verbose = verbose) } @@ -246,32 +246,6 @@ html_to_ari = function( ..., verbose = verbose) } - -#' @rdname gs_to_ari -#' @export -pdf_to_pngs = function( - path, verbose = TRUE, - dpi = 600) { - fmts = pdftools::poppler_config()$supported_image_formats - if ("png" %in% fmts) { - format = "png" - } else { - format = fmts[1] - } - info = pdftools::pdf_info(pdf = path) - filenames = vapply(seq.int(info$pages), function(x) { - tempfile(fileext = paste0(".", format)) - }, FUN.VALUE = character(1)) - if (verbose) { - message("Converting PDF to PNGs") - } - pngs = pdftools::pdf_convert( - pdf = path, dpi = dpi, - format = format, filenames = filenames, - verbose = as.logical(verbose)) - pngs -} - #' @rdname gs_to_ari #' @export images_to_ari = function( diff --git a/man/gs_to_ari.Rd b/man/gs_to_ari.Rd index d8e8f26..8d81394 100644 --- a/man/gs_to_ari.Rd +++ b/man/gs_to_ari.Rd @@ -8,7 +8,6 @@ \alias{pptx_to_ari} \alias{pdf_to_ari} \alias{html_to_ari} -\alias{pdf_to_pngs} \alias{images_to_ari} \alias{to_ari} \title{Convert Google Slides and notes to video with ari} @@ -27,8 +26,6 @@ pdf_to_ari(path, script = NULL, dpi = 300, ..., verbose = TRUE) html_to_ari(path, script = NULL, ..., verbose = TRUE) -pdf_to_pngs(path, verbose = TRUE, dpi = 600) - images_to_ari(path, script = NULL, dpi = 300, ..., verbose = TRUE) to_ari(path, script = NULL, ..., verbose = TRUE)