Open Ndaboom opened 2 years ago
Get the same error with vue & vite.
This package is not working.
the same
Same...
getting the same error, any solution for this, using vue3 & vite
Help!...
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();
....
}
!!! 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...
Thanks @Tusko
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!
any update?
@vheins pls check https://github.com/raiblaze/vue3-html2pdf/issues/1#issuecomment-1217961468
Thanks
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'
@vheins pls check #1 (comment)
So we cannot use this package if i understand correct?
will this be fixed any time soon?
I am trying to use it with vuetify3 and having the same issues
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>
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?
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?
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?
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.
import html2pdf from 'html2pdf.js'; import Vue3Html2pdf from 'vue3-html2pdf';
It works
import html2pdf from 'html2pdf.js'; import Vue3Html2pdf from 'vue3-html2pdf';
It works
yup it works..
optimizeDeps: { include: ['jspdf'], },
optimizeDeps: { include: ['jspdf'], }, This solution works for Vue 3 and vite. You will need to install the following packages
npm install html2pdf.js
andnpm install vue3-html2pdf
.optimizeDeps: { include: ["jspdf"], },
has to be placed inside the vite.config.ts file.
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
When I reload the page after including the package I get this bug.
Thanks in advance for your help.