├── .gitignore
├── .gitmodules
├── png2pdf.js
├── README.md
└── deck2png.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | deck.js
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "deck.js"]
2 | path = deck.js
3 | url = git@github.com:imakewebthings/deck.js.git
4 |
--------------------------------------------------------------------------------
/png2pdf.js:
--------------------------------------------------------------------------------
1 | var webpage = require('webpage'),
2 | page = webpage.create(),
3 | fs = require('fs');
4 |
5 | page.open('temp-output.html', function(status) {
6 | page.viewportSize = {
7 | width: 1120,
8 | height: 768
9 | };
10 | page.paperSize = {
11 | width: 1680,
12 | height: 1152
13 | };
14 | page.render('output.pdf');
15 |
16 | fs.removeTree('temp-slides');
17 | fs.remove('temp-output.html');
18 | phantom.exit();
19 | });
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Overview
2 |
3 | deck2pdf converts deck.js presentations to PDF using PhantomJS.
4 |
5 | ## Usage
6 |
7 | First, make sure you have PhantomJS installed:
8 |
9 | ```
10 | brew install phantomjs
11 | ```
12 |
13 | Second, add `deck2png.js` and `png2pdf.js` to your deck directory.
14 |
15 | Third, run this:
16 |
17 | ```
18 | phantomjs deck2png.js [yourdeckfile.html] && phantomjs png2pdf.js
19 | ```
20 |
21 | You'll be left with a file named `output.pdf`. If you're lucky, it looks something like your deck.
22 |
23 | ## Development
24 |
25 | The code in this repository is a spike, the result of a few hours of frustrated hacking. A lot of the code is inspired by an old version of the wonderful [Slippy's](https://github.com/Seldaek/slippy) PDF generator. Anyone looking to contribute might be able to glean more by looking at the history of that project.
26 |
27 | I'm currently accepting just about any pull request. There is no documentation. There are no tests. There are no code comments. I don't even know why half of the code I've written is necessary or why it works. (Like why do I have to set the PDF page size to what it is, while the image sizes are completely different?)
28 |
29 | Everything here is MIT license. Use, fork, and sell as you wish and at your own peril.
--------------------------------------------------------------------------------
/deck2png.js:
--------------------------------------------------------------------------------
1 | var webpage = require('webpage'),
2 | page = webpage.create(),
3 | system = require('system'),
4 | url = system.args[1] || 'index.html',
5 | fs = require('fs'),
6 | imageSources = [],
7 | imageTags;
8 |
9 | page.onLoadFinished = function(status) {
10 | var slideCount;
11 |
12 | if (status !== 'success') {
13 | console.log('Target file not found.');
14 | phantom.exit();
15 | }
16 |
17 | page.viewportSize = {
18 | width: 1024,
19 | height: 768
20 | };
21 |
22 | slideCount = page.evaluate(function() {
23 | var $ = window.jQuery;
24 |
25 | $('html').removeClass('csstransitions cssreflections');
26 | $('html, body').css({
27 | 'width': 1024,
28 | 'height': 768,
29 | 'overflow': 'hidden'
30 | });
31 | $.deck('.slide');
32 | return $.deck('getSlides').length;
33 | });
34 |
35 | fs.makeDirectory('temp-slides');
36 |
37 | for (var i = 0; i < slideCount; i++) {
38 | var src = 'temp-slides/output-' + i + '.png';
39 | imageSources.push(src);
40 | console.log('Rendering slide #' + i);
41 | page.render(src);
42 | page.evaluate(function() {
43 | var $ = window.jQuery;
44 | $.deck('next');
45 | });
46 | }
47 |
48 | imageTags = imageSources.map(function(src) {
49 | return '
';
50 | });
51 |
52 | var output = imageTags.join('') + '';
53 | fs.write('temp-output.html', output, 'w');
54 |
55 | phantom.exit();
56 | };
57 |
58 | page.open(url);
--------------------------------------------------------------------------------