Skip to content

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

Notifications You must be signed in to change notification settings

SofianD/invoiceJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Go to form-data-to-pdf to get FileBuffer interface.

getAndSaveInvoice(template, data, path?)

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

let result;

// 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();
// Display:
// [
//   {
//     name: 'Gilbert Montagnard',
//     pathOfsavedFile: 'C:\\Users\\Me\\Documents\\Gilbert-Montagnard1616428271017.pdf'
//   }
// ]

async function main() {
    try {
        result = await invoicejs.getAndSaveInvoice(
            template,
            data,
            {toSaveFiles: 'C:/Users/Me/Documents'}
        );
        console.log(result);
    } catch(error) {
        throw new Error(error);
    }
}

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published