How do I convert RMarkdown ioslides presentations to 2-up PDFs programmatically?

大兔子大兔子 提交于 2021-02-10 12:29:27

问题


I use rmarkdown to generate ioslides HTML presentations, using custom css. This bit is great and I love it. My question is about generating 'notes' versions of presentations.

The only way I've seen to get 2up PDF A4 notes from these slides is to print out of Safari, by clicking Print..., then landscape, then layout 2pages, then border = hairline, then save as. then find the right folder etc. However, it gets the formatting and fonts right, and Webkit renders things that Chrome or other solutions will not.

This is fine for one copy. But I am now regularly updating between 9 and 30 separate presentations at a time and all the clicking sends me nuts, especially when I need to update just a small issue, and I want to check all files have been regenerated as PDF.

Is there any solution to rapidly and programmatically generate a 2-up PDF version of a set of RMarkdown ioslides presentation slides? Alternatively good workarounds would be appreciated.


回答1:


You can use the webshot package to capture the output of HTML graphics and save this to a graphical device (PDF, PNG, PDF). You can read about it here.

Assuming you have a file called testPres.Rmd stored in the same working directory of the following script, it will convert the report to a PDF:

# Setup
install.packages("webshot")
webshot::install_phantomjs()

library(webshot)
library(rmarkdown)

rmdshot("testPres.Rmd", "document.pdf")

Having created a PDF of the slides, we now need to convert them into a two-page PDF. There is probably a more elegant way of doing this but you could use a very basic R Markdown document. This following script will load all the slides into a two-page layout:

---
output: pdf_document
header-includes:
  - \usepackage{pdfpages}
papersize: a4paper
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

\includepdf[pages={1-},scale=0.75, nup=1x2]{document.pdf}

I am not sure this meets your exact requires perfectly, but hopefully is enough to set you in the right direction.

You can check the documentation of the pdfpages LaTeX page to customise how the PDFs of the slide appear in the document (add margins, borders etc.)



来源:https://stackoverflow.com/questions/51491454/how-do-i-convert-rmarkdown-ioslides-presentations-to-2-up-pdfs-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!