Search
 
SCRIPT & CODE EXAMPLE
 

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>
Comment

jspdf html to pdf angular 8

import { Component } from '@angular/core';
import { jsPDF } from "jspdf";
import html2canvas from 'html2canvas';
 
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'html-to-pdf-angular-application';
public convertToPDF()
{
html2canvas(document.body).then(canvas => {
// Few necessary setting options
 
const contentDataURL = canvas.toDataURL('image/png')
let pdf = new jsPDF('p', 'mm', 'a4'); // A4 size page of PDF
var width = pdf.internal.pageSize.getWidth();
var height = canvas.height * width / canvas.width;
pdf.addImage(contentDataURL, 'PNG', 0, 0, width, height)
pdf.save('output.pdf'); // Generated PDF
});
}
}
Comment

PREVIOUS NEXT
Code Example
Html :: html go up a folder 
Html :: making a legend in html 
Html :: h1 alert 
Html :: bold text html 
Html :: drag and drop html 
Html :: Open popup Form using bootstrap modal on button click in asp net c# 
Html :: twig form row label 
Html :: html heading tags 
Html :: html website 
Html :: enable provider plugin cache in terraform 
Html :: html class 
Html :: vscode access workspace settings.json 
Html :: what is ref in html 
Html :: time in website 
Html :: html email signature 
Html :: html tutorial 
Html :: how to mask input in html as phone numbr 
Html :: srcset 
Html :: s9 berlin 
Html :: rich text editor mvc razor 
Html :: name attribute use case html 
Html :: nunjucks escape brackets 
Html :: linq card html 
Html :: am pm after the time in html 
Html :: salesforce required asterisk input filed 
Html :: PC JS 
Html :: adminLTE infoboxes 
Html :: hoe to make a html page attractive 
Html :: how to set up html basic workspace 
Html :: make a link of index in previous folder 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =