Javascript Library for Exporting SVG Charts from DOM | exportJS

An easy-to-use client-side Javascript library to export SVG graphics from webpages and download them as an SVG, PDF, or bitmap image (JPEG, PNG). Written in Vanilla JavaScript. It was originally created to export D3.js charts.

The library is characterized by:

  • Export SVG DOM object objects or SVG sequences to an SVG, PNG, JPEG, and PDF file.
  • Specify a custom size for the exported image or graphic.
  • High-resolution bitmap image using the scale.
  • Including SVG external CSS stylesheets.
  • Export text in custom embedded fonts.
  • Work with transparent background to convert JPEG format.
  • Exporting hidden SVGs in the DOM (view: none, SVGs in hidden .shapes, dropdown menus or tabs, etc.).

How to make use of it:

1. Download and load the svg-export.js library within the doc.

<script src="svg-export.min.js"></script>

2. Load the Canvg library if it’s essential to export SVG information as a picture.

<script src="https://unpkg.com/canvg/lib/umd.js"></script>

3. Load the next JavaScript libraries if it’s essential to export SVG information as a PDF.

<script src="https://cdn.jsdelivr.net/npm/pdfkit/js/pdfkit.min.js"></script>
<script src="https://github.com/devongovett/blob-stream/releases/download/v0.1.3/blob-stream.js"></script>
<script src="https://cdn.jsdelivr.net/npm/svg-to-pdfkit/source.min.js"></script>

4. Export your SVG as an SVG file.

svgExport.downloadSvg(
  // SVG ID
  "#mysvg",
  // Fille name
  "Filename",
  {  custom size
    width: 200, 
    height: 200 
  }
);

5. Export your SVG as a picture.

svgExport.downloadPng(
  // SVG ID
  "#mysvg",
  // Fille name
  "Filename",
  {
    // options here
  }
);
svgExport.downloadJpeg(
  // SVG ID
  "#mysvg",
  // Fille name
  "Filename",
  {
    // options here
  }
);

6. Export your SVG as a PDF file.

svgExport.downloadPdf(
  // SVG ID
  "#mysvg",
  // Fille name
  "Filename",
  {
    // options here
  }
);

7. Full choices with default values.

{
  width: 100,
  height: 100, 
  scale: 1,
  useCSS: true, // handles external CSS in SVG elements
  PDFOptions: {
    customFonts: [],
    pageLayout: { margin: 50, margins: {} },
    addTitleToPage: true,
    chartCaption: "",
    PDFtextFontFamily: "Helvetica",
    PDFTitleFontSize: 20,
    PDFCaptionFontSize: 14
  }
}

Save SVG Data To A File Using the svg-export, svg exportJS Plugin/Github


See Demo And Download

Official Website(sharonchoong): Click Here

This superior jQuery/javascript plugin is developed by sharonchoong. For extra Advanced usage, please go to the official website.

Related Posts

drag-drop-file-5x5-jq-uploader

Responsive Drag and Drop File Uploader/Download Plugin | 5x5_jq_uploader

5x5_jq_uploader plugin can be used to instantly create a drop file area and file queue with a little bit of preparation. Bootstrap is used for responsive planning…

Bootstrap-Dark-Mode

Stylesheet For Implementing Dark Mode with Bootstrap

Bootstrap Dark Mode provides a style sheet and two texts that allow you to implement Dark Mode on your website. Initially loaded based on user preferences, can…

responsive-navigation-menu

Multi-purpose Navigation Menu for Javascript Library | jQuery Corenav

coreNavigation is a multipurpose navigation menu for a jquery based javascript library, comes with more style, and is easy to integrate. 11 Default Menu 2 Responsive Navigation…

Simple-Multi-Select-Dropdown-Pure-Vanilla-Javascript

Simple Multi-Select Dropdown Pure Vanilla Javascript | multiSelect.js

MultiSelect.js is a simple, clean, and progressive JavaScript library designed for easy integration with any type of project or system. The design was heavily influenced by the…

Confetti-Falling-Animation-Effect-party

Confetti Falling Animation Effect In JavaScript | party.js

Party.js is a JavaScript library to brighten user site experience with visual effects! Celebrate success with dom confetti! The library is written in TypeScript and compiled into…

how-to-create-popup-in-html-with-css

How To Create A Popup in HTML with CSS

How to create popup in html with css – Popup without JavaScript is an elegant pop-up panel component with an animated scale, written in CSS. Have you…