Looking for assistance in implementing html2pdf with Angular 12 to convert specific parts of an HTML page into a downloadable PDF.
ERROR MESSAGE
An error occurred while trying to execute the code: index-7a8b7a1c.js:150 Uncaught (in promise) DOMException: Failed to set the 'adoptedStyleSheets' property on 'ShadowRoot': Sharing constructed stylesheets in multiple documents is not allowed
HTML SNIPPET
<section id="toPdfContainer">
<h5 class="card-title">Hello WOrld!</h5>
</section>
<button class="btn btn-primary w-100" (click)="toPdf()">TO PDF</button>
JAVASCRIPT FUNCTION
import * as html2pdf from 'html2pdf.js';
...
public toPdf() {
const elementToPdf = document.getElementById('toPdfContainer');
console.log('Converting to PDF', elementToPdf);
const options = {
margin: 1,
filename: 'myfile.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
};
html2pdf().set(options).from(elementToPdf).save();
}
Seeking assistance and guidance to resolve this issue.