muschellij2
5 years ago
5 changed files with 77 additions and 4 deletions
@ -0,0 +1,42 @@ |
|||
#' Convert a PowerPoint Document to a PDF |
|||
#' |
|||
#' @md |
|||
#' @param path path to the PowerPoint document |
|||
#' @param pdf_file output PDF file name. By default, creates . This functionality requires the use of |
|||
#' LibreOffice and the `soffice` binary it contains. See |
|||
#' [set_libreoffice_path] for more information. Note, |
|||
#' @export |
|||
#' @examples |
|||
#' \dontrun{ |
|||
#' path = system.file("examples/ex.pptx", package="docxtractr") |
|||
#' pdf <- convert_pptx_to_pdf(path, pdf_file = tempfile(fileext = ".pdf")) |
|||
#' } |
|||
convert_pptx_to_pdf <- function(path, pdf_file = sub("[.]pptx", ".pdf", path)) { |
|||
stopifnot(is_pptx(path)) |
|||
|
|||
lo_path <- getOption("path_to_libreoffice") |
|||
if (is.null(lo_path)) { |
|||
lo_path <- lo_find() |
|||
} |
|||
if (is.null(lo_path)) { |
|||
stop(lo_path_missing, call. = FALSE) |
|||
} |
|||
|
|||
# making temporary file because by default soffice |
|||
# will make sub("[.]pptx", ".pdf", path) output |
|||
# and don't want to do that in case pdf_file in other location |
|||
cp_path = tempfile(fileext = ".pptx") |
|||
cp_pdf = sub("[.]pptx", ".pdf", cp_path) |
|||
file.copy(path, cp_path) |
|||
|
|||
if (Sys.info()["sysname"] == "Windows") { |
|||
convert_win(lo_path, dirname(cp_path), cp_path, convert_to = "pdf") |
|||
} else { |
|||
convert_osx(lo_path, dirname(cp_path), cp_path, convert_to = "pdf") |
|||
} |
|||
if (!file.exists(cp_pdf)) { |
|||
stop("Conversion from PPTX to PDF did not succeed") |
|||
} |
|||
file.copy(cp_pdf, pdf_file) |
|||
return(pdf_file) |
|||
} |
Binary file not shown.
@ -0,0 +1,24 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/convert_pptx_to_pdf.R |
|||
\name{convert_pptx_to_pdf} |
|||
\alias{convert_pptx_to_pdf} |
|||
\title{Convert a PowerPoint Document to a PDF} |
|||
\usage{ |
|||
convert_pptx_to_pdf(path, pdf_file = sub("[.]pptx", ".pdf", path)) |
|||
} |
|||
\arguments{ |
|||
\item{path}{path to the PowerPoint document} |
|||
|
|||
\item{pdf_file}{output PDF file name. By default, creates . This functionality requires the use of |
|||
LibreOffice and the \code{soffice} binary it contains. See |
|||
\link{set_libreoffice_path} for more information. Note,} |
|||
} |
|||
\description{ |
|||
Convert a PowerPoint Document to a PDF |
|||
} |
|||
\examples{ |
|||
\dontrun{ |
|||
path = system.file("examples/ex.pptx", package="docxtractr") |
|||
pdf <- convert_pptx_to_pdf(path, pdf_file = tempfile(fileext = ".pdf")) |
|||
} |
|||
} |
Loading…
Reference in new issue