• Stars
    star
    609
  • Rank 71,276 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A javascript-only SVG to PDF conversion utility that runs in the browser. Brought to you by yWorks - the diagramming experts

svg2pdf.js

NPM version Continous Integration for svg2pdf.js

A javascript-only SVG to PDF conversion utility that runs in the browser leveraging jsPDF.

Give it a trial: online playground.

Installation

You can get svg2pf.js via npm:

npm install svg2pdf.js jspdf --save
# or
yarn add svg2pdf.js jspdf

Since version 2.x, this repository no longer depends on a forked jsPDF but can be used with original MrRio/jsPDF.

If you want to use a development version from the repository, pay attention to the fact that the files in dist may reflect the last release version. So a simple package.json dependency link to the branch or revision will fail. See #102 for details.

Usage

import { jsPDF } from 'jspdf'
import 'svg2pdf.js'

const doc = new jsPDF()

const element = document.getElementById('svg')
doc
  .svg(element, {
    x,
    y,
    width,
    height
  })
  .then(() => {
    // save the created pdf
    doc.save('myPDF.pdf')
  })

Have a look at the typings file for detailed documentation.

Other module formats

Importing is also possible via requirejs:

require.config({
  baseUrl: './node_modules'
});
require([
  'svg2pdf.js/dist/svg2pdf.umd.min',
  'jspdf/dist/jspdf.umd.min'
], (svg2pdf, jsPDF) => {...});

or script-tag:

<script src="[node_modules|bower_components]/jspdf/dist/jspdf.umd.min.js"></script>
<script src="[node_modules|bower_components]/svg2pdf.js/dist/svg2pdf.umd.min.js"></script>

Concerning custom fonts and non US-ASCII characters

If you want to use other than really basic fonts and characters you have to add them first before calling svg2pdf:

Please refer to the jsPDF readme.

Reporting issues

Svg2pdf is by no means perfect. If you find something is not working as expected we are glad to receive an issue report from you. In order to be able to react efficiently we ask you to provide us with the necessary information.

Please stick to our Code of Conduct.

Building

If you want to play with the sources or build the minified js file yourself, check out the repository and use the npm scripts defined in package.json:

npm run build

Testing

The test folder contains a set of unit tests. Each unit test has its own folder and contains exactly two files:

  • A spec.svg file that contains the svg to test
  • A reference.pdf file that is generated automatically and serves as reference for regression testing

You can run the tests using

npm run createreferences && npm run test-unit

The tests use the Karma framework and run in a captured (headless) browser.

The createreferences script starts a server that automatically saves reference PDFs if they don't already exist. You can omit this command if you just want to test for regression.

If you're debugging and want to have visual feedback, you should switch the debug flag to true in test/unit/all.spec.js. This ensures that a new reference PDF will be created on every run. You might also want to disable some tests in the test/common/tests array.

Dependencies

License

The MIT License (MIT)

Copyright (c) 2015-2023 yWorks GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

yfiles-for-html-demos

The source code demos for the yFiles for HTML diagramming library
397
star
2

yGuard

The open-source Java obfuscation tool working with Ant and Gradle by yWorks - the diagramming experts
Java
330
star
3

yfiles-jupyter-graphs

The home of the Jupyter notebook graph visualization widget powered by yFiles for HTML
94
star
4

generator-yfiles-app

A yeoman generator that scaffolds a yFiles for HTML powered application. Requires local yFiles package (https://www.yworks.com/yfileshtml).
JavaScript
22
star
5

yfiles-for-java-swing-demos

The source code demos for the yFiles for Java Swing diagramming library
14
star
6

yfiles-neo4j-basic-demo

A sample web app for the integration of yFiles for HTML with Neo4j to visualize database contents
JavaScript
13
star
7

ontology-visualizer

The sample web app for the yFiles use case about an Ontology Visualizer.
JavaScript
10
star
8

visual-programming

How to create a visual-programming environment with a generic diagramming framework. [WIP]
TypeScript
10
star
9

react-yfiles-orgchart

yFiles React Organization Chart Component - A powerful and versatile React component based on the yFiles library, allows you to seamlessly incorporate dynamic and interactive organization charts into your applications.
TypeScript
10
star
10

yfiles-for-wpf-demos

The source code demos for the yFiles WPF diagramming library
C#
9
star
11

yfiles-jupyter-graphs-for-neo4j

The open-source adapter for working with neo4j graphs and cypher queries in jupyter notebooks leveraging the yFiles Graphs for Jupyter plugin.
Python
9
star
12

space-time-graphs

The sample web app for the yFiles use case about Navigating Your Graph Through Time and Space.
TypeScript
8
star
13

yfiles.net-for-winforms-demos

The source code demos for the yFiles.NET Windows Forms diagramming library
C#
8
star
14

yfiles-for-javafx-demos

The source code demos for the yFiles for JavaFX diagramming library
7
star
15

graphs-in-power-bi

Use-case for yFiles for HTML that shows how to integrate a sophisticated custom graph visualization visual in PowerBI
Jupyter Notebook
6
star
16

yfiles-react-integration-basic

A basic sample app for the integration of yFiles for HTML with React
TypeScript
5
star
17

react-yfiles-supply-chain

yFiles React Supply Chain Component - A powerful and versatile React component based on the yFiles library, allows you to seamlessly incorporate dynamic and interactive supply chain diagrams into your applications.
TypeScript
5
star
18

yfiles-vue-integration-basic

A basic sample app for the integration of yFiles for HTML with Vue.js
Vue
4
star
19

yfiles-angular-integration-basic

A basic sample app for the integration of yFiles for HTML with Angular
TypeScript
4
star
20

migrate-yfiles-app

JavaScript toolchain that helps in migrating applications written for older yFiles for HTML versions to newer ones
JavaScript
3
star
21

graphs-in-digital-marketing

The sample web app for the yFiles use case about Digital Marketing Optimization.
TypeScript
3
star
22

yfiles-for-html-salesforce-lwc-sample

Sample code that shows how to use yFiles for HTML in a Lightning Web Component on the Salesforce platform
JavaScript
3
star
23

yfiles-layout-reactflow

yFiles Layouts for React Flow - A layout library for React Flow providing powerful yFiles layout algorithms and supporting components
TypeScript
3
star
24

cosmosdb-visualizer-example

This is a web app that uses the Azure Cosmos DB to perform visual process mining. Using Gremlin, Node.js, webpack, and yFiles for HTML.
JavaScript
1
star
25

migrate-yfiles-ts-app

Tool that helps with the migration of typescript files that reference old yFiles for HTML API.
TypeScript
1
star
26

GD2021-PhDSchool

Sample application for the PhD school session at Graph Drawing 2021
TypeScript
1
star
27

cypher-query-validator

Provides a typescript implementation that validates a Cypher query string against a simple schema definition and fixes relationship directions when necessary.
TypeScript
1
star
28

react-yfiles-core

This module provides shared functionality for the yFiles React components
TypeScript
1
star
29

yfiles-dash-basic-integration

Shows how to integrate yFiles for HTML as a Dash/Plotly plugin
JavaScript
1
star
30

yfiles-power-bi-integration-basic

Basic integration of yFiles for HTML in Power BI
TypeScript
1
star
31

yfiles-asp.net-blazor

Sample project for using yFiles for HTML with ASP.NET Blazor
HTML
1
star