首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >html to pdf下载在angular jspdf

html to pdf下载在angular jspdf
EN

Stack Overflow用户
提问于 2020-10-05 14:09:42
回答 1查看 71关注 0票数 0

我已经为angular安装了jspdf。我有一些html内容要显示在模态,我需要下载在pdf。每当我下载时,我得到的是空的pdf文件下载。

代码语言:javascript
复制
downloadPdf(): void {
const data = document.getElementById('pdfData');
html2canvas(data).then(canvas => {
  const imgWidth = 150;
  const pageHeight = 200;
  const imgHeight = canvas.height * imgWidth / canvas.width;
  const heightLeft = imgHeight;
  const contentDataURL = canvas.toDataURL('image/png');
  const pdf = new jsPDF('p', 'pt', 'a4');
  const position = 0;
  pdf.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight);
  pdf.save('invoice.pdf');
});
EN

回答 1

Stack Overflow用户

发布于 2020-10-11 22:23:49

使用jspdf.html()方法代替http://raw.githack.com/MrRio/jsPDF/master/docs/module-html.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64203236

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档