使用官员创建 pdf 和 word docx

Ama*_*nda 4 r reporters officer

我在循环中使用官员(用于使用记者)来创建 150 个独特的文档。但是,我需要将这些文档从 R 导出为 word docx 和 pdf。

有没有办法将使用官员创建的文档导出为 pdf?

Dav*_*hel 7

这是可能的,但我的解决方案取决于 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)

  • 快速响应:-),谢谢,我找到了它,必须添加 .exe 并引用“”路径 (2认同)