Created
November 29, 2020 16:55
-
-
Save zerojame/133c3220201a7e8f4d090de0a9c89137 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' | |
export default { | |
name: 'App', | |
mounted() { | |
this.export() | |
}, | |
methods: { | |
export () { | |
pdfMake.vfs = pdfFonts.pdfMake.vfs | |
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: { | |
normal: 'Kanit-Regular.ttf', | |
bold: 'Kanit-Medium.ttf', | |
italics: 'Kanit-Italic.ttf', | |
bolditalics: 'Kanit-MediumItalic.ttf' | |
}, | |
// Icon Font | |
Fontello: { | |
normal: 'fontello.ttf', | |
bold: 'fontello.ttf', | |
italics: 'fontello.ttf', | |
bolditalics: 'fontello.ttf' | |
} | |
} | |
const docDefinition = { | |
content: [ | |
'English', | |
'ไทย', | |
{ | |
text: '', | |
style: 'icon' | |
} | |
], | |
styles: { | |
icon: { font: 'Fontello' }, | |
}, | |
defaultStyle: { | |
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