在 R 中将 pptx 保存为 pdf

Saving pptx as pdf in R

我已经使用 officer 包创建了 powerpoint 文件,我还想将它们从 R 中保存为 pdf(不想手动打开每个文件并将其另存为 pdf)。这可能吗?

您可以保存使用此处发布的代码编辑的 powerpoint 对象:create pdf in addition to word docx using officer

您需要先安装 pdftools 和 libreoffice

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")

请注意 officer 软件包的作者是 referred 对此回复的人。

请注意 具有 LibreOffice iOS 路径。 (我个人最初没有注意到)。 Windows 路径类似于 "C:/Program Files/LibreOffice/program/soffice.exe".

自 Corey 提供的初始答案以来,使用 docxtractr::convert_to_pdf can now be found here 的示例。 包和函数是.