Add usage sample code of printToPDF API.

This commit is contained in:
Haojian Wu 2015-06-20 15:18:21 +08:00
parent a1cbd11b5b
commit d50db378d7

View file

@ -976,10 +976,29 @@ size.
Prints windows' web page as PDF with Chromium's preview printing custom Prints windows' web page as PDF with Chromium's preview printing custom
settings. settings.
By default, the options will be By default, an empty `options` will be regarded as
`{marginsType:0, printBackgrounds:false, printSelectionOnly:false, `{marginsType:0, printBackgrounds:false, printSelectionOnly:false,
landscape: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...]) ### WebContents.send(channel[, args...])
* `channel` String * `channel` String