Browse files

Adjusted pdf generation to skip the rasterization pass

This means you now need to download pdftk in addition to phantomJS, since it's used to merge multiple pdfs in one
  • Loading branch information...
1 parent 7975397 commit 4a2a570a20372743cb0e1102174225bf56d27507 @Seldaek committed May 25, 2011
Showing with 37 additions and 66 deletions.
  1. +1 −0 .gitignore
  2. +4 −2 README.mdown
  3. +0 −11 bin/phantom-png-to-pdf.js
  4. +19 −9 bin/{phantom-slippy-to-png.js → phantom-slippy-to-pdf.js}
  5. +11 −15 bin/slippy-pdf.sh
  6. +2 −29 src/slippy.css
View
1 .gitignore
@@ -1,3 +1,4 @@
bin/phantomjs
+bin/pdftk
src/config.php
src/myrepo.php
View
6 README.mdown
@@ -33,11 +33,13 @@ To upload your presentation on SlideShare, or to share it with others, it can be
export it to a PDF. Slippy comes with a CLI utility that does just that.
The only requirement is that you download [PhantomJS](http://code.google.com/p/phantomjs/downloads/list) (1.1+)
-and place it inside the bin/phantomjs dir or make it accessible via your PATH environment variable.
+and [pdftk](http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/) and place the executables in the bin/phantomjs
+and bin/pdftk dirs or make them accessible via your PATH environment variable.
Once that is done, you can call the script using `bin/slippy-pdf.sh <path to your html presentation> <path to the pdf file to generate>`.
-It'll take a while and then should output a 4:3 high-res PDF file.
+It'll take a while and then should output a 4:3 PDF file. If you don't like the aspect ratio or size,
+you can change the viewport size in the `bin/phantom-slippy-to-pdf.js` file.
Author
------
View
11 bin/phantom-png-to-pdf.js
@@ -1,11 +0,0 @@
-if (phantom.state.length === 0) {
- phantom.state = 'rasterize';
- phantom.viewportSize = { width: 2048, height: 2000 };
- phantom.paperSize = { width: 2048, height: 1536+4 };
- console.log('opening page');
- phantom.open("tmp-pdf/tmp-pdf.html");
-} else {
- phantom.sleep(500);
- phantom.render("tmp-pdf/slides.pdf");
- phantom.exit();
-}
View
28 bin/phantom-slippy-to-png.js → bin/phantom-slippy-to-pdf.js
@@ -1,24 +1,34 @@
+var current, slides, viewport, output, delay;
+
+// settings
+delay = 500;
+viewport = { width: 1024, height: 768 };
+
+// init
if (phantom.state.length === 0) {
if (phantom.args.length !== 2) {
console.log('Usage: phantom-pdf.js URL dirname');
phantom.exit();
} else {
- var address = phantom.args[0];
phantom.state = 'rasterize';
- phantom.viewportSize = { width: 2048, height: 1536 };
console.log('opening page');
- phantom.open(address);
+ phantom.open(phantom.args[0]);
}
} else {
- var current = 1;
- var slides = $('.slideContent').length;
- $('.incremental').css('opacity', '1');
- var output = phantom.args[1];
+ // run
+ current = 1;
+ slides = $('.slideContent').length;
+ phantom.viewportSize = { width: viewport.width, height: viewport.height };
+ phantom.paperSize = { width: viewport.width * 1.5, height: viewport.height * 1.5 + 20 };
+ output = phantom.args[1];
+
phantom.sleep(1000);
+ $('.incremental').css('opacity', '1');
+
for (;current<=slides;current++) {
console.log('rendering slide '+current);
- phantom.sleep(500);
- phantom.render(output+'slide'+"000".substring(current.toString().length)+current+'.png');
+ phantom.sleep(delay);
+ phantom.render(output+'slide'+"000".substring(current.toString().length)+current+'.pdf');
$(document).click();
$(document).click();
}
View
26 bin/slippy-pdf.sh
@@ -25,21 +25,17 @@ if [ "" = "$phantom" ]; then
fi
fi
-$phantom $bin/phantom-slippy-to-png.js $1 tmp-pdf/
-
-cd tmp-pdf
-
-echo '<!DOCTYPE html><html><head><title>Slippy Export</title>
-<style>img, body, html, * { border: 0; margin: 0; padding: 0; line-height:0; }</style>
-</head><body>' > tmp-pdf.html
-
-for i in *.png; do
- echo "<img src='$i' />" >> tmp-pdf.html
-done
+pdftk=`which pdftk 2>/dev/null`
+if [ "" = "$pdftk" ]; then
+ if [ -f "$bin/pdftk/pdftk" ]; then
+ pdftk="$bin/pdftk/pdftk"
+ else
+ echo 'pdftk could not be found, either download it and put it inside a pdftk directory, or make it accessible through your PATH environment variable.'
+ exit
+ fi
+fi
-echo '</body></html>' >> tmp-pdf.html
-cd ..
+$phantom $bin/phantom-slippy-to-pdf.js $1 tmp-pdf/
-$phantom $bin/phantom-png-to-pdf.js
-mv tmp-pdf/slides.pdf $2
+$pdftk tmp-pdf/*.pdf cat output $2
rm -r tmp-pdf/
View
31 src/slippy.css
@@ -166,41 +166,14 @@ a.eval {
size: landscape;
}
- .slide {
- position: relative;
- top: auto !important;
- left: auto !important;
- page-break-after: always;
- page-break-inside: avoid;
- height: auto;
- }
-
- .slide.lastslide {
- page-break-after: auto;
- }
-
- .slide, .slideContent, body, html {
- margin: 0 0 1em 0 !important;
- }
-
- .footer {
- background: 0;
- position: fixed;
+ body, html {
+ margin: 0 0 0 0 !important;
}
a.eval, .slideDisplay {
display: none;
}
- .lastslide {
- page-break-after: never;
- }
-
- html, body {
- overflow: auto !important;
- height: auto !important;
- }
-
.backcode {
display: none;
}

0 comments on commit 4a2a570

Please sign in to comment.