Skip to content

Instantly share code, notes, and snippets.

@tzmartin
Forked from diverted247/README
Created September 18, 2016 05:46
Show Gist options
  • Save tzmartin/88af3973683e450de0f6f0b28e23644c to your computer and use it in GitHub Desktop.
Save tzmartin/88af3973683e450de0f6f0b28e23644c to your computer and use it in GitHub Desktop.
Export slides from Google Slides as SVG - Console Script (Chrome tested)
To export SVG from Google Slides.
1. Open Slide deck.
2. View -> 100%
3. Click on every thumbnail from first to last, this puts the SVG into the DOM.
4. Paste the export.js in the console.
5. Make sure to allow multiple downloads.
6. All SVG should be in Downloads folder.
Cheers,
Ted :)
(function(){
var list = document.getElementById( 'pages' ).children;
var savexml = function( data , filename ){
var blob = new Blob( [ data ] , { type: 'text/xml' } );
var e = document.createEvent( 'MouseEvents' );
var a = document.createElement( 'a' );
a.download = filename;
a.href = window.URL.createObjectURL( blob );
a.dataset.downloadurl = [ 'text/json' , a.download , a.href ].join( ':' );
e.initMouseEvent( 'click' , true , false , window , 0 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
a.dispatchEvent( e );
}
//prep viewBox and svg element
//resize based on viewbox and initial transform
//google slides keeps transform for view in first <g> element
var x = list[0].getElementsByTagName('g')[0].transform.baseVal[0].matrix.e;
var y = list[0].getElementsByTagName('g')[0].transform.baseVal[0].matrix.f;
var w = list[0].viewBox.baseVal.width - x*2;
var h = list[0].viewBox.baseVal.height - y*2;
var viewbox = x + ' ' + y + ' ' + w + ' ' + h;
var header = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" fill-rule="evenodd" fill="none" stroke="none" stroke-linecap="square" stroke-miterlimit="10" overflow="hidden" viewBox="' + viewbox + '">';
var len = list.length;
for( var i = 0; i < len; i++ ){
savexml( header + list[i].innerHTML + '</svg>' , (i+1) + '.svg' );
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment