Open JohnSalard opened 5 years ago
please specify where you want to store the data.If you want to store it on some cloud storage service like s3,you can follow @Aathi instructions.If you want to save it to local storage,do something like this
const pdf = require('html-pdf');
var options = { format: 'Letter' };
pdf.create(html, options).toFile('./businesscard.pdf', function(err, res) { if (err) return console.log(err); console.log(res); // { filename: '/app/businesscard.pdf' } });
here html is the html string you want to convert to pdf.you can use @Aathi answer to generate a html string with your own params
@Aathi in your example you define with one parameter
htmlTemplate = (params)
but you call it with 3
htmlTemplate(order, allSupplierProducts, customer)
How that works?
@Serhioromano It should be
htmlTemplate({ order, allSupplierProducts, customer })
@Serhioromano , sorry it was my bad. it was a quick example so I didn't notice. it has been updated now. or you could do like how @deepansh946 has suggested, pass as an object to the respective function and destructure it
@Aathi suggestion of @deepansh946 is not valid JS
htmlTemplate({ order, allSupplierProducts, customer })
There is no such syntax for objects.
Also in your code, you create
const htmlTemplate = require('./templates/supplierOrderListTemplet')
and then you define this constant again after options.
@Serhioromano You can check this sandbox: https://codesandbox.io/s/javascript-nscdr
@Serhioromano Please check this es6 basic destructuring assignment syntax is a JavaScript in order to understand how it works. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
https://hacks.mozilla.org/2015/05/es6-in-depth-destructuring/
https://codeburst.io/es6-destructuring-the-complete-guide-7f842d08b98f
I see. ES6.
@JohnSalard You could do something like this