-
Notifications
You must be signed in to change notification settings - Fork 5
/
Slides2Png.scala
executable file
·74 lines (55 loc) · 1.67 KB
/
Slides2Png.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env sbt -Dsbt.main.class=sbt.ScriptMain
/***
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
"org.seleniumhq.selenium" % "selenium-java" % "2.53.0",
"org.scalatest" % "scalatest_2.11" % "2.2.0"
)
*/
import org.scalatest._
import org.scalatest.selenium._
import scala.annotation.tailrec
val presentationDim = new org.openqa.selenium.Dimension(1440,900)
def renderSlidesToImages(url: String, dirName: String): Int = {
import Firefox._
val MAX_SLIDES = 999
val SLEEP_MS = 500
def fullscreen = pressKeys("f")
def nextSlide = pressKeys("n")
def executeAsBoolean(s: String): Boolean = executeScript(s).asInstanceOf[Boolean]
def hasRightRoute = executeAsBoolean("return Reveal.availableRoutes().right;")
def screenshot(file: String) = { Thread.sleep(SLEEP_MS); capture to file }
@tailrec
def renderSlide(slides: List[String]): List[String] = {
val slide = "slide_%04d.png" format slides.size
screenshot(slide)
val allSlides = slide :: slides
if (hasRightRoute && allSlides.size < MAX_SLIDES) {
nextSlide
renderSlide(allSlides)
}
else {
allSlides
}
}
setCaptureDir(dirName)
go to url
webDriver.manage.window.setSize(presentationDim)
val slides = renderSlide(Nil)
close()
slides.size
}
def renderSlidesToPDF(url: String) {
val dirName = "slides_" + System.currentTimeMillis
val count = renderSlidesToImages(url, dirName)
val script = s"bin/png2pdf.sh $dirName"
sys.process.Process(script).run
println(s"Rendered $count slides")
}
// Entry point for our script
args.toList match {
case List(x) =>
renderSlidesToPDF(x)
case _ =>
System.err.println("usage: Slides2Png.scala <url>")
}