From 5da75aef01a16f694632c377d47d6d0518fbb8c5 Mon Sep 17 00:00:00 2001 From: Ian Smith Date: Sun, 27 Dec 2015 12:35:13 -0600 Subject: Fix spelling error in print-pdf plugin --- plugin/print-pdf/print-pdf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugin/print-pdf/print-pdf.js') diff --git a/plugin/print-pdf/print-pdf.js b/plugin/print-pdf/print-pdf.js index 86dc4df..38a698d 100644 --- a/plugin/print-pdf/print-pdf.js +++ b/plugin/print-pdf/print-pdf.js @@ -40,7 +40,7 @@ console.log( 'Printing PDF (Paper size: '+ page.paperSize.width + 'x' + page.pap page.open( inputFile, function( status ) { window.setTimeout( function() { - console.log( 'Printed succesfully' ); + console.log( 'Printed successfully' ); page.render( outputFile ); phantom.exit(); }, 1000 ); -- cgit v1.2.3 From a349ff43c58c23f9c837b8ea9b5fc7d4761b8de3 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Wed, 15 Feb 2017 11:18:54 +0100 Subject: new phantom pdf export script that works with 3.4.0 #1815 --- plugin/print-pdf/print-pdf.js | 55 +++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 26 deletions(-) (limited to 'plugin/print-pdf/print-pdf.js') diff --git a/plugin/print-pdf/print-pdf.js b/plugin/print-pdf/print-pdf.js index 38a698d..c3c5d94 100644 --- a/plugin/print-pdf/print-pdf.js +++ b/plugin/print-pdf/print-pdf.js @@ -4,30 +4,15 @@ * Example: * phantomjs print-pdf.js "http://lab.hakim.se/reveal-js?print-pdf" reveal-demo.pdf * - * By Manuel Bieh (https://github.com/manuelbieh) + * @author Manuel Bieh (https://github.com/manuelbieh) + * @author Hakim El Hattab (https://github.com/hakimel) */ // html2pdf.js -var page = new WebPage(); var system = require( 'system' ); -var slideWidth = system.args[3] ? system.args[3].split( 'x' )[0] : 960; -var slideHeight = system.args[3] ? system.args[3].split( 'x' )[1] : 700; - -page.viewportSize = { - width: slideWidth, - height: slideHeight -}; - -// TODO -// Something is wrong with these config values. An input -// paper width of 1920px actually results in a 756px wide -// PDF. -page.paperSize = { - width: Math.round( slideWidth * 2 ), - height: Math.round( slideHeight * 2 ), - border: 0 -}; +var probePage = new WebPage(); +var printPage = new WebPage(); var inputFile = system.args[1] || 'index.html?print-pdf'; var outputFile = system.args[2] || 'slides.pdf'; @@ -36,13 +21,31 @@ if( outputFile.match( /\.pdf$/gi ) === null ) { outputFile += '.pdf'; } -console.log( 'Printing PDF (Paper size: '+ page.paperSize.width + 'x' + page.paperSize.height +')' ); +console.log( 'Export PDF: Reading reveal.js config [1/3]' ); + +probePage.open( inputFile, function( status ) { + + console.log( 'Export PDF: Preparing print layout [2/3]' ); + + var config = probePage.evaluate( function() { + return Reveal.getConfig(); + } ); + + printPage.paperSize = { + width: config.width * ( 1 + config.margin ), + height: config.height * ( 1 + config.margin ), + border: 0 + }; + + printPage.open( inputFile, function( status ) { + window.setTimeout( function() { + console.log( 'Export PDF: Writing file [3/3]' ); + printPage.render( outputFile ); + console.log( 'Export PDF: Finished successfully!' ); + phantom.exit(); + }, 1000 ); + } ); -page.open( inputFile, function( status ) { - window.setTimeout( function() { - console.log( 'Printed successfully' ); - page.render( outputFile ); - phantom.exit(); - }, 1000 ); } ); + -- cgit v1.2.3 From fa70a7a5174b16b1b4e9ccaf3f36cbb082cc8051 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Wed, 15 Feb 2017 11:43:57 +0100 Subject: phantom export throws error if reveal.js isn't present --- plugin/print-pdf/print-pdf.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'plugin/print-pdf/print-pdf.js') diff --git a/plugin/print-pdf/print-pdf.js b/plugin/print-pdf/print-pdf.js index c3c5d94..d1c3251 100644 --- a/plugin/print-pdf/print-pdf.js +++ b/plugin/print-pdf/print-pdf.js @@ -31,20 +31,30 @@ probePage.open( inputFile, function( status ) { return Reveal.getConfig(); } ); - printPage.paperSize = { - width: config.width * ( 1 + config.margin ), - height: config.height * ( 1 + config.margin ), - border: 0 - }; - - printPage.open( inputFile, function( status ) { - window.setTimeout( function() { - console.log( 'Export PDF: Writing file [3/3]' ); - printPage.render( outputFile ); - console.log( 'Export PDF: Finished successfully!' ); - phantom.exit(); - }, 1000 ); - } ); + if( config ) { + + printPage.paperSize = { + width: Math.floor( config.width * ( 1 + config.margin ) ), + height: Math.floor( config.height * ( 1 + config.margin ) ), + border: 0 + }; + + printPage.open( inputFile, function( status ) { + window.setTimeout( function() { + console.log( 'Export PDF: Writing file [3/3]' ); + printPage.render( outputFile ); + console.log( 'Export PDF: Finished successfully!' ); + phantom.exit(); + }, 1000 ); + } ); + + } + 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); + + } } ); -- cgit v1.2.3 From 9a7c7ce93a530cfb8bb85e0670b1ffd171ccbba4 Mon Sep 17 00:00:00 2001 From: Manuel Riezebosch Date: Tue, 14 Mar 2017 14:13:24 +0100 Subject: print-pdf using callback iso timer Use window.callPhantom icw page. onCallback to wait for pdf-ready event. From: http://stackoverflow.com/a/28925479/129269 --- plugin/print-pdf/print-pdf.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'plugin/print-pdf/print-pdf.js') diff --git a/plugin/print-pdf/print-pdf.js b/plugin/print-pdf/print-pdf.js index d1c3251..9ffc261 100644 --- a/plugin/print-pdf/print-pdf.js +++ b/plugin/print-pdf/print-pdf.js @@ -6,6 +6,7 @@ * * @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,14 +41,22 @@ 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 { @@ -55,7 +64,6 @@ probePage.open( inputFile, function( status ) { phantom.exit(1); } - } ); -- cgit v1.2.3