Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Render HTML from External File into PDF using Angular 12. #3715

Closed
pcelman opened this issue Mar 18, 2024 · 1 comment
Closed

Unable to Render HTML from External File into PDF using Angular 12. #3715

pcelman opened this issue Mar 18, 2024 · 1 comment

Comments

@pcelman
Copy link

pcelman commented Mar 18, 2024

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?

Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant