• Stars
    star
    241
  • Rank 161,489 (Top 4 %)
  • Language
    Java
  • License
    Other
  • Created almost 11 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Converts various HTML5 slide decks to PDF

deck2pdf

deck2pdf is a simple application that will convert your deck.js, reveal.js, impress.js, Flowtime.js, Google html5slides, Slide Presentation Framework, ruban or DZSlides slide deck into a PDF file. Deck2PDF is also capable of handling other HTML5 libraries as long as you feed it with a profile.

This application relies on a JavaFX application, so you need at least a Java 7 installation that bundles JavaFX (which should be the case for all newer installs of Java).

1. Download

Pre-built binaries for JDK 8 can be download from Bintray.

If you use Gradle (or any Maven-compatible dependency resolution engine), artifacts are available on JCenter:

repositories {
    jcenter()
}
dependencies {
   compile 'me.champeau.deck2pdf:deck2pdf:0.3.0'
}

2. Install from source

Build Status

Alternatively, you can install deck2pdf from sources.

./gradlew distZip

Will generate a distribution into build/distributions/ that you can unzip wherever you want.

3. Changelog

3.1. 0.3.0

  • Change group from com.github.melix to me.champeau.deck2pdf

  • Add ability to export to PNG or JPEG

  • Require Java 8

4. Usage

deck2pdf --profile=deckjs <inputfile> <outputfile>

By default, deck2pdf assumes that you are using deck.js, but there more profiles supported:

For example, to convert a Deck.js slidedeck into PDF:

deck2pdf slides.html slides.pdf

Or for a reveal.js slidedeck:

deck2pdf --profile=revealjs slides.html slides.pdf

Optionally, you can specify width and height:

deck2pdf --width=1024 --height=768 slides.html slides.pdf

To export the slides as multiple images (PNG or JPG), change the file extension of the export file to .png or .jpg.

deck2pdf slides.html slides.png

You can use a number pattern in the file name (e.g., %03d) to have the slide numbers padded so they have a fixed length:

deck2pdf slides.html slides-%03d.png

You can also specify a quality option for JPG (default: 0.95):

deck2pdf --quality=75 slides.html slides.jpg
Warning
The JPG export is not available when using OpenJDK. You must use the Oracle JDK instead.

For a remark.js slideshow, make sure you use window.slideshow = remark.create(); to initialize the slideshow

5. Profile specific options

Some profiles have specific command line options that allow further configuration of the export. This section summarizes the options available for such profiles.

5.1. reveal.js

Option Behavior Default Example

skipFragments

If true, fragments will be ignored, otherwise each fragment will generate an individual slide

false

deck2pdf --skipFragments=true revealjs.html

5.2. ruban

Option Behavior Default Example

skipSteps

If true, instead of generating one PDF page per step, generates one PDF slide per section, with the last step of each section.

false

deck2pdf --skipSteps=true index.html

6. Support for other HTML5 slideshows

deck2pdf is capable of handling many HTML5 slideshows. The current distribution supports several profiles out of the box but it is easy to add yours. Depending on the complexity of the the framework, you can use either a simple properties file to describe your framework or a more complex Groovy file. Both profile types rely on the fact that you communicate with the browser with Javascript. This means that deck2js should be compatible with any HTML5 slideshow that exposes a Javascript API.

6.1. Simple profile using properties

The easiest way to define a new profile is to create a properties file. For example, here is the file that the deck.js export uses:

link:src/main/resources/deckjs.properties[]

The properties files consists of two entries:

  • totalSlides is a Javascript snippet which will compute the total number of slides of the deck

  • nextSlide is the Javascript code which needs to be called to jump to the next slide

Properties files are very simple, so are only capable of handling decks for which the number of slides is known in advance and the command to jump from one slide to another is always the same. For more complex slide shows, you can use the Groovy profiles.

6.2. Advanced profiles

6.2.1. Example

Advanced profiles are written using the Groovy scripting language. However, they are pretty simple too and they expose a simple API that should fit most situations.

Here is an example of profile as it is defined for impress.js:

