Browse Source

add print

pull/7/head
Cian Butler 4 years ago
parent
commit
11699d40cb
2 changed files with 49 additions and 0 deletions
  1. +48
    -0
      dist/js/print-pdf.js
  2. +1
    -0
      gulpfile.js

+ 48
- 0
dist/js/print-pdf.js View File

@@ -0,0 +1,48 @@
/**
* phantomjs script for printing presentations to PDF.
*
* Example:
* phantomjs print-pdf.js "http://lab.hakim.se/reveal-js?print-pdf" reveal-demo.pdf
*
* By Manuel Bieh (https://github.com/manuelbieh)
*/

// 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 inputFile = system.args[1] || 'index.html?print-pdf';
var outputFile = system.args[2] || 'slides.pdf';

if( outputFile.match( /\.pdf$/gi ) === null ) {
outputFile += '.pdf';
}

console.log( 'Printing PDF (Paper size: '+ page.paperSize.width + 'x' + page.paperSize.height +')' );

page.open( inputFile, function( status ) {
window.setTimeout( function() {
console.log( 'Printed successfully' );
page.render( outputFile );
phantom.exit();
}, 1000 );
} );


+ 1
- 0
gulpfile.js View File

@@ -28,6 +28,7 @@ gulp.task('copy-js', () => {
'./node_modules/reveal.js/lib/js/classList.js',
'./node_modules/reveal.js/plugin/notes/notes.js',
'./node_modules/reveal.js/plugin/notes/notes.html',
'./node_modules/reveal.js/plugin/print-pdf/print-pdf.js',
'./node_modules/reveal.js/plugin/zoom-js/zoom.js',
'./node_modules/reveal.js/plugin/highlight/highlight.js',
'./node_modules/reveal.js/plugin/markdown/markdown.js',


Loading…
Cancel
Save