Creating PDF with html2canvas using Vue 3 | Creando un PDF con html2canvas usando Vue 3

Posted by

How to create pdf html2canvas with Vue 3

const { ref, onMounted } = Vue;

const app = {
setup() {
const generatePdf = () => {
html2canvas(document.querySelector(“#app”), {
scale: 2
}).then(canvas => {
const pdf = new jsPDF(‘p’, ‘mm’, ‘a4’);

pdf.addImage(canvas.toDataURL(‘image/png’), ‘PNG’, 0, 0, 210, 297);
pdf.save(‘example.pdf’);
});
}

return {
generatePdf
};
}
}

Vue.createApp(app).mount(‘#app’);

0 0 votes
Article Rating
3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@mellorafael
6 months ago

great job!

@036nurarifin2
6 months ago

please tutorial preview before download

@giovanni.ferrari
6 months ago

thanks! this was very useful for me! I couldnt have vue-html2canvas work for me so this saved my life