I am new with Vue.js, and I am trying to generate a PDF, but I have no idea how to do it.
This is what I have:
import * as jsPDF from "jspdf" export default { props: ['id'], methods: { pdf () { const doc = new jsPDF() } } }
Error:
Property or method "pdf" is not defined on the instance but referenced during render
To get started, first install html2pdf. js and its dependencies using npm by running npm install --save html2pdf. js in your terminal. export default { name: 'app', methods: { exportToPDF() { html2pdf(document.
Generate PDF using JavaScriptSpecify the content in text() method of jsPDF object. Use the addPage() method to add new page to PDF. Use the save() method to generate and download PDF file.
What is jsPDF? jsPDF is an open-source library for generating PDF documents using JavaScript. It provides multiple options to generate PDF files, with custom properties. It has numerous plugins to support various ways of PDF generation.
First import the PDF library as:
import jsPDF from 'jspdf'
Then simply instantiate the object and give it the contents:
methods: { createPDF () { let pdfName = 'test'; var doc = new jsPDF(); doc.text("Hello World", 10, 10); doc.save(pdfName + '.pdf'); } }
Make sure to read the documentation for more
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With