-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint-pdf.js
64 lines (53 loc) · 2.14 KB
/
print-pdf.js
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
/**
* phantomjs script for printing presentations to PDF.
*
* Example, running local server in the present directory, defaulting to writing to slides.pdf
* phantomjs print-pdf.js
*
* Example, pulling from any URL
* phantomjs print-pdf.js "http://lab.hakim.se/reveal-js?print-pdf" reveal-demo.pdf
*
* By Manuel Bieh (https://github.com/manuelbieh) - https://github.com/hakimel/reveal.js/blob/master/plugin/print-pdf/print-pdf.js
* modified by shearer12345 (https://github.com/shearer12345) to delay rendering to allow pages that load content after on_load still work (usually). Also modified to run a simple web server to serve the content.
*/
var childProcess = require('child_process');
console.log( 'Starting pythonHttpServer' );
var pythonHttpServer = childProcess.spawn(
'python',
// second argument is array of parameters, e.g.:
["-m"
, "http.server"]
);
// html2pdf.js
var page = new WebPage();
var system = require( 'system' );
// example .\phantomjs.exe .\print-pdf.js 'http://shearer12345.github.io/talkLincolnOpenDayGamesComputing/?print-pdf/'
page.paperSize = {
format: 'A4',
orientation: 'landscape',
margin: {
left: '0',
right: '0',
top: '0',
bottom: '0'
}
};
page.zoomFactor = 1.0;
var revealFile = system.args[1] || 'http://localhost:8000/?print-pdf/#/';
var slideFile = system.args[2] || 'slides.pdf';
if( slideFile.match( /\.pdf$/gi ) === null ) {
slideFile += '.pdf';
}
console.log( 'Printing PDF...' );
loadDelaySeconds = 10;
page.open( revealFile, function( status ) {
console.log( 'Opened succesfully. Waiting ', loadDelaySeconds, ' seconds for page to fully load.' );
window.setTimeout(function () {
console.log( 'Finished waiting - now rendering' );
page.render( slideFile );
console.log( 'Finished rendering. Stopping pythonHttpServer.' );
pythonHttpServer.kill();
console.log( 'Done' );
phantom.exit();
}, loadDelaySeconds * 1000);
} );