If this package helped you out please star us on Github!
Much appreciated!
Platform | Repository | Supported | Link |
---|---|---|---|
PHP | Composer | Yes! | |
Javascript | NPM | Yes! | |
Python | PIP | Yes! | |
Java | Maven | In progress... |
JS Fiddle: Plain Javascript
JS Fiddle: Vue
JS Fiddle: React
JS Fiddle: Angular
Read our step-by-step guide on Medium. Click here!
Using npm:
$ npm install easyinvoice --save
Using yarn:
$ yarn add easyinvoice
Using unkpg CDN:
<script src="https://unpkg.com/easyinvoice/dist/easyinvoice.min.js"></script>
Using jsDelivr CDN:
<script src="https://cdn.jsdelivr.net/npm/easyinvoice/dist/easyinvoice.min.js"></script>
Html
<script src="https://unpkg.com/easyinvoice/dist/easyinvoice.min.js"></script>
NodeJS
var easyinvoice = require('easyinvoice');
Vue/React
import easyinvoice from 'easyinvoice';
Angular
import * as easyinvoice from 'easyinvoice';
//ór (not both)
import { easyinvoice } from 'easyinvoice';
//Import the library into your project
var easyinvoice = require('easyinvoice');
var data = {
//"documentTitle": "RECEIPT", //Defaults to INVOICE
//"locale": "de-DE", //Defaults to en-US, used for number formatting (see docs)
"currency": "USD", //See documentation 'Locales and Currency' for more info
"taxNotation": "vat", //or gst
"marginTop": 25,
"marginRight": 25,
"marginLeft": 25,
"marginBottom": 25,
"logo": "https://public.easyinvoice.cloud/img/logo_en_original.png", //or base64
"background": "https://public.easyinvoice.cloud/img/watermark-draft.jpg", //or base64 //img or pdf
"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": "2021.0001",
"invoiceDate": "1.1.2021",
"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.",
//Used for translating the headers to your preferred language
//Defaults to English. Below example is translated to Dutch
// "translate": {
// "invoiceNumber": "Factuurnummer",
// "invoiceDate": "Factuurdatum",
// "products": "Producten",
// "quantity": "Aantal",
// "price": "Prijs",
// "subtotal": "Subtotaal",
// "total": "Totaal"
// }
};
//Create your invoice! Easy!
easyinvoice.createInvoice(data, function (result) {
//The response will contain a base64 encoded PDF file
console.log(result.pdf);
});
Used for number formatting and the currency symbol:
//E.g. for Germany, prices would look like 123.456,78 €
const data = { locale: 'de-DE', currency: 'EUR'};
//E.g. for US, prices would look like $123,456.78
const data = { locale: 'en-US', currency: 'USD'};
Formatting and symbols are applied through the ECMAScript Internationalization API
Click here for a list of locale codes
Click here for a list of currency codes
Disclaimer: Not all locales and currency codes found in the above lists might be supported by the ECMAScript Internationalization API.
The logo and url inputs accept either a URL or a base64 encoded file.
Supported file types:
- Logo: image
- Background: image, pdf
const data = {
logo: "https://public.easyinvoice.cloud/img/logo_en_original.png",
background: "https://public.easyinvoice.cloud/img/watermark_draft.jpg",
};
const data = {
//Note: Sample base64 string
//Please use the link below to convert your image to base64
logo: "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==",
background: "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
};
//Import fs to be able to read from the local file system
var fs = require("fs");
//Use the code below to read your local file as a base64 string
const data = {
logo: fs.readFileSync('logo.png', 'base64'),
background: fs.readFileSync('images/background.png', 'base64')
};
Click here for an online tool to convert an image to base64
const result = await easyinvoice.createInvoice(data);
console.log(result.pdf);
var fs = require('fs');
const data = {};
const result = await easyinvoice.createInvoice(data);
await fs.writeFileSync("invoice.pdf", result.pdf, 'base64');
Using callback
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');
});
Using async/await
const data = {};
const result = await easyinvoice.createInvoice(data);
easyinvoice.download('myInvoice.pdf', result.pdf);
// you can download like this as well:
// easyinvoice.download();
// easyinvoice.download('myInvoice.pdf');
html
<!-- Only include when rendering is required -->
<script src="https://unpkg.com/pdfjs-dist/build/pdf.min.js"></script>
<script src="https://unpkg.com/pdfjs-dist/build/pdf.worker.min.js"></script>
<!-- Include pdfjs version 2.3.200 for Internet Explorer compatibility, no worker required -->
<!-- <script src="https://unpkg.com/[email protected]/build/pdf.min.js"></script> -->
<!-- The pdf will be rendered within this div -->
<div id="pdf"></div>
css (optional)
#pdf {
text-align: center;
}
#pdf canvas {
border: 1px solid black;
width: 95%;
}
js: Using Callback
var data = {};
var elementId = 'pdf';
easyinvoice.createInvoice(data, function(result) {
easyinvoice.render(elementId, result.pdf, function(){
console.log('Invoice rendered!');
});
});
js: Using async/await
const data = {};
const elementId = 'pdf';
const result = await easyinvoice.createInvoice(data);
await easyinvoice.render(elementId, result.pdf);
You could view your base64 pdf through the following website: https://base64.guru/converter/decode/pdf
Paste the base64 string and click 'Decode Base64 to PDF'.