Skip to content

Instantly share code, notes, and snippets.

@zoncoen
Created June 18, 2014 00:47
Show Gist options
  • Save zoncoen/8911900331b2ac4b227f to your computer and use it in GitHub Desktop.
Save zoncoen/8911900331b2ac4b227f to your computer and use it in GitHub Desktop.
Print pdf with vertical centering contents in Reveal.js. Run this snippet on the Chrome dev tools just before exporting the PDF. (https://github.com/hakimel/reveal.js/issues/563)
function toArray(o) {
return Array.prototype.slice.call(o);
}
toArray( document.querySelectorAll( '.reveal .slides section' ) ).forEach(function(slide){
var outerWrapper = document.createElement('div');
outerWrapper.style.cssText = 'display:flex; align-items:center; height:100%';
var wrapper = document.createElement('div');
wrapper.style.width = '100%';
outerWrapper.appendChild(wrapper);
toArray( slide.children ).forEach(wrapper.appendChild, wrapper);
slide.style.height = '100%';
slide.appendChild(outerWrapper);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment