我在循环中使用官员(过去使用记者)来创建 150 个独特的文档。然而,我需要将这些文档从 R 导出为 word docx 和 pdf。
有没有办法将用officer创建的文档导出为pdf?
这是可能的,但我的解决方案取决于 libreoffice。这是我正在使用的代码。希望它会有所帮助。我已经硬编码了 libreoffice 路径,那么您可能必须调整或改进变量的代码cmd_
.
该代码将 PPTX 或 DOCX 文件转换为 PDF。
library(pdftools)
office_shot <- function( file, wd = getwd() ){
cmd_ <- sprintf(
"/Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf --outdir %s %s",
wd, file )
system(cmd_)
pdf_file <- gsub("\\.(docx|pptx)$", ".pdf", basename(file))
pdf_file
}
office_shot(file = "your_presentation.pptx")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)