marcbachmann / node-html-pdf

This repo isn't maintained anymore as phantomjs got dreprecated a long time ago. Please migrate to headless chrome/puppeteer.
MIT License
3.56k stars 545 forks source link

html-pdf TypeError: callback is not a function #584

Open axelFrau opened 4 years ago

axelFrau commented 4 years ago

I was following a tutorial on how to use your npm package :

the tutorial url :

https://medium.com/@saumya.ranjan/how-to-generate-pdf-in-nodejs-ejs-and-html-pdf-81a9a154d22d#:~:text=report-template.ejs,-step-6&text=Go%20to%20new%20tab%20and,response%20as%20File%20created%20successfully

and when i'm sending my request to lauch the process, this the error i get which comes right from you node module could you tell me if anyone had the same issues ? my code is the same as the one in the tutorial.

-- Edit : Found out that the problem occurs for this call : the toFIle() crashes and causes the error : pdf.create(data, options).toFile(__root, "generatePDF/report.pdf", function (err, data) { console.log("in toFile :", data); if (err) { console.log("error : ", err); res.send(err); } else { res.send("File created successfully"); } });

` /Users/axel/Documents/CMF/cmf/cmf_server/node_modules/html-pdf/lib/pdf.js:128 console.log('callback : ',callback(null, data)); ^

TypeError: callback is not a function at respond (/Users/axel/Documents/CMF/cmf/cmf_server/node_modules/html-pdf/lib/pdf.js:128:31) at Socket.onData (/Users/axel/Documents/CMF/cmf/cmf_server/node_modules/html-pdf/lib/pdf.js:108:17) at Socket.emit (events.js:203:13) at addChunk (_stream_readable.js:295:12) at readableAddChunk (_stream_readable.js:276:11) at Socket.Readable.push (_stream_readable.js:210:10) at Pipe.onStreamRead (internal/stream_base_commons.js:166:17) `

anttitakalahti commented 3 years ago

https://github.com/marcbachmann/node-html-pdf#api

The signature of toFile is: toFile(filepath, function callback(err, res) {})

so your __root is extra there and "generatePDF/report.pdf" is in the place of callback which causes the problem you are seeing.

ayoubgm commented 3 years ago

You use three arguments instead of two toFile(filename?: string, callback?: (err: Error, res: FileInfo) => void): void.