Merge pull request #2019 from atom/pdf-api-doc

Add usage sample code of printToPDF API.
This commit is contained in:
Cheng Zhao 2015-06-23 10:20:46 +08:00
commit 3519dd96ee

View file

@ -980,10 +980,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