Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

to_pdf

Convert documents to pdf


Description

Convert documents to pdf using Libre Office. It supports very well "Microsoft PowerPoint" to PDF. "Microsoft Word" can also be converted but some Word features are not supported such as sections.

Windows users must be warned the program is slow on your platform. Performances are not excellent but fast enough on other platform.

Usage

to_pdf(
  input,
  output = gsub("\\.[[:alnum:]]+$", ".pdf", input),
  use_docx2pdf = FALSE,
  UserInstallation = NULL
)

Arguments

input, output

file input and optional file output. If output file is not provided, the value will be the value of input file with extension "pdf".

use_docx2pdf

if TRUE (and if 'Microsoft Word' executable can be found as well as 'docx2pdf'), docx2pdf will be used to convert 'Word' documents to PDF. This makes it possible to have a PDF identical to the 'Word' display whereas with 'LibreOffice', this is not always the case.

UserInstallation

use this value to set a non-default user profile path for "LibreOffice". If not provided a temporary dir is created. It makes possibles to use more than a single session of "LibreOffice."

Value

the name of the produced pdf (the same value as output), invisibly.

Ubuntu platforms

On some Ubuntu platforms, 'LibreOffice' require to add in the environment variable LD_LIBRARY_PATH the following path: /usr/lib/libreoffice/program (you should see the message "libreglo.so cannot open shared object file" if it is the case). This can be done with R command Sys.setenv(LD_LIBRARY_PATH = "/usr/lib/libreoffice/program/")

Examples

library(locatexec)
if (exec_available("libreoffice") && check_libreoffice_export()) {

  out_pptx <- tempfile(fileext = ".pdf")
  file <- system.file(package = "doconv",
    "doc-examples/example.pptx")

  to_pdf(input = file, output = out_pptx)

  out_docx <- tempfile(fileext = ".pdf")
  file <- system.file(package = "doconv",
    "doc-examples/example.docx")

  to_pdf(input = file, output = out_docx)

}

doconv

Document Conversion to 'PDF' or 'PNG'

v0.1.2
MIT + file LICENSE
Authors
David Gohel [aut, cre], ArData [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.