angulartypescriptpdf-conversion

How to download a page in Angular 8 with TS in pdf format


this is the function i'm calling for downloading the page

printComponent(cmpName) {
let printContents = document.getElementById(cmpName).innerHTML;
let originalContents = document.body.innerHTML;

document.body.innerHTML = printContents;

window.print();


document.body.innerHTML = originalContents;}

it is working but a intermediate step comes. the project requires direct download


Solution

  • You can use pdfmake

    export class AppComponent {
      generatePdf(cmpName){
      const documentDefinition = { content: document.getElementById(cmpName).innerHTML 
     };
      pdfmake.createPdf(documentDefinition).open();
     }
    }