| to_pdf | R Documentation |
Convert documents to pdf with a script using 'Office' or 'Libre Office'.
If 'Microsoft Word', 'Microsoft PowerPoint' and 'Microsoft Excel' are available, files 'docx', 'doc', 'rtf', 'pptx', 'ppt', 'xlsx' and 'xlsm' will be converted to PDF with 'Office' via a script.
If they are not available (on linux for example), 'Libre Office' will be used to convert documents. In that case the rendering can be different from the original document. It supports very well 'Microsoft PowerPoint' to PDF. 'Microsoft Word' can also be converted but some Word features are not supported, such as sections.
Workbooks ('xlsx', 'xlsm', 'xls', 'ods') are exported sheet by sheet:
'Excel' scales each sheet to the width of one page, see xlsx2pdf();
'LibreOffice' exports each sheet on a single page with the size of
its content.
to_pdf(
input,
output = gsub("\\.[[:alnum:]]+$", ".pdf", input),
timeout = 120,
UserInstallation = NULL,
show_markup = FALSE
)
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'. |
timeout |
timeout in seconds that 'LibreOffice' is allowed to use to convert the document, ignored if 0. It is not used when 'Microsoft Office' converts the document. |
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'. |
show_markup |
if |
the name of the produced pdf (the same value as output),
invisibly.
R adds its own library directories to the environment variable
LD_LIBRARY_PATH, which made 'LibreOffice' fail when run from R
(with the message "libreglo.so cannot open shared object file", or
an abort when /usr/lib/libreoffice/program was added to this
variable). 'LibreOffice' is now run without this variable, there is
nothing to set.
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.