pdf changes
This commit is contained in:
parent
756b6fed83
commit
d8dfd8a6f2
@ -4,10 +4,18 @@ import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { format } from 'date-fns';
|
||||
import { sendEmailWithAttachmentUtil } from "../../../utils/emailService";
|
||||
import * as pdfMake from 'pdfmake/build/pdfmake';
|
||||
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
|
||||
|
||||
(pdfMake as any).vfs = (pdfFonts as any).pdfMake ? (pdfFonts as any).pdfMake.vfs : pdfFonts.vfs;
|
||||
let pdfMake: any;
|
||||
let pdfFonts: any;
|
||||
|
||||
function initPdfLibraries() {
|
||||
if (!pdfMake) {
|
||||
pdfMake = require('pdfmake/build/pdfmake');
|
||||
pdfFonts = require('pdfmake/build/vfs_fonts');
|
||||
pdfMake.vfs = pdfFonts.pdfMake ? pdfFonts.pdfMake.vfs : pdfFonts.vfs;
|
||||
}
|
||||
return pdfMake;
|
||||
}
|
||||
|
||||
const admin = getAdmin();
|
||||
const logger = getLogger();
|
||||
@ -45,6 +53,7 @@ export interface EmailOptions {
|
||||
export class InvoiceService {
|
||||
async generateInvoice(data: InvoiceData): Promise<string> {
|
||||
try {
|
||||
const pdfMake = initPdfLibraries();
|
||||
const tempFilePath = path.join(os.tmpdir(), `invoice_${data.invoiceNumber}.pdf`);
|
||||
|
||||
const hasGst = data.gstNumber && data.gstNumber.length > 0;
|
||||
@ -255,7 +264,7 @@ export class InvoiceService {
|
||||
const pdfDoc = pdfMake.createPdf(docDefinition);
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
pdfDoc.getBuffer((buffer) => {
|
||||
pdfDoc.getBuffer((buffer: Buffer) => {
|
||||
fs.writeFile(tempFilePath, buffer, (err) => {
|
||||
if (err) reject(err);
|
||||
else resolve();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user