Skip to content

Instantly share code, notes, and snippets.

@btbytes
Forked from ramnathv/README.md
Last active August 29, 2015 13:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save btbytes/8717232 to your computer and use it in GitHub Desktop.
Save btbytes/8717232 to your computer and use it in GitHub Desktop.
Creating PDF versions of slidify presentations
*.md
*.html
*.pdf
libraries

Creating PDF versions of slidify presentations

This gist consists of a makefile and a script that can automate the creation of PDFs from Slidify generated HTML slides. The script assumes that the makefile and the script makepdf.js are in the same directory as the Rmd file. The makepdf.js script uses casperjs, a very useful utility to automate tasks that require browser interaction. You may follow the installation instructions on the casperjs website, to make sure that you have all the dependencies correctly installed before trying this out.

Installing dependencies

To install the R packages:

# install devtools if you haven't already
# install.packages('devtools')
pkgs <- c("slidify", "slidifyLibraries", "rCharts")
install_github(pkgs, 'ramnathv', ref = 'dev')

To install casperjs 1.1 (as casperjs 1.0.x does not work with phantomjs versions >= 1.9.0) [on a mac with brew]:

brew install casperjs --devel
---
title :
subtitle :
author :
job :
framework : io2012 # {io2012, html5slides, shower, dzslides, ...}
highlighter : highlight.js # {highlight.js, prettify, highlight}
hitheme : tomorrow #
widgets : [] # {mathjax, quiz, bootstrap}
mode : selfcontained # {standalone, draft}
---
## Read-And-Delete
1. Edit YAML front matter
2. Write using R Markdown
3. Use an empty line followed by three dashes to separate slides!
--- .class #id
## Slide 2
DELAY = 1000
RMD_FILE = $(wildcard *.Rmd)
HTML_FILE = $(patsubst %.Rmd, %.html, $(RMD_FILE))
PDF_FILE = $(patsubst %.Rmd, %.pdf, $(RMD_FILE))
pdf: $(PDF_FILE)
html: $(HTML_FILE)
all: $(PDF_FILE) $(HTML_FILE)
%.pdf: %.html
casperjs makepdf.js $< $@ $(DELAY)
%.html: %.Rmd
cd $(dir $<) && Rscript -e "slidify::slidify('index.Rmd')" && cd ..
clean:
rm -rf libraries
rm -r $(PDF_FILE)
rm -r $(HTML_FILE)
.PHONY: clean
var casper = require('casper').create({viewportSize:{width:1500,height:1000}});
var args = casper.cli.args;
var imgfile = (args[1] || Math.random().toString(36).slice(2))
casper.start(args[0], function() {
this.wait(args[2], function(){
this.captureSelector(imgfile, "slides");
});
});
casper.run();
@FavioVazquez
Copy link

Hi! Have you find a way to embed rCharts plots in the PDF? Maintaining the plot as it will render in the HTML page, dynamic and modifiable?

I run this, with some extra tweaks, and the graphs just does't show in the PDF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment