Setup
Add pdfMake to your Nuxt project easily with this module.
Installation
- Add
nuxt-pdfmake
dependency to your project
npm
npm install -D nuxt-pdfmake
- Add
nuxt-pdfmake
to themodules
section ofnuxt.config.js
nuxt.config.js
export default defineNuxtConfig({
modules: [
'nuxt-pdfmake'
]
})
- Extract the
$pdfMake
instance from theuseNuxtApp
composable & use it in your functions!
โจ Well done! You can now print/download PDFs directly in the browser.
Usage
To use the module, simply add it into your function by extracting it from the useNuxtApp
composable:
pages/index.vue
const exportData = () =>{
const { $pdfMake } = useNuxtApp();
const docDefinition = {
content: [
'First paragraph',
'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
]
};
$pdfMake.createPdf(docDefinition).open();
}
Table of Contents