Created
November 29, 2020 16:34
-
-
Save zerojame/a604b7239b97e301b5fbc344ccda4bb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div id="app"></div> | |
</template> | |
<script> | |
import pdfMake from 'pdfmake' | |
import pdfFonts from './assets/custom-fonts.js' // 1. import custom fonts | |
export default { | |
name: 'App', | |
mounted() { | |
this.export() | |
}, | |
methods: { | |
export () { | |
pdfMake.vfs = pdfFonts.pdfMake.vfs // 2. set vfs pdf font | |
pdfMake.fonts = { | |
// download default Roboto font from cdnjs.com | |
Roboto: { | |
normal: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-Regular.ttf', | |
bold: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-Medium.ttf', | |
italics: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-Italic.ttf', | |
bolditalics: 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-MediumItalic.ttf' | |
}, | |
// Kanit Font | |
Kanit: { // 3. set Kanit font | |
normal: 'Kanit-Regular.ttf', | |
bold: 'Kanit-Medium.ttf', | |
italics: 'Kanit-Italic.ttf', | |
bolditalics: 'Kanit-MediumItalic.ttf' | |
} | |
} | |
const docDefinition = { | |
content: [ | |
'English', | |
'ไทย' | |
], | |
defaultStyle: { // 4. default style 'KANIT' font to test | |
font: 'Kanit' | |
} | |
} | |
pdfMake.createPdf(docDefinition).open({}, window) | |
} | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment