print-pdf.js 743 B

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