JSFiddle - React, Tailwind, and code Playground
by Rapha Souza
HTML
<script src="https://code.jquery.com/jquery-3.4.1.slim.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jsPDF Save PDF with Custom Filename in Javascript</title>
</head>
<body>
<h1>jsPDF Save PDF with Custom Filename</h1>
<form id="form">
<input type="text" id="text" placeholder="Enter the text" required/>
<input type="text" placeholder="Enter Filename" id="filename" value="output" required/>
<button>Save PDF Document</button>
</form>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.5/jspdf.min.js"></script>
</html>
JavaScript
let form = document.getElementById('form')
form.addEventListener('submit',(e) => {
e.preventDefault()
let text = `<p> Carro</p>`
let filename = document.getElementById('filename').value
let doc = new jsPDF()
doc.html(text,10,10)
// save pdf with custom filename
doc.save(filename + ".pdf")
})