print-pdf.js 793 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * phantomjs script for printing presentations to PDF.
  3. *
  4. * Example:
  5. * phantomjs print-pdf.js "http://lab.hakim.se/reveal-js?print-pdf" reveal-demo.pdf
  6. *
  7. * By Manuel Bieh (https://github.com/manuelbieh)
  8. */
  9. // html2pdf.js
  10. var page = new WebPage();
  11. var system = require( 'system' );
  12. page.paperSize = {
  13. format: 'A4',
  14. orientation: 'landscape',
  15. margin: {
  16. left: '0',
  17. right: '0',
  18. top: '0',
  19. bottom: '0'
  20. }
  21. };
  22. page.zoomFactor = 1.5;
  23. var revealFile = system.args[1] || 'index.html?print-pdf';
  24. var slideFile = system.args[2] || 'slides.pdf';
  25. if( slideFile.match( /\.pdf$/gi ) === null ) {
  26. slideFile += '.pdf';
  27. }
  28. console.log( 'Printing PDF...' );
  29. page.open( revealFile, function( status ) {
  30. console.log( 'Printed succesfully' );
  31. page.render( slideFile );
  32. phantom.exit();
  33. } );