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.2.0

Published

Insert SVG into a PDF document created with @pdfme/pdf-lib. Converts SVG directly to pdf-lib operators.

Readme

svg4pdf-lib

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

svg4pdf-lib walks the SVG tree and emits @pdfme/pdf-lib operators and PDF objects directly. There is no intermediate PDF-instruction layer: paths, paints, transparency groups, shadings, patterns, text and images all become pdf-lib calls in a single pass.

Install

npm install svg4pdf-lib @pdfme/pdf-lib

@pdfme/pdf-lib is a peer dependency, so you control its version. @pdf-lib/upng is pulled in for PNG decoding; PDFKit is not a dependency.

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 — top-left corner of the drawing area on the PDF page (pt).
  • options — optional:
    • width, height — desired size in pt (defaults to the page size).
    • preserveAspectRatio — same syntax as SVG (xMidYMid meet, etc.).
    • fontCallback(family, bold, italic, options) — returns an embedded PDFFont for the requested face. Called for every <text> element; return undefined to skip the text.
    • warningCallback(message) — receives non-fatal warnings.
    • imageCallback(link) — transform an <image> href into the source handed to the image loader.
    • cmyk — when true, convert named colors and default paints to CMYK. SVG cmyk(c,m,y,k) syntax is always accepted.
    • colorCallback(color, raw) — transform or replace parsed SVG colors before they are applied. Useful for custom spot-color handling.
    • precision — curve subdivision precision for path geometry (default 3).

Coverage

  • Shape elements: rect, circle, ellipse, line, polyline, polygon, path (including elliptical arcs).
  • Text: text, tspan, textPath, with text-anchor, dominant-baseline, baseline-shift, letter and word spacing, textLength, text decoration, xml:space.
  • Structure: g, svg, defs, use, symbol, a.
  • Styling: presentation attributes, style="", <style> rules with tag/id/class selectors, and property inheritance.
  • Effects: marker, clipPath, mask (luminance and alpha), opacity, blend modes, dash patterns, vector-effect.
  • Paint servers: linear and radial gradients, and patterns as tiling patterns, both including per-stop alpha via soft masks.
  • CMYK: named colors, cmyk(c,m,y,k) syntax, and CMYK gradients when options.cmyk is enabled.
  • Raster images: <image> referencing base64 data:image/png or data:image/jpeg URIs, with PNG alpha as an SMask.
  • Link annotations: <a> elements become PDF link annotations.

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. The SVG parsing and layout logic is derived from SVG-to-PDFKit and svg-for-pdfkit; the upstream code remains available under the MIT License reproduced in the LICENSE file.