This project was generated with Angular CLI version 8.2.0.
npm install pdfmake --save
import * as pdfMake from 'pdfmake/build/pdfmake';
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
const pdf = pdfMake;
pdf.vfs = pdfFonts.pdfMake.vfs;
- go to '(project folder)/node_modules/pdfmake/'
- create 'examples/fonts' folder
- copy Roboto and Thai fonts ('src/assets/fonts')
- open '(project folder)/node_modules/pdfmake/' in terminal, then run 'npm install'
- run 'gulp buildFonts'. (will see Thai font name in 'pdfmake/build/vfs_fonts.js')
- add fonts to pdfMake
pdf.fonts = {
THSarabunNew: {
normal: 'THSarabunNew.ttf',
bold: 'THSarabunNew-Bold.ttf',
italics: 'THSarabunNew-Italic.ttf',
bolditalics: 'THSarabunNew-BoldItalic.ttf'
},
Roboto: {
normal: 'Roboto-Regular.ttf',
bold: 'Roboto-Medium.ttf',
italics: 'Roboto-Italic.ttf',
bolditalics: 'Roboto-MediumItalic.ttf'
}
};
Declare enum does not create at run time. https://lukasbehal.com/2017-05-22-enums-in-declaration-files/
So, fixed @types/pdfmake/index.d.ts with const enum
- enum PageSize --> const enum PageSize
- enum PageOrientation --> const enum PageOrientation