print-pdf.js 830 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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.viewportSize = {
  13. width: 1024,
  14. height: 768
  15. };
  16. page.paperSize = {
  17. format: 'letter',
  18. orientation: 'landscape',
  19. margin: {
  20. left: '0',
  21. right: '0',
  22. top: '0',
  23. bottom: '0'
  24. }
  25. };
  26. var revealFile = system.args[1] || 'index.html?print-pdf';
  27. var slideFile = system.args[2] || 'slides.pdf';
  28. if( slideFile.match( /\.pdf$/gi ) === null ) {
  29. slideFile += '.pdf';
  30. }
  31. console.log( 'Printing PDF...' );
  32. page.open( revealFile, function( status ) {
  33. console.log( 'Printed succesfully' );
  34. page.render( slideFile );
  35. phantom.exit();
  36. } );