yWorks / svg2pdf.js

A javascript-only SVG to PDF conversion utility that runs in the browser. Brought to you by yWorks - the diagramming experts
MIT License
667 stars 104 forks source link

t.cloneNode is not a function #51

Closed tonyhayes closed 6 years ago

tonyhayes commented 6 years ago

I'm getting the following error when trying to convert an SVG object using Vue.js

    at e (svg2pdf.min.js?95fe:31)
    at VueComponent.getPDF (Charts.vue?6ddd:110)
HTML
    <div id="svg-container">
      <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="100">
        <rect height="100" width="100" style="stroke:#f7f7f7; fill: #74ad24" />
      </svg>
    </div>
Vue imports
import * as JsPdf from 'jspdf-yworks';
import * as svg2pdf from 'svg2pdf.js';
Function 
    getPDF () {
      console.log('getPDF');
      // Get svg markup as string
      let svg = document.getElementById('svg-container').innerHTML;
      svg = svg.replace(/\r?\n|\r/g, '').trim();
      const pdf = new JsPdf('l', 'pt', 'a4');

      // render the svg element
      svg2pdf(svg, pdf, {
        xOffset: 0,
        yOffset: 0,
        scale: 1
      });

      // get the data URI
      // const uri = pdf.output('datauristring');

      // or simply safe the created pdf
      pdf.save('myPDF.pdf');
    },
SVG string
"<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="100"><rect height="100" width="100" style="stroke: rgb(247, 247, 247); fill: rgb(116, 173, 36);"></rect></svg>"
yGuy commented 6 years ago

The first argument to svg2pdf should be a dom element, not a string. Please try debugging the issues yourself, first. This is not a support forum.