I kept having the same problem with this method -- I just can't get it to work.
I did figure out a way to convert docx to PDF using RDCOMClient, however.
library(RDCOMClient)
file <- "C:/path/to your/doc.docx"
wordApp <- COMCreate("Word.Application") # create COM object
wordApp[["Visible"]] <- TRUE #opens a Word application instance visibly
wordApp[["Documents"]]$Add() #adds new blank docx in your application
wordApp[["Documents"]]$Open(Filename=file) #opens your docx in wordApp
#THIS IS THE MAGIC
wordApp[["ActiveDocument"]]$SaveAs("C:/path/to your/new.pdf",
FileFormat=17) #FileFormat=17 saves as .PDF
wordApp$Quit() #quit wordApp
I found the FileFormat=17 bit here https://learn.microsoft.com/en-us/office/vba/api/word.wdexportformat
Edit: Alternative option - Use Python in R via Reticulate package. This uses the pywin32 Python package. If you don't have it, you can install it using instructions found here: https://rstudio.github.io/reticulate/articles/python_packages.html
I'm not as conversant in Python, but this works on my machine.
See below:
library(reticulate)
com <- import("win32com.client")
file <- "C:/path/to your/doc.docx"
wordPy <- com$gencache$EnsureDispatch("Word.Application")
wordPyOpen <- wordPy$Documents$Open(file)
wordPyOpen$SaveAs("C:/path/to your/doc.pdf",
FileFormat=17)
wordPy$Quit()
Hopefully this helps!