json-to-svg-to-pdf
This is a silly module we wrote to generate business cards. As a result, consider this module very YMMV. (Spoiler alert: the code is intentionally dense for use as a refactoring exercise.)
To use this yourself:
- Define two SVG templates in
template/front.svgandtemplate/back.svgwith whatever mustache template strings you like (e.g.{{fullName}}) - Create a JSON/CSON for each person in
input/(e.g.input/justin.cson) that defines those mustache attribute names - Run
json-to-svg-to-pdf
What you'll get is, for each input file, a pair of font-embedded PDFs in
output/ (e.g.
output/justin-front.pdf and output/justin-back.pdf).
Prerequisites
The PDF generation relies on Inkscape's inkscape
binary being on your path.
To install it on a Mac with Homebrew and
Homebrew Cask, run
brew cask install xquartz inkscape.
TODO
The glaring limitation currently is the code assumes you have exactly two templates defined for each input. It could be complicated/improved to discover 1…n templates and follow the same naming pattern