Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

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
});
}
}
Source by www.itsolutionstuff.com #
 
PREVIOUS NEXT
Tagged: #jspdf #html #pdf #angular
ADD COMMENT
Topic
Name
7+7 =