I'm working on a project that needs to transform a HTML page into a PDF file. I'm using the jsPDF plugin. There are many examples of how to convert htmls to pdf, "but" , all the examples I saw, only use text tag as p - h1 - span
. My problem is that the data I want to convert into PDF is inside a form. When I download the file, only h1
and label
of the form appear, but the input values are not rendered in the PDF file. Would anyone know how to bring the entered values into the inputs as well? If that exists as.
function Pdf() {
var pdf = new jsPDF('p', 'pt', 'letter');
pdf.fromHTML($("#myBody")[0], 15, 15, {
'width': 210
});
pdf.save('PDF.pdf');
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.debug.js"></script>
<script src="https://cdn.rawgit.com/MrRio/jsPDF/master/libs/html2pdf.js"></script><divclass="container" style="margin-top:20px">
<form action="#" method="Post" id="form" style="margin-left:15px">
<h1 class="text-center" style="text-decoration:underline">FORMULÁRIO</h1><br><br>
<div class="form-row">
<div class="form-group col-md-6">
<label for="email">Email: </label>
<input type="email" class="form-control" id="email" placeholder="Email">
</div>
<div class="form-group col-md-6">
<label for="tel">Telefone: </label>
<input type="tel" class="form-control" id="tel" placeholder="Digite o telefone">
</div>
<div class="form-group col-md-12">
<label for="ender">Endereço: </label>
<input type="text" class="form-control" id="ender" placeholder="Digite o endereço">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="cidade">Cidade: </label>
<input type="text" class="form-control" id="cidade">
</div>
<div class="form-group col-md-4">
<label for="estado">Estado: </label>
<select id="estado" class="form-control">
<option selected>Escolha</option>
<option>SP</option>
<option>RJ</option>
<option>MG</option>
</select>
</div>
<div class="form-group col-md-4">
<label for="cep">Cep: </label>
<input type="text" class="form-control" id="cep">
</div>
</div>
</form>
<input type="button" value="DOWNLOAD" class="btn btn-primary" id="btn" onclick="Pdf()">
</div>