introduction

Options

Learn more about the options that can be passed to the Nuxt pdfMake module.

Default Options

This module will by default inject 2 composables & plugin into your app. This behaviour can be adjusted by passing options to the module.

nuxt.config.js
export default defineNuxtConfig({
  //These are the default options
  pdfmake:{
  /**
   * Enable the module
   * @default true
   */
  enabled: true;
  /**
   * Enable the composable injection. This adds both the `usePDFMake` & `useFontPresets` composables
   * @default true
   */
  enableComposable: true;
  /**
   * Enable the devtools tab
   * @default true
   */
  enableDevtools: true;
  }
});

Font Presets

The module adds a new composable to your app called useFontPresets. This composable allows you to easily add fonts to your pdfs.

pages/index.vue
const exportComposable = () => {
  const pdfMake = usePDFMake();
  pdfMake.createPdf(docDef, tableLayoutDef, useFontPresets()).open();
};

You can also use a specific font from the set like so:

pages/index.vue
const exportData = () => {
  const pdfMake = usePDFMake();
  pdfMake.createPdf(docDef, tableLayoutDef, { Inter: useFontPresets().Inter }).open();
};

Currently, I only need these 4 fonts 😂. Feel free to add your own fonts by following the guide here.

Current Fonts

  • Inter
  • Roboto
  • Poppins
  • Lora

This is what the full signature of createPdf looks like:

// The full signature of createPdf looks like this.
// tableLayouts, fonts and vfs are all optional - falsy values will cause the default values to be used.
pdfMake.createPdf(docDefinition, tableLayouts, fonts, vfs);