json-to-svg-to-pdf
v1.1.0
Published
Converts JSON/CSON input through SVG templates and renders them to PDF using librsvg
Downloads
2
Readme
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.svg
andtemplate/back.svg
with 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 librsvg's
rsvg-convert
being on your path.
To install it on a Mac with homebrew, run brew install
librsvg
.
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