This is a styled invoice Template jsPDF in an ES module setup.
Includes svg2pdf for better SVG support.
Here there is a demo.
It is primarily for bundling into JS for usage in a browser.
There was this issue which was getting closed. It should work on nodeJS side just without the .html() method. Which is not used here. I did not test it yet.
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 here.
npm run build
npm run devnpm 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/fontssubdirectory. - 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 fetchSvgandnewPageare 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.