[Vuejs]-Vue.js generate pdf with html content

1👍

This can be achieve with the jspdf library

http://raw.githack.com/MrRio/jsPDF/master/examples/html2pdf/showcase_supported_html.html

Example code:

<div id="html">My HTML</div>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js"></script>

<script>
    var pdf = new jsPDF('p', 'pt', 'a4');
    pdf.html(document.getElementById('html'), {
        callback: function (pdf) {
            pdf.save('a4.pdf');
        }
    });
</script>

0👍

as below example you can downwload the pdf with html in vue.js

<div ref="content">
  <h1> hello wolrd ! </h1>
</div>

downloadPDF() {
const doc = new jsPDF('p', 'pt', 'a4');
          doc.html(this.$refs.content.innerHTML, {
          callback: function (doc) {
            doc.save('op.pdf');
          },
          x: 10,
          y: 10,
          
        });}

Leave a comment