Create a gist now

Instantly share code, notes, and snippets.

Export a dzslides presentation to PNGs, then combine into a PDF using geb [Windows]
* slides2png is a Groovy script that 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.
* slides2png relies on IMAGE_MAGICK_HOME environment variable pointing to
* the directory where ImageMagick was unpacked.
* @author Dan Allen, Samuel Santos
* @license ASLv2
* @see
import geb.Browser
if (args.length == 0) {
println "Please specify the URL of the presentation"
def url = args[0]
def reportsDir = "/tmp/geb-reports"
if (args.length > 1) {
reportsDir = args[1]
} {
config.reportsDir = new File(reportsDir)
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.bat")
script.append("rem Convert PNGs files into a PDF\n\n")
script.append("call cd $reportsDir\n")
script.append("call \"%IMAGE_MAGICK_HOME%/convert\"")
script.append(" slide_" + idx + ".png")
body << 'j'
sleep 500
script.append(" presentation.pdf")
script.executable = true
def out = new StringBuilder()
def err = new StringBuilder()
def proc = [script.absolutePath].execute()
proc.consumeProcessOutput(out, err)
println "out:\n$out"
println "err:\n$err"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment