-
-
Notifications
You must be signed in to change notification settings - Fork 280
Export Slides to PDF
If you have installed Google Chrome or Chromium, you can use the function pagedown::chrome_print()
to print an HTML page to PDF:
install.packages(c("pagedown", "xaringan"))
# make sure you have pagedown >= 0.2 and xaringan >= 0.9; if not, run
# remotes::install_github(c('rstudio/pagedown', 'yihui/xaringan'))
pagedown::chrome_print("path/to/your/slides.Rmd")
# or just pass the HTML output file path to chrome_print()
pagedown::chrome_print("path/to/your/slides.html")
With the xaringanBuilder package and Chrome
# install.packages("remotes")
remotes::install_github("jhelvy/xaringanBuilder")
library(xaringanBuilder)
build_pdf("slides.Rmd")
build_pdf("slides.html")
“Complex” slides are slides that contain
panelsets or
other html widgets / advanced features that might not render well as a
pdf. To render these, set complex_slides = TRUE
. If you want to build a
new slide for each increment on incremental
slides, set
partial_slides = TRUE
.
build_pdf("slides.Rmd", complex_slides = TRUE, partial_slides = TRUE)
build_pdf("slides.html", complex_slides = TRUE, partial_slides = TRUE)
Note: this has only been tested on Windows (10), MacOS & Linux right now.
The webshot()
function from the {webshot} package can render a xaringan html in pdf.
Here's how to:
# install.packages("webshot")
library(webshot)
To run the first time you use the package:
install_phantomjs()
The webshot()
function can convert using a link to a local html. To do this, you'll use the file
protocol. Here's a simple way to point to your local file:
file_name <- paste0("file://", normalizePath("my_xaringan.html"))
You can then:
webshot(file_name, "mypdf.pdf")
Be sure to have the
When browsing the remark
repo, various approaches exist converting HTML slides to PDF. One way is to print the slides to PDF using your web browser (e.g. Ctrl + P
or Command + P
in Google Chrome
). Firefox is not supported, Chrome should work best. There used to be some aesthetic issues, but they have been mostly solved (#65).
You may also consider automated solutions like decktape.js
.
Please follow the README instructions to install it.
You just need to make one command-line call (or use system()
to stay in R) which looks as follows:
system("`npm bin`/decktape remark slides.html slides.pdf") # decktape v2.5.0
As of more recent (xaringan vx.x.x ?) versions, xaringan provides a wrapper to this conversion, and one can simply call:
xaringan::decktape()