pdfmake-wrapper icon indicating copy to clipboard operation
pdfmake-wrapper copied to clipboard

Support request for pdfmake 0.2.X

Open Leccho opened this issue 2 years ago • 6 comments

Add support for pdfmake 0.2.X

Leccho avatar Nov 29 '22 15:11 Leccho

@Lugriz any chance for 0.2.x support? Or even the new 0.3.x still in beta? Is it too much work? I can see some work is already done here - can it be merged/released? https://github.com/Lugriz/pdfmake-wrapper/compare/fix-pdfmake-compatibility

anodynos avatar Apr 01 '23 21:04 anodynos

@anodynos I think this project is not supported anymore. I've been using pdfmake directly lately. You don't have to change much to make it work.

Leccho avatar Apr 03 '23 18:04 Leccho

Thanks, it was first attempt with it, I finally managed to make v0.2.7 play nice with typescript, so no probs 😉

anodynos avatar Apr 03 '23 21:04 anodynos

@anodynos I ended up using pdfmake backend with typescript: Install dependencies

npm i pdfmake
npm i -D @types/pdfmake

Your service or equivalent:

import { createPdf, TCreatedPdf } from 'pdfmake/build/pdfmake';
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
import { Content, TDocumentDefinitions } from 'pdfmake/interfaces';

export class PdfService {
  public createPdf(): Promise<Buffer> {
    const documentDefinitions: TDocumentDefinitions = { ... };
    const pdf: TCreatedPdf = createPdf(documentDefinitions, undefined, undefined, pdfFonts.pdfMake.vfs);
    const buffer: Buffer | void = await new Promise((resolve: (buffer: Buffer) => void): void => {
      pdf.getBuffer((b: Buffer): void => resolve(b));
    }).catch((): void => {
      // currently not working since there's no way to catch errors and create a reject of the promise
      // this is a problem with pdfmake
      throw new InternalServerErrorException('Could not create pdf');
    });
    if (!buffer) {
      throw new InternalServerErrorException('Could not create pdf');
    }
    return Buffer.from(buffer);
  }
}

Leccho avatar Apr 04 '23 19:04 Leccho

Thanks @Leccho ;-)

anodynos avatar Apr 05 '23 12:04 anodynos

Nice to hear we can use pdfmake directly. We get the following warning currently: Warning:(55, 17) Dependency npm:pdfmake:0.1.72 is vulnerable, safe version 0.2.7 CVE-2022-46161 9.8 Improper Control of Generation of Code ('Code Injection') vulnerability with high severity found Results powered by Checkmarx(c)

veslav3 avatar Aug 16 '23 13:08 veslav3