Save SVG Data To A File Using the svg-export JavaScript library
1. Download and load the svg-export.js library in the document.
<script src="svg-export.min.js"></script>
2. Load the Canvg library if you need to export SVG data as an image.
<script src="https://unpkg.com/canvg/lib/umd.js"></script>
3. Load the following JavaScript libraries if you need to export SVG data 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 an image.
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 options with default values.
{
originalWidth: 100,
originalHeight: 100,
width: 100,
height: 100,
scale: 1,
useCSS: true,
excludeByCSSSelector: '', // e.g. [stroke='red'], [stroke='green'], [display='none'], .text-muted.
transparentBackgroundReplace: "white",
allowCrossOriginImages: false,
pdfOptions: {
customFonts: [],
pageLayout: { margin: 50, margins: {} },
addTitleToPage: true,
chartCaption: "",
pdfTextFontFamily: "Helvetica",
pdfTitleFontSize: 20,
pdfCaptionFontSize: 14
}
}; 8. Execute a callback function after the file export has completed.
{
onDone: function(){
// do something
}
}; v2.0 (10/22/2025)
06/23/2023
v1.3.0 (01/08/2023)
v1.2.0 (09/12/2021)
12/28/2020
The post Save SVG Data To A File Using the svg-export JavaScript library appeared first on CSS Script.
FORT WAYNE, Ind. (WOWO) — Severe weather is possible across Indiana Sunday night, especially between…
When I reviewed MLB The Show 20, I praised it as the best baseball simulation…
Batman is a character that transcends time. Regardless of your generation, everyone has "my Batman",…
Crimson Desert feels like it was designed in a lab by someone who wanted to…
HAMMOND, Ind. (WOWO) — An East Chicago woman who spent more than two decades collecting…
MIAMI BEACH, FL. (WOWO) — An Indiana University student and a recent graduate were killed…
This website uses cookies.