4
4
* Example:
5
5
* phantomjs print-pdf.js "http://lab.hakim.se/reveal-js?print-pdf" reveal-demo.pdf
6
6
*
7
- * By Manuel Bieh (https://github.com/manuelbieh)
7
+ * @author Manuel Bieh (https://github.com/manuelbieh)
8
+ * @author Hakim El Hattab (https://github.com/hakimel)
8
9
*/
9
10
10
11
// html2pdf.js
11
- var page = new WebPage ( ) ;
12
12
var system = require ( 'system' ) ;
13
13
14
- var slideWidth = system . args [ 3 ] ? system . args [ 3 ] . split ( 'x' ) [ 0 ] : 960 ;
15
- var slideHeight = system . args [ 3 ] ? system . args [ 3 ] . split ( 'x' ) [ 1 ] : 700 ;
16
-
17
- page . 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.
26
- page . paperSize = {
27
- width : Math . round ( slideWidth * 2 ) ,
28
- height : Math . round ( slideHeight * 2 ) ,
29
- border : 0
30
- } ;
14
+ var probePage = new WebPage ( ) ;
15
+ var printPage = new WebPage ( ) ;
31
16
32
17
var inputFile = system . args [ 1 ] || 'index.html?print-pdf' ;
33
18
var outputFile = system . args [ 2 ] || 'slides.pdf' ;
@@ -36,13 +21,31 @@ if( outputFile.match( /\.pdf$/gi ) === null ) {
36
21
outputFile += '.pdf' ;
37
22
}
38
23
39
- console . log ( 'Printing PDF (Paper size: ' + page . paperSize . width + 'x' + page . paperSize . height + ')' ) ;
24
+ console . log ( 'Export PDF: Reading reveal.js config [1/3]' ) ;
25
+
26
+ probePage . open ( inputFile , function ( status ) {
27
+
28
+ console . log ( 'Export PDF: Preparing print layout [2/3]' ) ;
29
+
30
+ var config = probePage . evaluate ( function ( ) {
31
+ return Reveal . getConfig ( ) ;
32
+ } ) ;
33
+
34
+ printPage . paperSize = {
35
+ width : config . width * ( 1 + config . margin ) ,
36
+ height : config . height * ( 1 + config . margin ) ,
37
+ border : 0
38
+ } ;
39
+
40
+ printPage . open ( inputFile , function ( status ) {
41
+ window . setTimeout ( function ( ) {
42
+ console . log ( 'Export PDF: Writing file [3/3]' ) ;
43
+ printPage . render ( outputFile ) ;
44
+ console . log ( 'Export PDF: Finished successfully!' ) ;
45
+ phantom . exit ( ) ;
46
+ } , 1000 ) ;
47
+ } ) ;
40
48
41
- page . open ( inputFile , function ( status ) {
42
- window . setTimeout ( function ( ) {
43
- console . log ( 'Printed successfully' ) ;
44
- page . render ( outputFile ) ;
45
- phantom . exit ( ) ;
46
- } , 1000 ) ;
47
49
} ) ;
48
50
51
+
0 commit comments