]> khamidou — GitHub mirrors - electron.git/commitdiff
Add usage sample code of printToPDF API.
authorHaojian Wu <hokein.wu@gmail.com>
Sat, 20 Jun 2015 07:18:21 +0000 (15:18 +0800)
committerHaojian Wu <hokein.wu@gmail.com>
Sat, 20 Jun 2015 07:18:21 +0000 (15:18 +0800)
docs/api/browser-window.md

index 05cddc7978a79f539404547ec8e8fd13c61aa44f..903abce4062b1e9869bd840dc54c33c33e7e29ea 100644 (file)
@@ -976,10 +976,29 @@ size.
 Prints windows' web page as PDF with Chromium's preview printing custom
 settings.
 
-By default, the options will be
+By default, an empty `options` will be regarded as
 `{marginsType:0, printBackgrounds:false, printSelectionOnly:false,
   landscape:false}`.
 
+```javascript
+var BrowserWindow = require('browser-window');
+var fs = require('fs');
+
+var win = new BrowserWindow({width: 800, height: 600});
+win.loadUrl("http://github.com");
+
+win.webContents.on("did-finish-load", function() {
+  // Use default printing options
+  win.webContents.printToPDF({}, function(error, data) {
+    if (error) throw error;
+    fs.writeFile(dist, data, function(error) {
+      if (err)
+        alert('write pdf file error', error);
+    })
+  })
+});
+```
+
 ### WebContents.send(channel[, args...])
 
 * `channel` String