Convert docx to pdf directly using "Microsoft Word". This function will not work if "Microsoft Word" is not available on your machine.
The calls to "Microsoft Word" are made differently depending on the operating system:
On "Windows", a "PowerShell" script using COM technology is used to control "Microsoft Word". The resulting PDF is containing a browsable TOC.
On macOS, an "AppleScript" script is used to control "Microsoft Word". The resulting PDF is not containing a browsable TOC as when on 'Windows'.
docx2pdf(input, output = gsub("\\.(docx|doc|rtf)$", ".pdf", input))
the name of the produced pdf (the same value as output
)
library(locatexec)
if (exec_available('word')) {
file <- system.file(package = "doconv",
"doc-examples/example.docx")
out <- docx2pdf(input = file,
output = tempfile(fileext = ".pdf"))
if (file.exists(out)) {
message(basename(out), " is existing now.")
}
}