700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > angular将html导出为pdf Angular2 - 使用jspdf从HTML生成pdf

angular将html导出为pdf Angular2 - 使用jspdf从HTML生成pdf

时间:2023-07-25 04:20:57

相关推荐

angular将html导出为pdf Angular2 - 使用jspdf从HTML生成pdf

对于我正在处理的项目,我需要能够生成用户当前正在使用的页面的PDF,为此我将使用jspdf。因为我有一个HTML我需要生成一个PDF,我需要的addHTML()功能。这里有很多话题,说Angular2 - 使用jspdf从HTML生成pdf

You'll either need to use html2canvas or rasterizehtml .

我选择使用html2canvas。这是我的代码看起来像此刻:

import { Injectable, ElementRef, ViewChild } from '@angular/core';

import * as jsPDF from 'jspdf';

import * as d3 from 'd3';

import * as html2canvas from 'html2canvas';

@Injectable()

export class pdfGeneratorService {

@ViewChild('to-pdf') element: ElementRef;

GeneratePDF() {

html2canvas(this.element.nativeElement, {

onrendered: function(canvas: HTMLCanvasElement) {

var pdf = new jsPDF('p','pt','a4');

pdf.addHTML(canvas, function() {

pdf.save('web.pdf');

});

}

});

}

}

当这个函数被调用时,我得到一个控制台错误:

EXCEPTION: Error in ./AppComponent class AppComponent - inline template:3:4 caused by: You need either /niklasvh/html2canvas or /cburgmer/rasterizeHTML.js

到底为什么会这样?我给了一个canvas作为参数,它仍然说我需要使用html2canvas。

-04-07

FlorisdG

+0

你试过从html2canvas/dist/html2canvas.js中导入*作为html2canvas吗? –

+0

@SyedAliTaqi我想你的建议,但它抛出错误 –

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。