Browse Source

now named convert_to_pdf

pull/21/head
muschellij2 5 years ago
parent
commit
b1d7798926
  1. 2
      NAMESPACE
  2. 14
      R/convert_pptx_to_pdf.R
  3. 16
      man/convert_to_pdf.Rd
  4. 13
      tests/testthat/test-pptx-conversion.R

2
NAMESPACE

@ -3,7 +3,7 @@
S3method(print,docx)
export("%>%")
export(assign_colnames)
export(convert_pptx_to_pdf)
export(convert_to_pdf)
export(docx_cmnt_count)
export(docx_describe_cmnts)
export(docx_describe_tbls)

14
R/convert_pptx_to_pdf.R

@ -1,7 +1,7 @@
#' Convert a PowerPoint Document to a PDF
#' Convert a Document (usually PowerPoint) to a PDF
#'
#' @md
#' @param path path to the PowerPoint document
#' @param path path to the document, can be PowerPoint or DOCX
#' @param pdf_file output PDF file name. By default, creates a PDF in the
#' same directory as the `path` file.
#' This functionality requires the use of
@ -11,10 +11,12 @@
#' @examples
#' \dontrun{
#' path = system.file("examples/ex.pptx", package="docxtractr")
#' pdf <- convert_pptx_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
#' pdf <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
#' path = system.file("examples/data.docx", package="docxtractr")
#' pdf_doc <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
#' }
convert_pptx_to_pdf <- function(path, pdf_file = sub("[.]pptx", ".pdf", path)) {
stopifnot(is_pptx(path))
convert_to_pdf <- function(path, pdf_file = sub("[.]pptx", ".pdf", path)) {
stopifnot(is_pptx(path) | is_doc(path) | is_docx(path))
lo_assert()
lo_path <- getOption("path_to_libreoffice")
@ -23,7 +25,7 @@ convert_pptx_to_pdf <- function(path, pdf_file = sub("[.]pptx", ".pdf", path)) {
# 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)
cp_pdf = sub("[.](pptx|docx|doc)$", ".pdf", cp_path)
file.copy(path, cp_path)
if (Sys.info()["sysname"] == "Windows") {

16
man/convert_pptx_to_pdf.Rd → man/convert_to_pdf.Rd

@ -1,13 +1,13 @@
% 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}
\name{convert_to_pdf}
\alias{convert_to_pdf}
\title{Convert a Document (usually PowerPoint) to a PDF}
\usage{
convert_pptx_to_pdf(path, pdf_file = sub("[.]pptx", ".pdf", path))
convert_to_pdf(path, pdf_file = sub("[.]pptx", ".pdf", path))
}
\arguments{
\item{path}{path to the PowerPoint document}
\item{path}{path to the document, can be PowerPoint or DOCX}
\item{pdf_file}{output PDF file name. By default, creates a PDF in the
same directory as the \code{path} file.
@ -16,11 +16,13 @@ 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
Convert a Document (usually PowerPoint) to a PDF
}
\examples{
\dontrun{
path = system.file("examples/ex.pptx", package="docxtractr")
pdf <- convert_pptx_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
pdf <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
path = system.file("examples/data.docx", package="docxtractr")
pdf_doc <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
}
}

13
tests/testthat/test-pptx-conversion.R

@ -5,7 +5,18 @@ test_that("we can convert a PPTX if LibreOffice Installed", {
}, silent = TRUE)
if (!inherits(lp, "try-error")) {
path <- system.file("examples/ex.pptx", package = "docxtractr")
pdf <- convert_pptx_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
pdf <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
expect_true(file.size(pdf) > 0)
}
})
test_that("we can convert a DOCX to PDF if LibreOffice Installed", {
lp = try({
docxtractr:::lo_find()
}, silent = TRUE)
if (!inherits(lp, "try-error")) {
path <- system.file("examples/data.docx", package = "docxtractr")
pdf <- convert_to_pdf(path, pdf_file = tempfile(fileext = ".pdf"))
expect_true(file.size(pdf) > 0)
}
})

Loading…
Cancel
Save