-1

After my user fills out the form I want to render the page to PDF.

There are a lot of options for HTML to PDF, how would I render the page in memory and get the innerHtml? Or is there another way?

Right now I'm building the PDF manually.

xgdfalcon
  • 9
  • 1

1 Answers1

0

Try to use jspdf and html2canvas

install this package.

npm i jspdf
npm i html2canvas

ts file

import * as jsPDF from 'jspdf';
import h2c from 'html2canvas';

loadPDF() {
let doc = new jsPDF('p', 'pt', 'a4');
h2c(document.getElementById('pagePrintPdf')).then(function (canvas) {
  let width = doc.internal.pageSize.getWidth();
  let height = doc.internal.pageSize.getHeight();
  let dataURL = canvas.toDataURL('image/jpeg', 1.0);
  doc.addImage(dataURL, 'jpg', 0, 0, width, height, 'none');
  doc.save(`test.pdf`);
  });
}
Bansi29
  • 1,053
  • 6
  • 24