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 :: icon inside input tag 
Html :: markup embed youtube 
Html :: link md 
Html :: bootstrap form-switch 
Html :: add keywords meta tag 
Html :: <i class="fa fa-tag"</i fontawesome 
Html :: angular open pdf in new tab 
Html :: tag img 
Html :: html page to screenshot 
Html :: html time input with second 
Html :: amp-img example 
Html :: index.html file 
Html :: radio checked on start 
Html :: html <br tag 
Html :: highlight js 
Html :: use variable in input value vuejs 
Html :: navbar with logo css 
Html :: html form label 
Html :: input type password show asterisk 
Html :: make checkbox required 
Html :: hr tag html 
Html :: html script crossorigin 
Html :: label input html 
Html :: The template root requires exactly one element.eslint-plugin-vue 
Html :: HTML5 Video tag not working in Safari , iPhone and iPad 
Html :: Error: input is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`. 
Html :: rick astley never gonna give you up 
Html :: html make text bold 
Html :: which text is used to create text animations in html 
Html :: game engine 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =