Closed sandeep-kr-kgp closed 2 years ago
nvm..I figured it out. The trick is to convert that string to DOM element using DOM Parser..Working code:
var parser = new DOMParser(); var svgDOM = parser.parseFromString(svgString, 'image/svg+xml'); const doc = new jsPDF(); doc.svg(svgDOM.documentElement, { x: 0, y: 0, width: 1200, height: 800, }).then(() => { // save the created pdf doc.save('myPDF.pdf'); });
const svg = someSVGString; const doc = new jsPDF(); doc.svg(svg, { x: 0, y: 0, width: 1200, height: 800, }).then(() => { // save the created pdf doc.save('myPDF.pdf'); });
This throws error that querySelectorAll is not a funciton because that's not any dom element. Is there any way to use existing svg string to generate pdf ?