JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 193
  • Score
    100M100P100Q85930F
  • License ISC

convert html code to svg and download svg or png

Package Exports

  • htmlsvg

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (htmlsvg) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

htmlsvg

converts html element to svg element (rect,text,img).

online demo:

https://htmlsvg.netlify.app/

Install

$ npm install htmlsvg

Usage

import htmlToSvg from "htmlsvg";
const htmlElement = document.getElementById("DivId");
const svg = await htmlToSvg(htmlElement);
console.log(svg);

You can directly download svg with passing config object

import htmlToSvg from "htmlsvg";

const svgConfig = {
  downloadSvg: true,
  filename: "htmltosvg",
};
const htmlElement = document.getElementById("DivId");
const svg = await htmlToSvg(htmlElement, svgConfig);
console.log(svg);

You can directly download png with passing config object

import htmlToSvg from "htmlsvg";

const svgConfig = {
  downloadSvg: true,
  downloadPng: true,
  convertDataUrl: true, // you need to convert images to dataurl if you wanna download png image
  filename: "htmltosvg",
};
const htmlElement = document.getElementById("DivId");
const svg = await htmlToSvg(htmlElement, svgConfig);
console.log(svg);