admin管理员组文章数量:1026925
in my nuxt project ı want to convert my html poenent to pdf. when clicked button ı want to convert poenent with all color to pdf.
import {jsPDF} from 'jspdf'
export default {
data() {
return {
margins : { top: 80, bottom: 60, left: 40, width: 522 } }
},
methods: {
generatePdf() {
const doc = new jsPDF('p', 'pt', 'A4');
doc.fromHTML(this.$refs.testHtml, this.margins.left, this.margins.top,{
'width' : this.margins.width
});
doc.save('test.pdf');
}
}
}
in here , the problem is about doc.fromHTML. in many project this way is valid but in nuxt doc.fromHTML doesnt work . it gives error.
in my nuxt project ı want to convert my html poenent to pdf. when clicked button ı want to convert poenent with all color to pdf.
import {jsPDF} from 'jspdf'
export default {
data() {
return {
margins : { top: 80, bottom: 60, left: 40, width: 522 } }
},
methods: {
generatePdf() {
const doc = new jsPDF('p', 'pt', 'A4');
doc.fromHTML(this.$refs.testHtml, this.margins.left, this.margins.top,{
'width' : this.margins.width
});
doc.save('test.pdf');
}
}
}
in here , the problem is about doc.fromHTML. in many project this way is valid but in nuxt doc.fromHTML doesnt work . it gives error.
Share Improve this question edited Jan 28, 2021 at 3:47 Zac Anger 7,8172 gold badges20 silver badges47 bronze badges asked Jan 27, 2021 at 19:46 user11083200user11083200 1- thx for editing my question but my priority is an answer for my question not editing – user11083200 Commented Jan 28, 2021 at 5:39
3 Answers
Reset to default 4I'm late but someone can use this solution.
Use this method:
printReport() {
window.print();
},
<button onClick="printReport">Print !</button>
If you want to hide somthing when printing, use this in CSS.
@media print {
.no-printme {
display: none !important;
}
.printme {
display: block;
}
}
use vue-html2pdf npm package this will solve your problem and also internally it uses jspdf, so you will get its configuration.
https://www.npmjs./package/vue-html2pdf
vue-html2pdf npm module does not work properly. Rather than you can try html2pdf module for convert html to pdf in vuejs.
Package link: https://www.npmjs./package/html2pdf.js/v/0.9.1
in my nuxt project ı want to convert my html poenent to pdf. when clicked button ı want to convert poenent with all color to pdf.
import {jsPDF} from 'jspdf'
export default {
data() {
return {
margins : { top: 80, bottom: 60, left: 40, width: 522 } }
},
methods: {
generatePdf() {
const doc = new jsPDF('p', 'pt', 'A4');
doc.fromHTML(this.$refs.testHtml, this.margins.left, this.margins.top,{
'width' : this.margins.width
});
doc.save('test.pdf');
}
}
}
in here , the problem is about doc.fromHTML. in many project this way is valid but in nuxt doc.fromHTML doesnt work . it gives error.
in my nuxt project ı want to convert my html poenent to pdf. when clicked button ı want to convert poenent with all color to pdf.
import {jsPDF} from 'jspdf'
export default {
data() {
return {
margins : { top: 80, bottom: 60, left: 40, width: 522 } }
},
methods: {
generatePdf() {
const doc = new jsPDF('p', 'pt', 'A4');
doc.fromHTML(this.$refs.testHtml, this.margins.left, this.margins.top,{
'width' : this.margins.width
});
doc.save('test.pdf');
}
}
}
in here , the problem is about doc.fromHTML. in many project this way is valid but in nuxt doc.fromHTML doesnt work . it gives error.
Share Improve this question edited Jan 28, 2021 at 3:47 Zac Anger 7,8172 gold badges20 silver badges47 bronze badges asked Jan 27, 2021 at 19:46 user11083200user11083200 1- thx for editing my question but my priority is an answer for my question not editing – user11083200 Commented Jan 28, 2021 at 5:39
3 Answers
Reset to default 4I'm late but someone can use this solution.
Use this method:
printReport() {
window.print();
},
<button onClick="printReport">Print !</button>
If you want to hide somthing when printing, use this in CSS.
@media print {
.no-printme {
display: none !important;
}
.printme {
display: block;
}
}
use vue-html2pdf npm package this will solve your problem and also internally it uses jspdf, so you will get its configuration.
https://www.npmjs./package/vue-html2pdf
vue-html2pdf npm module does not work properly. Rather than you can try html2pdf module for convert html to pdf in vuejs.
Package link: https://www.npmjs./package/html2pdf.js/v/0.9.1
本文标签:
版权声明:本文标题:javascript - How to convert html component to pdf print in nuxt js projects - doc.fromHTML true usage - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745652693a2161413.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论