Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
svg2pdf.js
Advanced tools
A javascript-only SVG to PDF conversion utility that runs in the browser leveraging jsPDF
A javascript-only SVG to PDF conversion utility that runs in the browser leveraging jsPDF.
Give it a trial: online playground.
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.
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.
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>
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.
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.
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
The test
folder contains a set of unit tests. Each unit test has its own folder and contains exactly two files:
spec.svg
file that contains the svg to testreference.pdf
file that is generated automatically and serves as reference for regression testingYou 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.
The MIT License (MIT)
Copyright (c) 2015-2020 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.
FAQs
A javascript-only SVG to PDF conversion utility that runs in the browser leveraging jsPDF
The npm package svg2pdf.js receives a total of 8,841 weekly downloads. As such, svg2pdf.js popularity was classified as popular.
We found that svg2pdf.js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.