Node.js Express Easy Payment PDF Invoice Generator in Javascript After Online Payment Using EasyInvoice Library Tutorial 2020

Node.js Express Easy Payment PDF Invoice Generator in Javascript After Online Payment Using EasyInvoice Library Tutorial 2020

 

 

 

 

 

Installing

 

 

npm i easyinvoice

 

 

Using CDN

 

 

<script src="https://unpkg.com/easyinvoice/dist/easyinvoice.min.js"></script>

 

 

 

Example 1 Generating PDF as Base64 in command line

 

 

//Import the library into your project
var easyinvoice = require('easyinvoice');
 
var data = {
    //"documentTitle": "RECEIPT", //Defaults to INVOICE
    "currency": "USD",
    "taxNotation": "vat", //or gst
    "marginTop": 25,
    "marginRight": 25,
    "marginLeft": 25,
    "marginBottom": 25,
    "logo": "https://www.easyinvoice.cloud/img/logo.png", //or base64
    //"logoExtension": "png", //only when logo is base64
    "sender": {
        "company": "Sample Corp",
        "address": "Sample Street 123",
        "zip": "1234 AB",
        "city": "Sampletown",
        "country": "Samplecountry"
        //"custom1": "custom value 1",
        //"custom2": "custom value 2",
        //"custom3": "custom value 3"
    },
    "client": {
        "company": "Client Corp",
        "address": "Clientstreet 456",
        "zip": "4567 CD",
        "city": "Clientcity",
        "country": "Clientcountry"
        //"custom1": "custom value 1",
        //"custom2": "custom value 2",
        //"custom3": "custom value 3"
    },
    "invoiceNumber": "2020.0001",
    "invoiceDate": "05-01-2020",
    "products": [
        {
            "quantity": "2",
            "description": "Test1",
            "tax": 6,
            "price": 33.87
        },
        {
            "quantity": "4",
            "description": "Test2",
            "tax": 21,
            "price": 10.45
        }
    ],
    "bottomNotice": "Kindly pay your invoice within 15 days."
};
 
//Create your invoice! Easy!
easyinvoice.createInvoice(data, function (result) {
    //The response will contain a base64 encoded PDF file
    console.log(result.pdf);
});

 

See also  Build a Image to Binary or Hexadecimal Codes Converter in Browser Using HTML5 CSS3 and Javascript Full Project For Beginners

 

 

 

 

 

To Store PDF File Locally in Node.js

 

 

var fs = require('fs');
 
const data = {};
const result = await easyinvoice.createInvoice(data);                       
await fs.writeFileSync("invoice.pdf", result.pdf, 'base64');

 

 

Download your PDF Invoice

 

 

const data = {};
easyinvoice.createInvoice(data, function (result) {
    easyinvoice.download('myInvoice.pdf', result.pdf);
    //  you can download like this as well:
    //  easyinvoice.download();
    //  easyinvoice.download('myInvoice.pdf');   
});

 

 

 

 

 

 

 

 

 

Leave a Reply