0

Is there some chance to generate PDF from HTML content. I mean something like print to PDF. I need to use very difficult html with technical draws (absolute positions, etc) and I need to take whole Vue file template and generate PDF.

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

Comments

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,
          
        });}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.