Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

html to pdf angular

npm install --save pdfmake
npm install html-to-pdfmake
npm install jspdf --save

ts file:
import jsPDF from 'jspdf';
import pdfMake from 'pdfmake/build/pdfmake';
import pdfFonts from 'pdfmake/build/vfs_fonts';
pdfMake.vfs = pdfFonts.pdfMake.vfs;
import htmlToPdfmake from 'html-to-pdfmake';

...
@ViewChild('pdfTable') pdfTable: ElementRef;
  
  public downloadAsPDF() {
    const doc = new jsPDF();
   
    const pdfTable = this.pdfTable.nativeElement;
   
    var html = htmlToPdfmake(pdfTable.innerHTML);
     
    const documentDefinition = { content: html };
    pdfMake.createPdf(documentDefinition).open(); 
    
    
HTML file:
<div class="container">
  <div id="pdfTable" #pdfTable>
...
</div>
  <button class="btn btn-primary" (click)="downloadAsPDF()">Export To PDF</button>
</div>
Source by www.itsolutionstuff.com #
 
PREVIOUS NEXT
Tagged: #html #pdf #angular
ADD COMMENT
Topic
Name
6+8 =