Insert SVG into a PDF document. This repository holds two independent packages that convert the same SVG feature set to two different PDF backends.
| Package | Backend | Use it with |
|---|---|---|
svg-for-pdfkit |
PDFKit | SVGtoPDF(doc, svg, x, y, options) |
svg4pdf-lib |
@pdfme/pdf-lib |
drawSvg(page, svg, x, y, options) |
svg-for-pdfkit is a maintained fork of
SVG-to-PDFKit by
alafr. svg4pdf-lib does not depend on it and does
not use PDFKit: it emits pdf-lib operators directly, in a single conversion
pass. See each package's README for its API, supported features and
limitations.
packages/svg-for-pdfkit/ plain-JS SVG → PDFKit converter (+ examples, notes)
packages/svg4pdf-lib/ TypeScript SVG → pdf-lib converter
The two packages are versioned and released independently; changes to one do not require a release of the other.
This is a pnpm workspace.
pnpm install
pnpm build # both packages
pnpm test # both packagesTo work on a single package:
pnpm --filter svg4pdf-lib build
pnpm --filter svg4pdf-lib test
pnpm --filter svg4pdf-lib test:watchsvg-for-pdfkit is plain JavaScript, so its build script only prints a notice;
its test script runs scripts/smoke.mjs, which generates a PDF with PDFKit.
Each package is published on its own, so a release is always done from inside that package's directory.
To release one package:
cd packages/svg4pdf-lib # or packages/svg-for-pdfkit
# 1. set the new version in package.json
# 2. publish
pnpm publish
# 3. back in the repo root, record the release
git commit -am "svg4pdf-lib 0.2.0"
git tag svg4pdf-lib@0.2.0
git push origin main --tagsTo release both, do this once per package, each with its own version.
That is all there is to it: pnpm publish builds svg4pdf-lib first (via its
prepack script), and svg-for-pdfkit needs no build step.
A few things worth knowing:
- You must be logged in to npm; run
npm loginifnpm whoamireportsE401. - Preview what will be uploaded with
pnpm publish --dry-run. The version must be higher than what is already published, otherwise the publish is refused. - Tag with the package name (
svg4pdf-lib@0.2.0). Unprefixed tags such as0.1.18predate the split into two packages and are ambiguous.
LGPL-3.0-or-later. The original SVG-to-PDFKit code remains available under the
MIT License, reproduced in each package's LICENSE file.