link:src/main/resources/impressjs.groovy[]

The file name for a properties profile must end with .properties.

6.2.2. Groovy API

The Groovy allows you to define more complex interactions with the slide deck. It also allows you to export slide decks for which you don’t know the number of slides in advance, as long as you are capable of telling that you’ve reached the end of the slide deck.

Calling javascript in the browser from the profile is done using the js function:

js 'var slideCount = slides.length;'

Then the Groovy profile exposes some hooks that you can use:

  • setup is called once the slide deck is loaded and ready for export. It gives you a chance to perform an initial customization before exporting the slides. For example:

setup = {
    // disable controls for better rendering
    js 'Reveal.configure({controls: false, progress: false});'
}
  • isLastSlide is called after a slide has been exported. If the method returns true, then export is complete. For example:

isLastSlide = {
    js '''
        var totalSlides = Dz.slides.length;
        var cSlide = Dz.idx;
        cSlide==totalSlides && Dz.step==Dz.slides[cSlide - 1].$$('.incremental > *').length
    '''
}
  • totalSlides can be used to determine the total number of slides (if a slide contains a transition, each transition is counted as a slide). It is optional, as long as you define the isLastSlide hook. Providing it would add a counter to the log output.

totalSlides = {
    js (/$$(".step", byId('impress')).length/)
}
  • nextSlide must be implemented so that deck2pdf knows how to jump from one slide to another (or one transition to another). For example:

nextSlide = {
    js('api.next()')
}

As the Groovy profile is stateful, you can for example keep track of the slide number and have a distinct operation depending on the slide number:

int curSlide = 0
nextSlide = {
    curSlide++
    switch (curSlide) {
        case 1:
            js 'api.next()'
            break;
        case 2:
            js 'api.goto(2)'
            break;
        default:
            js "api.goto($curSlide)"
    }
}
  • pause lets you change the duration before next slide is exported, in milliseconds. Currently, you are not allowed to set a distinct pause for each slide, the change is global. For example:

pause = 2000

The file name for a Groovy profile must end with .groovy.

Accessing command line options

It is possible for a Groovy profile to access command line options. This can be useful if you want the profile to be configurable from command line. Accessing the command line options is easy, since the named parameters from the command line are directly exported in the script through the options variable:

setup {
    if (Boolean.valueOf(options.verbose)) {
        // --verbose=true on command line
        println "Hello, I'm in verbose mode!"
    }
    String mode = options.mode?:'auto'
    switch (mode) {
        case 'auto':
            ...
            break;
        case 'skip':
            ...
            break;
    }

}

6.3. Using a custom profile

Once you’ve written a new profile, you can use it with the --profile switch:

deck2pdf --profile=/path/to/profile.groovy slides.html slides.pdf

Of course, you can submit a pull request so that we include your profile into the distribution!

7. Custom fonts

You’ll need to read this section if you have custom fonts in your presenation.

7.1. JavaFX 3.0: CSS3 @font-face

In order to use custom fonts in your presentation, as defined using the CSS3 +@font-face@, you need to use at least JavaFX 3.0 (available in JDK 8). Otherwise, the embedded browser will fall back to using the default system font.

Here’s an example custom font sourced from Google Fonts:

<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:400,700">

This link element imports the following CSS:

