Setup

Add pdfMake to your Nuxt project easily with this module.

Installation

  1. Add nuxt-pdfmake dependency to your project
npm
npm install -D nuxt-pdfmake
yarn
yarn add --dev nuxt-pdfmake
  1. Add nuxt-pdfmake to the modules section of nuxt.config.js
nuxt.config.js
export default defineNuxtConfig({
  modules: [
    'nuxt-pdfmake'
  ]
})
  1. Extract the $pdfMake instance from the useNuxtApp 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