Converts a .docx file to PDF with LibreOffice, or with Microsoft Word
through the doconv package. LibreOffice is free and runs on all
platforms. Each call uses a fresh temporary LibreOffice profile, so it
works while a LibreOffice window is open and in parallel runs.
Usage
docx_to_pdf(
docx,
pdf = NULL,
engine = c("auto", "libreoffice", "word"),
overwrite = FALSE,
verbose = TRUE
)Arguments
- docx
Path to an existing
.docxfile.Path of the PDF to write.
NULL(default) uses the path ofdocxwith the extension changed to.pdf.- engine
"auto"(default) tries LibreOffice, then Word throughdoconvif that package is installed."libreoffice"and"word"force one engine.- overwrite
Overwrite an existing
pdf? DefaultFALSE.- verbose
Print progress messages? Default
TRUE.
Details
If LibreOffice is installed in an unusual place, set the option
convertxlsform.soffice or the environment variable
CONVERTXLSFORM_SOFFICE to the path of the soffice binary.
Examples
if (interactive() && has_libreoffice()) {
docx <- tempfile(fileext = ".docx")
doc <- officer::read_docx()
doc <- officer::body_add_par(doc, "Hello")
print(doc, target = docx)
pdf <- docx_to_pdf(docx, pdf = tempfile(fileext = ".pdf"))
file.exists(pdf)
}
