Created
June 18, 2012 17:27
-
-
Save mojavelinux/2949536 to your computer and use it in GitHub Desktop.
Export a dzslides presentation to PNGs, then combine into a PDF using geb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* slides2png plays a dzslides presentation using WebDriver, captures each | |
* slide to a PNG and generates a shell script to collate the PNGs together | |
* into a PDF using convert (from ImageMagick). | |
* | |
* The URL of the presentation is passed as the sole argument to the script. | |
* If the presentation is local, specify the absolute path prefixed with the | |
* file:// protocol. | |
* | |
* @author Dan Allen | |
* @license ASLv2 | |
* @see https://github.com/mojavelinux/dzslides/blob/master/scripts/slides2png | |
*/ | |
@Grapes([ | |
@Grab("org.codehaus.geb:geb-core:0.7.0"), | |
@Grab("org.seleniumhq.selenium:selenium-firefox-driver:2.22.0"), | |
@Grab("org.seleniumhq.selenium:selenium-support:2.22.0") | |
]) | |
import geb.Browser | |
if (args.length == 0) { | |
println "Please specify the URL of the presentation" | |
return | |
} | |
def url = args[0] | |
def reportsDir = '/tmp/geb-reports' | |
if (args.length > 1) { | |
reportsDir = args[1] | |
} | |
Browser.drive { | |
config.reportsDir = new File(reportsDir) | |
cleanReportGroupDir() | |
go url | |
def idx = 1 | |
def body = $('body') | |
body << 'f' | |
sleep 500 | |
def script = null | |
def selected = null | |
while (selected == null || !selected.lastElement().equals($('[aria-selected=true]').lastElement())) { | |
selected = $('[aria-selected=true]').last() | |
report "slide_" + idx | |
if (script == null) { | |
script = new File(getReportGroupDir(), 'to_pdf.sh') | |
script.append("#!/bin/sh\n\ncd `dirname \$0`\nconvert") | |
} | |
script.append(' slide_' + idx + '.png') | |
body << 'j' | |
idx++ | |
sleep 500 | |
} | |
script.append(' presentation.pdf') | |
script.executable = true | |
[script.absolutePath].execute().waitFor() | |
}.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment