Skip to content

Instantly share code, notes, and snippets.

@ramnathv
Created January 30, 2014 00:33
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ramnathv/8700285 to your computer and use it in GitHub Desktop.
Save ramnathv/8700285 to your computer and use it in GitHub Desktop.
Creating PDF Version 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.

DELAY = 1000
RMD_FILE = $(wildcard *.Rmd)
HTML_FILE = $(patsubst %.Rmd, %.html, $(RMD_FILES))
PDF_FILE = $(patsubst %.html, %.pdf, $(HTML_FILES))
pdf: $(PDF_FILE)
html: $(HTML_FILE)
all: pdf html
%.pdf: %.html
casperjs makepdf.js $< $@ $(DELAY)
%.html: %.Rmd
cd $(dir $<) && Rscript -e "slidify::slidify('index.Rmd')" && cd ..
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

How do I implement this? I have a slidify presentation with some rCharts plots in it. When I press the knitter button it renders automatically to HTML. How can I use this to export my presentation to PDF? Is this the only way? Thanks.

@mwilson19
Copy link

Really like this information thank you very much, I am a novice so took me a minute to figure out how to call the script and make it work, you may want to add that to this.

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