raiblaze / vue3-html2pdf

71 stars 18 forks source link

SyntaxError: The requested module '/node_modules/html2pdf.js/node_modules/jspdf/dist/jspdf.min.js?v=f2489bd3' does not provide an export named 'default' #1

Open Ndaboom opened 2 years ago

Ndaboom commented 2 years ago

When I reload the page after including the package I get this bug.

Thanks in advance for your help.

Shamzic commented 2 years ago

Get the same error with vue & vite.

This package is not working.

Tusko commented 2 years ago

the same

nevsie commented 2 years ago

Same...

soumen-grmtech commented 2 years ago

getting the same error, any solution for this, using vue3 & vite

Ryo-S-hub commented 2 years ago

Help!...

Tusko commented 2 years ago
import * as pdfFonts from "pdfmake/build/vfs_fonts";
import pdfMake from "pdfmake";
import htmlToPdfmake from "html-to-pdfmake";

...

setup(){
....
 const pdfTable = document.getElementById("pdf-content");
        var html = htmlToPdfmake(pdfTable.innerHTML);
        const documentDefinition = { content: html };

        pdfMake.vfs = pdfFonts?.pdfMake?.vfs;
        pdfMake.createPdf(documentDefinition).open();
....
}
Ryo-S-hub commented 2 years ago

!!! Thank you🙇‍♂️ I wrote just the same code using pdfmake to get around this problem! Currently, It looks like this is the only way to make PDF with vue.js...

ekwoster commented 2 years ago

Thanks @Tusko

dalmia commented 1 year ago

If anyone came here looking for a solution for NuxtV3, I was able to use the base package html2pdf directly by defining a custom plugin. I have explained my answer here.

Hope it helps!

vheins commented 1 year ago

any update?

Tusko commented 1 year ago

@vheins pls check https://github.com/raiblaze/vue3-html2pdf/issues/1#issuecomment-1217961468

vheins commented 1 year ago

@vheins pls check https://github.com/raiblaze/vue3-html2pdf/issues/1#issuecomment-1217961468

Thanks

kemalyilmaz77 commented 1 year ago

If you add jspdf in component for vite, the problem is solved, you can run the dev operating system import jsPDF from 'jspdf' import Vue3Html2pdf from 'vue3-html2pdf'

RubenHoek commented 1 year ago

@vheins pls check #1 (comment)

So we cannot use this package if i understand correct?

dhallX commented 1 year ago

will this be fixed any time soon?

secmofo commented 1 year ago

I am trying to use it with vuetify3 and having the same issues

vheins commented 1 year ago

I am trying to use it with vuetify3 and having the same issues

try this

<script>
import html2pdf from 'html2pdf.js';
export default {
    methods: {
        generatePdf() {
            html2pdf().from(this.$refs.html2Pdf).set({
                margin: [0.5, 0, 0.5, 0],
                filename: 'yourfile.pdf',
                enableLinks: false,
                image: { type: 'jpeg', quality: 0.98 },
                html2canvas: { scale: 2 },
                jsPDF: { unit: 'cm', format: 'a4', orientation: 'portrait' },
                pagebreak: { mode: ['css', 'legacy'] }
            }).toPdf().get('pdf').then(function (pdf) {
                window.open(pdf.output('bloburl'), '_blank').print();
            });
        },
    }
}
</script>

<template>
    <div ref="html2Pdf">
     your code here
    </div>

    <button @click="generatePdfStockOpname">
        Click Here
    </button>
</template>
WestynD commented 1 year ago

That code works for me, but I was getting errors when trying to convert it to work with script setup. I would prefer to get it working in setup to match the rest of my project. Any suggestions?

matteorchard commented 1 year ago

If you add jspdf in component for vite, the problem is solved, you can run the dev operating system import jsPDF from 'jspdf' import Vue3Html2pdf from 'vue3-html2pdf' @tarja77

This implies installing it, and it doesn't solve the issue for me. Do you have more details about this solution?

arnonrdp commented 1 year ago

I just upgraded from Vue 2 to Vue 3 (from Webpack to Vite as well) and now I'm having this issue.

I also noticed when you comment the element to load the page and then uncomment it back it says:

Failed to resolve component: vue3-html2pdf
If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement.

When I call the function, the message is:

Uncaught (in promise) TypeError: this.$refs.html2Pdf.generatePdf is not a function
    at Proxy.downloadPDFReport

@Ndaboom, did you fix this? @raiblaze, any ideas?


EDIT:

I fixed by installing jsPDF dependency. I didn't need to import it into any file (which I found very strange).

I believe this fix could come directly here from the repository.

tranmanhhungdn1201 commented 1 year ago

import html2pdf from 'html2pdf.js'; import Vue3Html2pdf from 'vue3-html2pdf';

It works

kriem2000 commented 1 year ago

import html2pdf from 'html2pdf.js'; import Vue3Html2pdf from 'vue3-html2pdf';

It works

yup it works..

ekoeryanto commented 1 year ago

optimizeDeps: { include: ['jspdf'], },

iomilovanderpas commented 1 year ago

optimizeDeps: { include: ['jspdf'], }, This solution works for Vue 3 and vite. You will need to install the following packages npm install html2pdf.js and npm install vue3-html2pdf.

optimizeDeps: {
include: ["jspdf"],
},

has to be placed inside the vite.config.ts file.

romiardisaja commented 1 year ago

If you add jspdf in component for vite, the problem is solved, you can run the dev operating system import jsPDF from 'jspdf' import Vue3Html2pdf from 'vue3-html2pdf'

worked for me, thx