Rstudio Rmarkdown编织成多个PDF?

时间:2019-11-29 18:41:27

标签: rstudio r-markdown knitr

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

1 个答案:

答案 0 :(得分:1)

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

除了rmd文件之外,我还创建了一个R脚本,用于编辑rmd文件生成的pdf文件并将其拆分为较小的pdfs。

示例:

# 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页的另一个pdf。

相关问题