瀏覽代碼

phantom export throws error if reveal.js isn't present

Hakim El Hattab 7 年之前
父節點
當前提交
fa70a7a517
共有 1 個文件被更改,包括 24 次插入14 次删除
  1. 24 14
      plugin/print-pdf/print-pdf.js

+ 24 - 14
plugin/print-pdf/print-pdf.js

@@ -31,20 +31,30 @@ probePage.open( inputFile, function( status ) {
 		return Reveal.getConfig();
 	} );
 
-	printPage.paperSize = {
-		width: config.width * ( 1 + config.margin ),
-		height: config.height * ( 1 + config.margin ),
-		border: 0
-	};
-
-	printPage.open( inputFile, function( status ) {
-		window.setTimeout( function() {
-			console.log( 'Export PDF: Writing file [3/3]' );
-			printPage.render( outputFile );
-			console.log( 'Export PDF: Finished successfully!' );
-			phantom.exit();
-		}, 1000 );
-	} );
+	if( config ) {
+
+		printPage.paperSize = {
+			width: Math.floor( config.width * ( 1 + config.margin ) ),
+			height: Math.floor( config.height * ( 1 + config.margin ) ),
+			border: 0
+		};
+
+		printPage.open( inputFile, function( status ) {
+			window.setTimeout( function() {
+				console.log( 'Export PDF: Writing file [3/3]' );
+				printPage.render( outputFile );
+				console.log( 'Export PDF: Finished successfully!' );
+				phantom.exit();
+			}, 1000 );
+		} );
+
+	}
+	else {
+
+        console.log( 'Export PDF: Unable to read reveal.js config. Make sure the input address points to a reveal.js page.' );
+        phantom.exit(1);
+
+    }
 
 } );