如何解决Angular Html2Pdf - DOMException:无法在“ShadowRoot”上设置“adoptedStyleSheets”属性
使用 Angular 12 实现 html2pdf,将部分 html 页面转换为 PDF 以供下载。
控制台错误
index-7a8b7a1c.js:150 Uncaught (in promise) DOMException: Failed to 在“ShadowRoot”上设置“adoptedStyleSheets”属性:共享 不允许在多个文档中构建样式表
HTML
<section id="toPdfContainer">
<h5 class="card-title">Hello WOrld!</h5>
</section>
<button class="btn btn-primary w-100" (click)="toPdf()">TO PDF</button>
脚本
import * as html2pdf from 'html2pdf.js';
...
public toPdf() {
const elementToPdf = document.getElementById('toPdfContainer');
console.log('to PDF',elementToPdf);
const opt = {
margin: 1,filename: 'myfile.pdf',image: { type: 'jpeg',quality: 0.98 },html2canvas: { scale: 2 },jsPDF: { unit: 'in',format: 'letter',orientation: 'portrait' }
};
html2pdf().set(opt).from(elementToPdf).save();
}
有人能帮我解决这个问题吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。