Search code examples
vue.jsjspdfhtml2canvashtml2pdf

Vuejs + vue-html2pdf: window is not defined


I can't get the plugin to work. As stated in these instructions, I imported vue-html2pdf in my vue component:

import VueHtml2pdf from 'vue-html2pdf

I registered it in my component's components list:

components: { VueHtml2pdf }

Here's my methods:

methods: { 
  generatePDF () { 
    if (process.browser) { 
      this.$refs.html2Pdf.generatePdf() 
    } 
  } 
}

Here's my template:

<v-btn class="mt-5" @click="generatePDF">
Télécharger le catalogue
</v-btn>

<client-only>
  <vue-html2pdf
    ref="html2Pdf"
    :enable-download="true"
    filename="hee hee"
    :manual-pagination="false"
  >
    <section slot="pdf-content">
      <!-- PDF Content Here -->
    </section>
  </vue-html2pdf>
</client-only>

but I get this error:

window is not defined

What am I missing here please ? One answer to this could save my job, any help would be appreciated...

Here's a screenshot:

enter image description here

Package Version "vue-html2pdf": "^1.8.0",


Solution

  • As stated here, I directly used html2pdf (without the vue wrapper) and everything worked fine.

    Hop this will help someone !