1.1.1 โ€ข Published 3 years ago

@solcode/invoice-creator-api-package v1.1.1

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

"Buy Me A Coffee"

๐Ÿงพ Invoice client-side PDF generator

This NPM package takes care of filling the HTML template (handlebars), letting you use the HTML preview, and of course, generating a PDF.

๐Ÿค” Why?

I've written this package due to my need for generating a custom template invoices.

๐Ÿงฐ Installation

Node

npm i @solcode/invoice-creator-api-package

Yarn

yarn add @solcode/invoice-creator-api-package

๐ŸŽฌ Introduction & Usage

This NPM package represents a generator class that consists of 2 main functions.

ActionFunctionParameters
Constructornew Generator()template, data
Fill template with datarenderTemplate()
Download PDF client-sidedownloadPDF()generateRenderedPdf = true

๐Ÿ“ Template

Template is a handlebars (or vanilla HTML5) string, but since the PDF generation is limited in some ways, there are a few additional requirements for the HTML, such as:

  • src attribute of img tags needs to have base64 encoded data instead of URLs (otherwise, images won't load in PDFs)
  • same rule applies for SVGs, they need to be inline

You can use https://www.base64-image.de for converting images to base64 data.

๐Ÿ’ฟ Data

Data is nothing more than a simple JSON object that matches handlebars variables inside of the template. Eg.:

{{ total }} // handlebar variable inside of HTML

// and this would be the JSON
const data = {
    total: 200
}

โžก๏ธ Example

Take a look at this simple example down there.

import Generator from '@solcode/invoice-creator-api-package'

const template = '<p>this is my {{ title }}</p>'
const data = {
    title: 'test'
}

const generatorObject = new Generator(template, data) // returns Generator object
generatorObject.renderTemplate() // renders the template and save it to generator's property renderedTemplate

// if we wanna see preview of html we can get it by
let previewHtml = generatorObject.renderedTemplate
console.log(previewHtml) // we can display it how we want then

generatorObject.downloadPDF() // generates and downloads PDF

๐Ÿ“Ž License

This piece of code is open-source under MIT license.

๐Ÿ›ฃ Roadmap

  • creating template variables standard
  • class abstraction over data json object

๐Ÿ’ป Contributing

If you feel that you have a great idea which could improve this piece of code, fork it, commit your changes and make a pull request, so we can take a look at it, thanks! ๐Ÿ˜Ž

โค๏ธ Feel free to support us

Even that we have our clients, a little support would really help us to speed up free & open-source projects like this.

"Buy Me A Coffee"

BTC Address (3KkrgnJfN8zCGTqWPfjRAKLeUSPD2z79aG)

1.1.1

3 years ago

1.1.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago