blob: 86dc4df8a6b9e14cd543ba77b1ca0b8c46b17c1c [file] [log] [blame]
JJ Allaireefa6ad42016-01-30 13:12:05 -05001/**
2 * phantomjs script for printing presentations to PDF.
3 *
4 * Example:
5 * phantomjs print-pdf.js "http://lab.hakim.se/reveal-js?print-pdf" reveal-demo.pdf
6 *
7 * By Manuel Bieh (https://github.com/manuelbieh)
8 */
9
10// html2pdf.js
11var page = new WebPage();
12var system = require( 'system' );
13
14var slideWidth = system.args[3] ? system.args[3].split( 'x' )[0] : 960;
15var slideHeight = system.args[3] ? system.args[3].split( 'x' )[1] : 700;
16
17page.viewportSize = {
18 width: slideWidth,
19 height: slideHeight
20};
21
22// TODO
23// Something is wrong with these config values. An input
24// paper width of 1920px actually results in a 756px wide
25// PDF.
26page.paperSize = {
27 width: Math.round( slideWidth * 2 ),
28 height: Math.round( slideHeight * 2 ),
29 border: 0
30};
31
32var inputFile = system.args[1] || 'index.html?print-pdf';
33var outputFile = system.args[2] || 'slides.pdf';
34
35if( outputFile.match( /\.pdf$/gi ) === null ) {
36 outputFile += '.pdf';
37}
38
39console.log( 'Printing PDF (Paper size: '+ page.paperSize.width + 'x' + page.paperSize.height +')' );
40
41page.open( inputFile, function( status ) {
42 window.setTimeout( function() {
43 console.log( 'Printed succesfully' );
44 page.render( outputFile );
45 phantom.exit();
46 }, 1000 );
47} );
48