Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined for invoice.getInvoice().toPDF().toBuffer() #45

Closed
vishvendrasingh opened this issue May 20, 2020 · 7 comments
Closed

undefined for invoice.getInvoice().toPDF().toBuffer() #45

vishvendrasingh opened this issue May 20, 2020 · 7 comments

Comments

@vishvendrasingh
Copy link

unable to create buffer

`const invoiceIt = require('@rimiti/invoice-it').default;

const recipient = {
company_name: 'Receiver company',
first_name: 'Will',
last_name: 'Jameson',
street_number: '20',
street_name: 'Rue Victor Hugo',
zip_code: '77340',
city: 'Pontault-Combault',
country: 'France',
phone: '06 00 00 00 00',
mail: '[email protected]'
};

const emitter = {
name: 'Dim Solution',
street_number: '15',
street_name: 'Rue Jean Jaures',
zip_code: '75012',
city: 'Paris',
country: 'France',
phone: '01 00 00 00 00',
mail: '[email protected]',
website: 'www.dimsolution.com'
};

const invoice = invoiceIt.create(recipient, emitter);
const pdf = invoice.getInvoice().toPDF().toBuffer()
const pdf = invoice.getInvoice().toPDF()
// .toFile('./invoice.pdf')
// .then((r) => {
// console.log('PDF file created.',r);
// });
console.log(pdf)`

@rimiti
Copy link
Owner

rimiti commented May 20, 2020

Oh! Can you create a PR to fix that ?

@vishvendrasingh
Copy link
Author

sure @rimiti will do. One more question is there any option to update table_information?

@vishvendrasingh
Copy link
Author

below generates the buffer, please tell me in which file do you want me to place this code?

const HtmlPDF = require('html-pdf'); await new Promise((resolve, reject) => { HtmlPDF.create(html).toBuffer(function(err, buffer){ resolve(buffer) } ) }

@diffusi-on
Copy link
Contributor

What about fix?

@diffusi-on
Copy link
Contributor

diffusi-on commented May 26, 2020

Fix please

src/generator.js

_toBufferFromPDF(content) { return content.toBuffer((err, buffer) => { if (err) throw new Error(err); return buffer; }); }

Should be replaced to

_toBufferFromPDF(content) { return new Promise((resolve, reject) => content.toBuffer((err, buffer) => { if (err) return reject(err); return resolve(buffer); })); }

@diffusi-on
Copy link
Contributor

@rimiti

PR for this fix #46

@rimiti
Copy link
Owner

rimiti commented May 27, 2020

Thanks for you contribution. It has been released.

🙏

@rimiti rimiti closed this as completed May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants