Skip to content

Instantly share code, notes, and snippets.

@Thainainan03
Created November 29, 2020 16:55
Show Gist options
  • Save Thainainan03/133c3220201a7e8f4d090de0a9c89137 to your computer and use it in GitHub Desktop.
Save Thainainan03/133c3220201a7e8f4d090de0a9c89137 to your computer and use it in GitHub Desktop.
<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