Skip to content

Latest commit

 

History

History
59 lines (44 loc) · 1.56 KB

README.md

File metadata and controls

59 lines (44 loc) · 1.56 KB

PdfExport

This project was generated with Angular CLI version 8.2.0.

Install pdfMake

npm install pdfmake  --save

Import pdfMake and pdfFonts

import * as pdfMake from 'pdfmake/build/pdfmake';
import * as pdfFonts from 'pdfmake/build/vfs_fonts';

const pdf = pdfMake;
pdf.vfs = pdfFonts.pdfMake.vfs;

Add Thai fonts

  1. go to '(project folder)/node_modules/pdfmake/'
  2. create 'examples/fonts' folder
  3. copy Roboto and Thai fonts ('src/assets/fonts')
  4. open '(project folder)/node_modules/pdfmake/' in terminal, then run 'npm install'
  5. run 'gulp buildFonts'. (will see Thai font name in 'pdfmake/build/vfs_fonts.js')
  6. 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'
  }
};

Fixed bugs

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

Reference