@font-face {
  font-family: 'Yanone Kaffeesatz';
  font-style: normal;
  font-weight: 400;
  src: local('Yanone Kaffeesatz Regular'), local('YanoneKaffeesatz-Regular'), url(http://themes.googleusercontent.com/static/fonts/yanonekaffeesatz/v4/YDAoLskQQ5MOAgvHUQCcLbvy90DtE_Pg_qiF9bHvTzw.ttf) format('truetype');
}
@font-face {
  font-family: 'Yanone Kaffeesatz';
  font-style: normal;
  font-weight: 700;
  src: local('Yanone Kaffeesatz Bold'), local('YanoneKaffeesatz-Bold'), url(http://themes.googleusercontent.com/static/fonts/yanonekaffeesatz/v4/We_iSDqttE3etzfdfhuPRUgbSk09ekaEjkXjfj0Ujx8.ttf) format('truetype');
}

You can now use these two combinations of font-family, font-style and font-weight in your presentation. Unlike a normal browser (e.g., Chrome, Firefox, etc), you cannot use a font combination that is not represented here (or on your system). If you attempt to use a combination not represented here (such as a combination that include font-style: italic;), the embedded browser will fall back to using the default font.

Aside from that exception, custom fonts should just work when using JavaFX 3.0.

7.2. JavaFX 2.2: Explicit font loading

If you you’re using JavaFX 2.2 (available in JDK 7), you can still use custom fonts, but you must load them explicitly before the embedded browser loads the presentation.

First, download the TTF file for each font you want to use and copy it to a directory of your choice. The files should be named using the hyphenated form shown in the CSS above. For example:

  • YanoneKaffeesatz-Regular.ttf

  • YanoneKaffeesatz-Bold.ttf

Now you can use the fontsdir command line option to tell deck2pdf where to load the fonts from:

deck2pdf --fontsdir=/path/to/ttf/files slides.html slides.pdf

More Repositories

1

jmh-gradle-plugin

Integrates the JMH benchmarking framework with Gradle
Groovy
598
star
2

japicmp-gradle-plugin

A Gradle plugin for JApicmp
Java
134
star
3

jdoctor

A Java library for designing good error messages
Java
133
star
4

gr8confagenda

Source code for the GR8Conf Agenda Android application
Groovy
118
star
5

includegit-gradle-plugin

A Gradle plugin to include Git repositories
Java
95
star
6

asm-bytecode-intellij

An ASM (http://asm.ow2.org/) plugin for IntelliJ IDEA
Java
69
star
7

grooidshell-example

An example of usage of dynamic classes at runtime using Groovy on Android
Java
45
star
8

groovy-bytecode-ast

A Groovy AST transformation which allows writing the body of a method as bytecode instructions.
Groovy
45
star
9

gradle-buildscan-recipes

A Gradle plugin for Build Scans
Groovy
43
star
10

antlr4-gradle-plugin

Antlr4 plugin for Gradle
Groovy
40
star
11

ast-workshop

Unleashing the power of AST transformations
Shell
38
star
12

jmh-gradle-example

Sample project showcasing the JMH gradle plugin
Java
38
star
13

jlangdetect

A language detection library for the JVM
Java
33
star
14

mrjar-gradle

Example of how to produce a MRJAR with Gradle
Groovy
21
star
15

speakertime

A demo project for Groovy and Android, as seen in Devoxx
Groovy
20
star
16

astro4j

Astronomy libraries for Java
Java
18
star
17

mrjar-gradle-plugin

A multi-release JAR plugin for Gradle
Java
18
star
18

springboot-groovytemplates

A demo app that makes use of Spring Boot, Groovy templates and GORM
Groovy
15
star
19

gradle-presentation-template

A presentation template using Asciidoctor+Reveal.js and Gradle
Kotlin
14
star
20

gradle-6-whats-new

What's new in Gradle 6?
Kotlin
13
star
21

gradle-cf-plugin

Gradle plugin for CloudFoundry
Groovy
13
star
22

gradle-tapi-demo-artifacts

A demonstration of the Gradle Tooling API: inspecting Gradle builds to get some information about them
Java
12
star
23

teamcity-groovy-buildstep

A TeamCity plugin which adds the ability to write a build step using Groovy
JavaScript
10
star
24

openbeans

Automatically exported from code.google.com/p/openbeans
Java
9
star
25

codenarc-idea

Java
9
star
26

blog

My blog
CSS
8
star
27

gradle-wasm-plugin

A POC of writing Gradle tasks using wasm as implementation
Java
7
star
28

micronaut-test-resources-demo

Java
7
star
29

lecharny-challenge

The Lecharny Challenge
Java
7
star
30

gradle-maven-exec

Embedding Maven build in Gradle
Kotlin
6
star
31

graal-simple-httpserver

A simple HTTP server using Kotlin, Groovy and Gradle
Kotlin
6
star
32

version-catalog-poc

Kotlin
5
star
33

grithub

A Groovy API for GitHub Java API
Groovy
5
star
34

robovm-groovy-test

A test project for Groovy on RoboVM
Groovy
4
star
35

spring-groovymarkup

Support classes for using MarkupTemplateEngine from Spring
Java
4
star
36

maven-repository-injection

A POC which demonstrates repository injection with Apache Maven
Java
4
star
37

staticbuilder

Statically compiled markup builder for Groovy
Java
4
star
38

javaone2016-juggling-jigsaw

Groovy
3
star
39

advisories-gradle-plugin

A plugin which scans your dependencies for vulnerabilities looking at GitHub advisories database
Kotlin
3
star
40

groovy-guava

A Groovier API for Google Guava
Groovy
3
star
41

javaone-groovy-dsls

HTML
3
star
42

paseq-gradle-plugin-poc

Proof of concept of paseq plugin for Gradle
Java
3
star
43

poc-gradle-git-demo

Demonstrates generation of a class from Git info
Java
3
star
44

gradle-variant-aware-dependency-resolution

Java
2
star
45

devoxxbe2015-groovy-dsls

HTML
2
star
46

finistjug-fast-builds

HTML
2
star
47

gradlesummit2016-jigsaw-gradle

Java
2
star
48

gradle-compile-avoidance-current-model

Groovy
2
star
49

gradle-repl

Kotlin
2
star
50

kotlin-mpp-demo

Kotlin
2
star
51

s2gx-groovy-dsls

Slides for S2GX 2015 "Building modern DSLs in Groovy"
HTML
2
star
52

bdxjug2015

Talk at BordeauxJUG, May 2015
Groovy
2
star
53

gradle-download-helper

Java
2
star
54

rivieradev-composite-builds

Talk about composite builds at RivieraDev 2017
HTML
2
star
55

benchmark-groovy-gstring

Benchmark for String concatenation in Groovy
Groovy
2
star
56

gr8conf2016-intro-software-model

Introduction to the new Java software model in Gradle
Groovy
2
star
57

gradle-javac-dependencies-plugin

Experimental javac plugin
Java
2
star
58

jroller-export

Exports from JRoller.com to JBake compatible format
Shell
2
star
59

micronaut-license-report

An aggregating project to generate a license report
Kotlin
1
star
60

s2gx-deepdive-groovy-compiler

Slides for S2GX 2015 "Deep dive into the Groovy compiler"
Groovy
1
star
61

micronaut-aot-demo

Java
1
star
62

gradle-dependencies-dump

Playground for dumping gradle dependencies
Java
1
star
63

s2gx-2013

SpringOne2GX 2013 slideware
JavaScript
1
star
64

gr8conf2016-deepdive-groovy-compiler

Deep dive into the Groovy compiler - GR8Conf Europe 2016
Groovy
1
star
65

devoxxfr2013

Slides and source code for Devoxx France 2013 conferences
Shell
1
star
66

ggx2013

Slides for my Groovy & Grails eXchange 2013 talk
JavaScript
1
star
67

CodeStory

Concours CodeStory
Groovy
1
star
68

webinar-dep-mgmt-part-2

Kotlin
1
star
69

micronaut-uber-build

Java
1
star
70

gr8conf2016-variant-aware-dep-mgmt

Slides for "Variant aware dependency management with Gradle"
HTML
1
star
71

talks

Slides for various talks
JavaScript
1
star
72

gradle-global-config-consistency-plugin

Kotlin
1
star
73

virtualjug-fast-builds

HTML
1
star
74

paris-android-ug-fast-builds

Slides for my Paris Android User Group talk
HTML
1
star
75

micronaut-svelte-demo

Java
1
star
76

javaone-2017-max-incremental

Slides for my JavaOne 2017 talk : minutes to seconds - maximizing incrementality
HTML
1
star
77

javaone-2017-jigsaw

Slides for my JavaOne 2017 talk : building and testing Java 9 applications with Gradle
HTML
1
star
78

groovy-script-extension-example

Java
1
star
79

sphero-playground

Go
1
star