docx2pdf {doconv} | R Documentation |
Convert docx to pdf
Description
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'.
Usage
docx2pdf(input, output = gsub("\\.(docx|doc|rtf)$", ".pdf", input))
Arguments
input , output |
file input and optional file output (default to input with pdf extension). |
Value
the name of the produced pdf (the same value as output
)
Windows authorizations
If your execution policy is set to "RemoteSigned", 'doconv' will not be able to run powershell script. Set it to "Unrestricted" and it should work. If you are in a managed and administrated environment, you may not be able to use 'doconv' because of execution policies.
Macos manual authorizations
On macOS the call is happening into a working
directory managed with function working_directory()
.
Manual interventions are necessary to authorize 'Word' and 'PowerPoint' applications to write in a single directory: the working directory. These permissions must be set manually, this is required by the macOS security policy. We think that this is not a problem because it is unlikely that you will use a Mac machine as a server.
You must click "allow" two times to:
allow R to run 'AppleScript' scripts that will control Word
allow Word to write to the working directory.
This process is a one-time operation.
Examples
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.")
}
}