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

@hadi77ir/pdfme-svg

v0.1.7

Published

pdfme svg plugin

Readme

pdfme-svg

A pdfME plugin that renders SVG content inside PDF templates.

Fork note

This codebase is mainly a fork of github.com/yWorks/svg2pdf.js. The only repository-specific modifications are the jsPDF shim (src/jspdf-shim.ts) and the pdfME plugin wrapper (src/index.ts). Other changes include improving svg2pdf's handling of SVGs, which may be contributed to upstream.

Install

npm install @hadi77ir/pdfme-svg @pdfme/common @pdfme/pdf-lib

Build

This package ships its compiled output in dist/.

npm run build

Usage with pdfME

Register the plugin under the svg type and pass SVG strings as field values.

import { generate } from '@pdfme/generator';
import createSvgPlugin from '@hadi77ir/pdfme-svg';

const template = {
  basePdf: { width: 210, height: 297, padding: 0 },
  schemas: [
    {
      name: 'logo',
      type: 'svg',
      position: { x: 20, y: 20 },
      width: 60,
      height: 60,
      loadExternalStyleSheets: false,
    },
  ],
};

const inputs = [
  {
    logo: `<svg viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg">
  <rect x="10" y="10" width="100" height="100" rx="12" fill="#111827"/>
  <circle cx="60" cy="60" r="30" fill="#60A5FA"/>
  <path d="M40 62 L55 77 L82 46" stroke="#F9FAFB" stroke-width="8" fill="none"/>
</svg>`,
  },
];

const pdf = await generate({
  template,
  inputs,
  plugins: { svg: createSvgPlugin() },
});

Scaling

Optional schema fields let you control how SVG content fits inside the schema box:

  • scale: Uniform scale factor (alias: zoom).
  • fit: How to fit the SVG content inside the box. One of none (default), contain, cover, stretch.

When both are provided, scale is applied after the fit calculation.

Example:

{
  name: 'logo',
  type: 'svg',
  position: { x: 20, y: 20 },
  width: 60,
  height: 60,
  fit: 'contain',
  scale: 1.1,
}

For advanced measurement, getSvgBoundingBox is exported and can be used with a DOM and a jsPDF instance.

Notes

  • Positions and sizes are in millimeters, matching pdfME's layout system.
  • When a DOM is available (browser or a DOM shim in Node), the plugin uses the internal svg2pdf pipeline for higher fidelity.
  • When no DOM is available, it can fall back to pdf-lib's drawSvg for compatibility (if fallbackToPdfLib is set to true in input schema) or throw an error.
  • Fit modes rely on SVG bounding boxes and require a DOM-enabled environment.
  • Set loadExternalStyleSheets: true to allow external CSS in SVGs (requires network access and a DOM-enabled environment).

License

  • Plugin Code and changes to Main Code: MIT License, Copyright (c) 2025 Mohammad Hadi Hosseinpour
  • Main Code: From svg2pdf.js, MIT License, Copyright (c) 2015-2025 yWorks GmbH
  • tsconfig.*.json, import info parts of package.json and npm scripts: From pdfME, MIT License, Copyright (c) 2020 HandDot

LLM Usage

Most of the new modifications in this repository (the plugin code) has been written by LLMs (Gemini-3-Pro-Preview and GPT-5.2-Codex-ExtraHigh).