如何导入svg2pdf库成角5?

时间:2019-03-09 12:13:14

标签: javascript angular shared-libraries

我想将svg2pdf库导入一个有角度的项目,但我没有得到。

我已经尝试过:

1)npm install svg2pdf.js-保存

2)从'svg2pdf.js'导入*作为svg2pdf;

但是第3步仍无法正常工作: 注意:alert('teste 3');工作和警惕('teste 4');不起作用...

3)

public download2() {

      var svgElement = document.getElementById('svg');
      var width = 300;
      var height = 200;

      // create a new jsPDF instance
      const pdf = new jsPDF('l', 'pt', [width, height]);

alert('teste 3');

      // render the svg element
      svg2pdf(svgElement, pdf, {
        xOffset: 0,
        yOffset: 0,
        scale: 1
      });
alert('teste 4');

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

      // or simply save the created pdf
      pdf.save('myPDF.pdf');
}

注意:相同的步骤适用于库jspdf:

1)npm install jspdf --save

2)从``jspdf''导入*作为jsPDF;

3)

public download() {
var doc = new jsPDF();
doc.text(20, 20, 'Hello world!');
doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
doc.addPage();
doc.text(20, 20, 'Do you like that?');

// Save the PDF
doc.save('Test.pdf');
}

4)HTML:

    <button (click)="download()">PDF</button>

    <button (click)="download2()">SVG to PDF</button>

    <svg id="area_svg" xmlns="http://www.w3.org/2000/svg"
         width="296mm"
         height="410mm"
         baseProfile="full" version="1.1" style="border: 1px solid red">

      <g id=svg>
<line x1="0" y1="0" x2="200" y2="200" style="stroke-width:2" />    
      </g>


    </svg>

0 个答案:

没有答案