diff options
Diffstat (limited to 'plugin/print-pdf/print-pdf.js')
-rw-r--r-- | plugin/print-pdf/print-pdf.js | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/plugin/print-pdf/print-pdf.js b/plugin/print-pdf/print-pdf.js index d1c3251..f62aedc 100644 --- a/plugin/print-pdf/print-pdf.js +++ b/plugin/print-pdf/print-pdf.js @@ -2,10 +2,11 @@ * phantomjs script for printing presentations to PDF. * * Example: - * phantomjs print-pdf.js "http://lab.hakim.se/reveal-js?print-pdf" reveal-demo.pdf + * phantomjs print-pdf.js "http://revealjs.com?print-pdf" reveal-demo.pdf * * @author Manuel Bieh (https://github.com/manuelbieh) * @author Hakim El Hattab (https://github.com/hakimel) + * @author Manuel Riezebosch (https://github.com/riezebosch) */ // html2pdf.js @@ -21,11 +22,11 @@ if( outputFile.match( /\.pdf$/gi ) === null ) { outputFile += '.pdf'; } -console.log( 'Export PDF: Reading reveal.js config [1/3]' ); +console.log( 'Export PDF: Reading reveal.js config [1/4]' ); probePage.open( inputFile, function( status ) { - console.log( 'Export PDF: Preparing print layout [2/3]' ); + console.log( 'Export PDF: Preparing print layout [2/4]' ); var config = probePage.evaluate( function() { return Reveal.getConfig(); @@ -40,22 +41,27 @@ probePage.open( inputFile, function( status ) { }; printPage.open( inputFile, function( status ) { - window.setTimeout( function() { - console.log( 'Export PDF: Writing file [3/3]' ); + console.log( 'Export PDF: Preparing pdf [3/4]') + printPage.evaluate( function() { + Reveal.isReady() ? window.callPhantom() : Reveal.addEventListener( 'pdf-ready', window.callPhantom ); + } ); + } ); + + printPage.onCallback = function( data ) { + // For some reason we need to "jump the queue" for syntax highlighting to work. + // See: http://stackoverflow.com/a/3580132/129269 + setTimeout( function() { + console.log( 'Export PDF: Writing file [4/4]' ); printPage.render( outputFile ); console.log( 'Export PDF: Finished successfully!' ); phantom.exit(); - }, 1000 ); - } ); - + }, 0 ); + }; } else { - console.log( 'Export PDF: Unable to read reveal.js config. Make sure the input address points to a reveal.js page.' ); - phantom.exit(1); - - } + console.log( 'Export PDF: Unable to read reveal.js config. Make sure the input address points to a reveal.js page.' ); + phantom.exit( 1 ); + } } ); - - |