npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

svg4pdf-lib

v0.1.1

Published

Insert SVG into a PDF document created with @pdfme/pdf-lib. Built on top of svg-for-pdfkit.

Readme

svg4pdf-lib

Insert SVG into a PDF document created with @pdfme/pdf-lib (a maintained fork of the original pdf-lib).

This package is an adapter for svg-for-pdfkit, a community-maintained fork of the excellent SVG-to-PDFKit by alafr. svg-for-pdfkit handles SVG parsing, property inheritance, transforms, markers, gradients, patterns, masks, and text; svg4pdf-lib translates its PDFKit-style drawing calls into @pdfme/pdf-lib vector operators.

The adapter configures svg-for-pdfkit with flipYAxis: true and negateTextMatrix: true so that the emitted PDF operators match @pdfme/pdf-lib's coordinate system and text-matrix convention.

Install

npm install svg4pdf-lib @pdfme/pdf-lib

@pdfme/pdf-lib is a peer dependency. svg-for-pdfkit is included as a runtime dependency and does not pull in PDFKit.

Usage

import {PDFDocument} from "@pdfme/pdf-lib"
import {drawSvg} from "svg4pdf-lib"

const pdfDoc = await PDFDocument.create()
const page = pdfDoc.addPage([612, 792])

const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
  <circle cx="50" cy="50" r="40" fill="red" stroke="black" stroke-width="2"/>
</svg>`

drawSvg(page, svg, 100, 100, {
  width: 200,
  height: 200,
  fontCallback: (family, bold, italic) => {
    // Return an already-embedded PDFFont for the requested family/style.
    return myEmbeddedFonts[family]
  }
})

const bytes = await pdfDoc.save()

API

drawSvg(page, svg, x, y, options?)

  • page — a @pdfme/pdf-lib PDFPage.
  • svg — SVG markup as a string.
  • x, y — position on the PDF page (pt), origin bottom-left.
  • options — optional:
    • width, height — desired size in pt. Aspect ratio is preserved by default.
    • preserveAspectRatio — same syntax as SVG (xMidYMid meet, etc.).
    • fontCallback(family, bold, italic, options) — returns a PDFFont for the requested face. Called for every <text> element.
    • warningCallback(message) — receives non-fatal warnings.
    • cmyk — when true, convert named colors and default paints to CMYK (0-1). Also enables SVG cmyk(c,m,y,k) color syntax.
    • colorCallback(color, raw) — transform or replace parsed SVG colors before they are applied. Useful for custom spot-color handling.

Coverage

Inherited from svg-for-pdfkit:

  • Shape elements: rect, circle, ellipse, line, polyline, polygon, path.
  • Text: text, tspan, textPath (with text-anchor, dominant-baseline, etc.).
  • Structure: g, svg, defs, use, symbol, a.
  • Effects: marker, clipPath, mask, transforms, opacity, fill/stroke styling, dash patterns.
  • Paint servers: linear/radial gradients and patterns (tiling patterns via Form XObjects), including per-stop alpha via soft masks.
  • CMYK colors: named colors, cmyk(c,m,y,k) CSS syntax, and CMYK gradients when options.cmyk is enabled.
  • Raster images: <image> elements referencing base64 data:image/png or data:image/jpeg URIs.

Limitations:

  • Remote image URLs are not fetched; provide base64 data URIs or pre-resolve images through options.imageCallback.
  • Spot colors (Separation colorspaces) are not rendered automatically. Use options.colorCallback to map spot-color names to concrete RGB/CMYK values.

License

LGPL-3.0-or-later. See LICENSE. This package is derived from SVG-to-PDFKit and svg-for-pdfkit; the upstream code remains available under the MIT License reproduced in the LICENSE file.