0.0.2 • Published 4 years ago

@sofiand/invoice v0.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

InvoiceJS

This package compiles HTML documents with the corresponding data to save them as PDF files.

Installation

$ npm i @sofiand/invoice

Usage

Go to zup to know how templates work.

getAndSaveInvoice(template: string, data: any[], path?: dataToPDF.Path): Promise[dataToPDF.FileBuffer[]](https://github.com/SofianD/from-data-to-pdf#FileBuffer)

const invoicejs = require('@sofiand/invoice');

// template is the converted template as string.
const template = '<html>...';

// data is a list where each element contains the information required by template.
const data = [
    {
        lastname: 'Gilbert',
        firstname: 'Montagnard',
        adress: 'Somewhere',
        params: [
            {
                name: 'premier param',
                value: 'première valeur'
            },
            {
                name: 'second param',
                value: 'seconde valeur'
            }
        ]
    }
];

main();

async function main() {
    try {
        const response = await invoicejs.getAndSaveInvoice(template, data, {toSaveFiles: 'C:/Users/Me/Documents'});
        console.log(response);
        // Display:
        // [
        //   {
        //     name: 'Gilbert Montagnard',
        //     pathOfsavedFile: 'C:\\Users\\Me\\Documents\\Gilbert-Montagnard1616428271017.pdf'
        //   }
        // ]
    } catch(error) {
        throw new Error(error);
    }
}