除使用Word docx之外,还创建PDF文件 [英] create pdf in addition to word docx using officer
问题描述
我正在一个循环中使用官员(曾经使用过记者)来创建150个唯一文档.但是,我需要将这些文档从R导出为word docx和pdfs.
I am using officer (used to use reporters) within a loop to create 150 unique documents. I need these documents however to be exported from R as word docx AND pdfs.
是否可以将用官员创建的文档导出为pdf?
Is there a way to export the document created with officer to a pdf?
推荐答案
这是可能的,但我的解决方案取决于libreoffice.这是我正在使用的代码.希望它会有所帮助.我已经硬编码了libreoffice路径,那么您可能必须适应或改进变量cmd_
的代码.
That's possible but the solution I have depends on libreoffice. Here is the code I am using. Hope it will help. I've hard-coded libreoffice path then you probably will have to adapt or improve the code for variable cmd_
.
代码将PPTX或DOCX文件转换为PDF.
The code is transforming a PPTX or DOCX file to 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")
这篇关于除使用Word docx之外,还创建PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!