Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@react-pdf/svg

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-pdf/svg

SVG parsing for react-pdf

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
1.1M
38.23%
Maintainers
1
Weekly downloads
 
Created
Source

React renderer for creating PDF files on the browser and server

@react-pdf/svg

SVG string parser for react-pdf.

Parses SVG markup into a tree of nodes compatible with react-pdf's SVG primitives.

Installation

npm install @react-pdf/svg
# or
yarn add @react-pdf/svg

Usage

import { parseSvg } from '@react-pdf/svg';

const tree = parseSvg(
  '<svg viewBox="0 0 100 100"><circle cx="50" cy="50" r="40" fill="red" /></svg>',
);

Returns an SvgNode tree:

{
  type: 'SVG',
  props: { viewBox: '0 0 100 100' },
  children: [
    {
      type: 'CIRCLE',
      props: { cx: '50', cy: '50', r: '40', fill: 'red' },
      children: []
    }
  ]
}

Supported elements

svg, g, path, rect, circle, ellipse, line, polyline, polygon, text, tspan, defs, clipPath, linearGradient, radialGradient, stop, image

API

parseSvg(svgString: string): SvgNode

Parses an SVG string and returns the root SvgNode. Attributes are converted to camelCase and tag names are mapped to react-pdf primitive types. Unsupported elements are skipped with a console warning.

SvgNode

interface SvgNode {
  type: string;
  props: Record<string, unknown>;
  children?: SvgNode[];
}

License

MIT

FAQs

Package last updated on 15 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts