Open Julix91 opened 4 years ago
Hi @Julix91 ,
Your code helped me get the save-to-pdf functionality working. How did you know to rewrite it in this way? From your post, it sounds like what you did was replace "the callback way of doing it with a promise way". Why did the callback way fail and the promise way succeed?
index.js
// FUNCTION TO SAVE CURRENT WINDOW TO PDF (PER elementary-electron)
// function save () {
// alert('save function called')
// remote.getCurrentWebContents().printToPDF({
// portrait: true
// }, function (err, data){
// alert('callback function called')
// fs.writeFile('annotation.pdf', data, function (err){
// if (err) alert('error generating pdf! ' + err.message)
// else alert('pdf saved!')
// })
// })
// }
// FUNCTION TO SAVE CURRENT WINDOW TO PDF (PER Julix91)
function save () {
remote.getCurrentWebContents().printToPDF({portrait: true})
.then( data => {
fs.writeFile('annotation.pdf', data, function (err) {
if (err) {
alert('error generating pdf! ' + err.message) ;
} else {
alert('pdf saved!') ;
}
})
})
.catch ( err => {
console.log('test');
})
}
Don't know, it's been a while... sorry.
On Wed., Jun. 10, 2020, 05:24 Nick Smedira, notifications@github.com wrote:
Hi @Julix91 https://github.com/Julix91 ,
Your code helped me get the save-to-pdf functionality working. How did you know to rewrite it in this way? From your post, it sounds like what you did was replace "the callback way of doing it with a promise way". Why did the callback way fail and the promise way succeed?
index.js
// FUNCTION TO SAVE CURRENT WINDOW TO PDF (PER elementary-electron) // function save () { // alert('save function called') // remote.getCurrentWebContents().printToPDF({ // portrait: true // }, function (err, data){ // alert('callback function called') // fs.writeFile('annotation.pdf', data, function (err){ // if (err) alert('error generating pdf! ' + err.message) // else alert('pdf saved!') // }) // }) // }
// FUNCTION TO SAVE CURRENT WINDOW TO PDF (PER Julix91) function save () { remote.getCurrentWebContents().printToPDF({portrait: true}) .then( data => { fs.writeFile('annotation.pdf', data, function (err) { if (err) { alert('error generating pdf! ' + err.message) ; } else { alert('pdf saved!') ; } }) }) .catch ( err => { console.log('test'); }) }
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/maxogden/elementary-electron/issues/36#issuecomment-641968364, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADCH3Z36ZOQM7NPO22XTQELRV53PZANCNFSM4KR5X6AQ .
I had issues every step of the way. Needed to add node support to app.js and made changes to index.js too. I don't know why replacing the callback way of doing it with a promise way worked, but with the following code getting the cat pic, annotating and printing on 'p' press all work.
However, still getting error messages in the console, similar to https://github.com/maxogden/elementary-electron/issues/32
Tracked them to here: https://github.com/visionmedia/superagent/issues/676 https://github.com/visionmedia/superagent/issues/714
but I couldn't figure out where it's being included from to test if upgrading the version fixes it or such.
app.js
index.js