Socket
Socket
Sign inDemoInstall

svg-to-pdfkit

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-to-pdfkit

Insert SVG into a PDF document created with PDFKit


Version published
Weekly downloads
179K
increased by6.36%
Maintainers
1
Weekly downloads
 
Created

What is svg-to-pdfkit?

The svg-to-pdfkit npm package allows you to render SVG images into PDF documents using the PDFKit library. This is useful for generating PDFs that include vector graphics, which can be scaled without loss of quality.

What are svg-to-pdfkit's main functionalities?

Render SVG to PDF

This feature allows you to render an SVG string into a PDF document. The code sample demonstrates how to create a PDF document, render an SVG circle into it, and save the output as a PDF file.

const PDFDocument = require('pdfkit');
const fs = require('fs');
const SVGtoPDF = require('svg-to-pdfkit');

const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('output.pdf'));

const svg = '<svg height="100" width="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>';
SVGtoPDF(doc, svg, 0, 0);

doc.end();

Positioning SVG in PDF

This feature allows you to specify the position where the SVG should be rendered in the PDF document. The code sample demonstrates how to render an SVG circle at coordinates (100, 150) in the PDF.

const PDFDocument = require('pdfkit');
const fs = require('fs');
const SVGtoPDF = require('svg-to-pdfkit');

const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('output.pdf'));

const svg = '<svg height="100" width="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>';
SVGtoPDF(doc, svg, 100, 150);

doc.end();

Scaling SVG in PDF

This feature allows you to scale the SVG when rendering it into the PDF document. The code sample demonstrates how to render an SVG circle with a width and height of 200 units in the PDF.

const PDFDocument = require('pdfkit');
const fs = require('fs');
const SVGtoPDF = require('svg-to-pdfkit');

const doc = new PDFDocument();
doc.pipe(fs.createWriteStream('output.pdf'));

const svg = '<svg height="100" width="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>';
SVGtoPDF(doc, svg, 0, 0, { width: 200, height: 200 });

doc.end();

Other packages similar to svg-to-pdfkit

FAQs

Package last updated on 24 Nov 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc