How to convert R reveal.js presentation to pdf?

piyush picture piyush · Nov 24, 2016 · Viewed 8.3k times · Source

I made a presentation in R, using one of the reveal.js templates (using revealjs R package).

By default, its generating a html file and when opened for presentation it displays top part of the browser including bookmarks, filepath etc... I can turn off bookmarks bar but not the filepath part, I need to present this in a formal setting so exporting the presentation to pdf seems like a better option.

Does anyone know how to export it to pdf? Can I add anything in the YAML header so that the output will be pdf and not html?

Below is the sample code, it generates "test.html" file. I want to generate "test.pdf" while preserving all other properties of presentations e.g transitions, interactive plots etc...

---
title: "test"
output: revealjs::revealjs_presentation
---

## R Markdown

This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.


## Slide with Bullets

- Bullet 1
- Bullet 2
- Bullet 3

## Slide with R Code and Output

```{r}
summary(cars)
```

## Slide with Plot

```{r, echo=FALSE}
plot(cars)
```

Answer

R Yoda picture R Yoda · Dec 7, 2016

If a manual solution is OK for you (no automatic generation of PDFs when you knit):

Open your HTML file in the browser and add ?print-pdf to the URL, e. g.

http://index.html?print-pdf

You can then print the slides into PDF (e. g. with Ubuntu Linux + Firefox + "save to file" printing option).