ソースを参照

merge in phantomjs script for printing pdf (#276)

Hakim El Hattab 12 年 前
コミット
17622052a0
1 ファイル変更38 行追加0 行削除
  1. 38 0
      plugin/print-pdf/print-pdf.js

+ 38 - 0
plugin/print-pdf/print-pdf.js

@@ -0,0 +1,38 @@
+/**
+ * phantomjs script for printing presentations to PDF.
+ *
+ * Example:
+ *
+ * phantomjs print-pdf.js "http://lab.hakim.se/reveal-js?print-pdf" reveal-demo.pdf
+ */
+
+// html2pdf.js
+var page = new WebPage();
+var system = require( 'system' );
+
+page.paperSize = {
+	format: 'A4',
+	orientation: 'landscape',
+	margin: {
+		left: '0',
+		right: '0',
+		top: '0',
+		bottom: '0'
+	}
+};
+page.zoomFactor = 1.5;
+
+var revealFile = system.args[1] || 'index.html?print-pdf';
+var slideFile = system.args[2] || 'slides.pdf';
+
+if( slideFile.match( /\.pdf$/gi ) === null ) {
+	slideFile += '.pdf';
+}
+
+console.log( 'Printing PDF...' );
+
+page.open( revealFile, function( status ) {
+	console.log( 'Printed succesfully' );
+	page.render( slideFile );
+	phantom.exit();
+} );