Skip to content

Instantly share code, notes, and snippets.

@diverted247
Last active March 21, 2024 18:55
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save diverted247/4c32679519ce2d063934 to your computer and use it in GitHub Desktop.
Save diverted247/4c32679519ce2d063934 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' );
}
})();
@diverted247
Copy link
Author

Corrects viewBox based on svg data. Will be cropped perfectly around slide contents at slide size

@andrewpeck
Copy link

Thanks so much for posting this, it is great. I needed a diagram that I made for a powerpoint as part of my documentation. This came up in my search and worked really well. I used it from Firefox and it works there also. Thanks again!

@stupidSheep
Copy link

The current slide can also be exported directly from Slides without any scripting. File > Download > Scalable Vector Graphics

@kuznetsov-ds
Copy link

Hi!
Have tryed different ways - it saves only first 10 slide. Why could it be?

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