【发布时间】:2021-05-30 03:25:52
【问题描述】:
我使用officer包创建了PowerPoint文件,我还想将它们保存为R中的pdf(不想手动打开每个文件并将其另存为pdf)。这可能吗?
【问题讨论】:
-
你使用的是什么操作系统?
我使用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 某人对此回复的人。
【讨论】:
docxtractr 包中:cran.r-project.org/web/packages/docxtractr/index.html 在docxtractr::convert_to_pdf 函数中。
请注意,the answer from Corey Pembleton 具有 LibreOffice iOS 路径。 (我个人最初并没有注意到)。 Windows 路径类似于"C:/Program Files/LibreOffice/program/soffice.exe"。
由于Corey提供的初始答案,使用docxtractr::convert_to_pdfcan now be found here的示例。
包和函数是John M commented in Corey initial answer。
【讨论】: