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 sent authorized header attribute value using c# .net httpclient for third party api call of oauth 2.0

How to sent authorized header attribute value using C# .NET HTTP client for third party API call of OAuth 2.0 For call token From Authorized...

Popular Posts