Unable to Render HTML from External File into PDF using Angular 12.
pcelman opened this issue · comments
I'm encountering difficulty rendering HTML content from an external file into a PDF within an Angular 12 application.
I have this function on a service:
` htmlFilePath = "../../pdf/pdf-component.html"
viewPDF() {
html2canvas(this.htmlFilePath).then((canvas) => {
const imgData = canvas.toDataURL('image/jpeg');
const imgWidth = 210;
const pageHeight = 297;
const imgHeight = canvas.height * imgWidth / canvas.width;
let heightLeft = imgHeight;
const pdf = new jsPDF('p', 'mm', "A4");
let position = 0;
pdf.addImage(imgData, 'JPEG', 0, position, imgWidth, imgHeight);
heightLeft -= pageHeight;
while (heightLeft >= 0) {
position = heightLeft - imgHeight;
pdf.addPage();
pdf.addImage(imgData, 'JPEG', 0, position, imgWidth, imgHeight);
heightLeft -= pageHeight;
}
this.addFooters(pdf);
pdf.output('dataurlnewwindow');
});
}`
htmlFilePath is just an example, can´t make it render a pdf from a different location.
Any suggestions?
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.