Browse Source

docs: update webContents.printToPDF() example for promisified API (#21550)

References: https://github.com/electron/electron/pull/16795 https://github.com/electron/electron/pull/17907
trop[bot] 5 years ago
parent
commit
2dc42971ce
1 changed files with 3 additions and 2 deletions
  1. 3 2
      docs/api/web-contents.md

+ 3 - 2
docs/api/web-contents.md

@@ -1323,12 +1323,13 @@ win.loadURL('http://github.com')
 
 win.webContents.on('did-finish-load', () => {
   // Use default printing options
-  win.webContents.printToPDF({}, (error, data) => {
-    if (error) throw error
+  win.webContents.printToPDF({}).then(data => {
     fs.writeFile('/tmp/print.pdf', data, (error) => {
       if (error) throw error
       console.log('Write PDF successfully.')
     })
+  }).catch(error => {
+    console.log(error)
   })
 })
 ```