Ama*_*nda 4 r reporters officer
我在循环中使用官员(用于使用记者)来创建 150 个独特的文档。但是,我需要将这些文档从 R 导出为 word docx 和 pdf。
有没有办法将使用官员创建的文档导出为 pdf?
这是可能的,但我的解决方案取决于 libreoffice。这是我正在使用的代码。希望它会有所帮助。我已经对 libreoffice 路径进行了硬编码,那么您可能需要调整或改进 variable 的代码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")
Run Code Online (Sandbox Code Playgroud)