作者:DilWilling | 来源:互联网 | 2022-12-09 16:31
我正在尝试在angular中使用jspdf库的addHTML函数,并且已经安装了html2Canvas,但是出现了错误。
这是我的demo.component.ts文件。
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
import * as jsPDF from 'jspdf';
import * as html2canvas from "html2canvas";
@Component({
selector: 'app-demo',
templateUrl: './demo.component.html',
styleUrls: ['./demo.component.scss']
})
export class DemoComponent implements OnInit {
@ViewChild('content') content:ElementRef;
constructor() { }
ngOnInit() {}
download() {
console.log("vijay")
let doc = new jsPDF('p','pt','a4');
let specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
let cOntent= this.content.nativeElement.innerHTML;
// doc.fromHTML( content, 15, 15, {
// 'width': 200,
// 'elementHandlers': specialElementHandlers
// });
doc.addHTML(document.getElementById('content'),function() {
doc.save('web.pdf');
});
}
}
这是我的demo.component.html文件。
HTML Table
Company
Contact
Country
Alfreds Futterkiste
Maria Anders
Germany
Centro comercial Moctezuma
Francisco Chang
Mexico
Ernst Handel
Roland Mendel
Austria
Island Trading
Helen Bennett
UK
Laughing Bacchus Winecellars
Yoshi Tannamuri
Canada
Magazzini Alimentari Riuniti
Giovanni Rovelli
Italy
Download
当我点击下载按钮时,它将给我这个错误:
错误:您需要https://github.com/niklasvh/html2canvas或https://github.com/cburgmer/rasterizeHTML.js
我已经在demo.component.ts中导入了html2canvas。并已尝试使用formHTML并能正常工作,但我想专门使用addHTML函数或html2canvas。
任何帮助将不胜感激。