This a styled invoice Template jsPDF in an ES6 / ECMAScript webpack setup.
Includes svg2pdf for better SVG support.
Here there is a demo.
npm install
If you want the usable node package, you can install it via npm:
npm i jspdf-invoice -S
it is here https://www.npmjs.com/package/jspdf-invoice
Creates a bundle JS file which provides the global method printPDF()
.
For demonstration a docs GitHub page is build.
npm run build
npm run dev
npm run serve
Is done via GitHub action.
- raise version in
dist/package.json
A copy of the src dir is taken as artifact for the node package in the dist dir.
I do use a custom font here. Which is prepared as base64 code like following: https://github.com/parallax/jsPDF#use-of-unicode-characters--utf-8
- My custom fonts are laying as .ttf font-files in
src/fonts
subdirectory. - prepared JS script with the font's base64 code are in
src/print/fonts
- they got a
import { jsPDF } from 'jspdf';
added at the very top
- Print components or template partials are placed in
src/print/partials
fetchSvg
andnewPage
are tools placed insrc/print/utils
Images need to be SVG in here!
- Logo Size: width="40" height="49"
- Address-bar: width="668" height="56", which is scaled down to keep details
- Background: width="733" height="528", which is centralised and hangs a bit over the edges
- SVG should be SVGO (e.g. https://jakearchibald.github.io/svgomg/ or configure a SVGO export in sketch sketch SVGO export plugin like this sketch-hq/svgo-compressor#20 (comment)) optimized. So some attributes not working for rendering are removed.
- currently using localStorage to save the background graphic globally for synchronous usage. Might not be the best idea.