How to Create pdf file and download it or convert into base64 string

 

How to Create pdf file and download it or convert into base64 string


1).First Install Following packages from Node module
1).npm install jspdf --save
page Url:https://www.npmjs.com/package/jspdf
2).npm install jspdf jspdf-autotable
page Url:https://www.npmjs.com/package/jspdf-autotable
Code Writing:-


import * as jspdf from 'jspdf'; import 'jspdf-autotable'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) export class HeroService { constructor() { } generateXml(data,UseType,IsGenerate){ const pdf= new jsPDF(); pdf.autoTable({ html: '#my-table' }) // Or use javascript directly: pdf.autoTable({ head: [['Name', 'Email', 'Country']], body: [ ['David', 'david@example.com', 'Sweden'], ['Castille', 'castille@example.com', 'Spain'], // ... ], }) if (IsGenerate) { pdf.save(data.ReferenceNo + '.pdf'); return ''; } else { return pdf.output('datauristring').replace('data:application/pdf;filename=generated.pdf;base64,', ''); } }

Now Need to Call Service in Your Component:-
 postJson.PdfString = this.pdfService.generatePDF(this.trademodel, true, false);

No comments:

Post a Comment

Thank You For Your Great Contribution

Featured Post

how to find duplicate item from array using multiple object keys in angular or javascript

 how to find duplicate item from array using multiple object keys There is a way to find based of multiple key find duplicate records in ang...

Popular Posts