首页 > 解决方案 > Rstudio Rmarkdown编织到多个pdf?

问题描述

我可以在 Rstudio 中为不同的页面范围(或使用某种分隔符)输出多个 pdf 文件吗?

标签: rstudior-markdownknitr

解决方案


这是我正在使用的一个技巧,以防您找不到简单的方法(在 ubuntu 上,安装pdftk之后):

除了 rmd 文件,我创建了一个 R 脚本,它编辑 rmd 文件生成的 pdf 并将其拆分为更小的 pdf。

例子:

# 1 KNIT THE RMD FILE AND GENERATE A SINGLE PDF WITH ALL THE PAGES
rmarkdown::render('~/my_rmd_file.Rmd')

# 2 CUT THE FIRST 5 PAGES OF THE PDF

# 2.1 make up a name for the smaller pdf: 
name_for_the_top5pages_pdf <- "my_rmd_file_top5.pdf"

# 2.2 compose the command that edits the pdf: 
cmd_extract_first_5_pages <- paste0("pdftk my_rmd_file cat 1-5 output ",name_for_the_top5pages_pdf)

# 2.3 run the command    
system(cmd_extract_first_5_pages)   

它将保留原始 pdf 并使用前 5 页创建另一个。


推荐阅读