1
Body of html:
<div id="content">
<div class="table-responsive" >
<table class="table">';
while($row = mysqli_fetch_array($result))
{
$output .= '
<div class="modal-body">
<div class="table-responsive">
<form id="insert_form">
<div class="form-group input-group">
<span class="input-group-addon">
<span class="fa fa-code"></span>
</span>
<input type="text" id="codigo1" name="codigo" value="'.$row["codigo"].'" class="form-control" readonly="true"/>
</div>
<div class="form-group input-group">
<span class="input-group-addon">
<span class="glyphicon glyphicon-user"></span>
</span>
<input type="text" id="nome1" name="nome" value="'.$row["nome"].'" class="form-control" readonly="true"/>
</div>
<div class="form-group input-group">
<span class="input-group-addon">
<span class="fa fa-birthday-cake"></span>
</span>
<input type="text" id="data1" name="data" value="'.$row["data"].'" class="form-control" readonly="true"/>
</div>
<div class="form-group input-group">
<span class="input-group-addon">
<span class="fa fa-calendar"></span>
</span>
<input type="text" id="admissao1" name="admissao" value="'.$row["admissao"].'" class="form-control" readonly="true"/>
</div>
<div class="form-group input-group">
<span class="input-group-addon">
<span class="glyphicon glyphicon-info-sign"></span>
</span>
<input type="text" id="dependencia1" name="dependencia" value="'.$row["Dependencia"].'" class="form-control" readonly="true"/>
</div>
<div class="form-group input-group">
<span class="input-group-addon">
<span class="teste">Ajudas Técnicas</span>
</span>
<div class="funkyradio">
<div class="grid-container">
<div class="funkyradio-success grid-item">
<input type="checkbox" name="tecnicas" id="tecnicas2" Value="Sim" ' . ( ($row["tecnicas"]=='Sim') ? 'checked' : '' ) .' readonly="true">
<label for="tecnicas">Sim</label>
</div>
<div class="funkyradio-primary grid-item">
<input type="checkbox" name="tecnicas" id="tecnicas3" Value="Não" ' . ( ($row["tecnicas"]=='Não') ? 'checked' : '' ) .' readonly="true">
<label for="tecnicas1">Não </label>
</div>
</div>
<span class="input-group-addon">
<span>Qual/Quais</span>
</span>
</div>
</span>
<input type="text" class="form-control" id="qual1" name="qual" value="'.$row["qual"].'" class="form-control" readonly="true">
</div>
<div class="modal-footer" >
<button type="button" class="btn btn-danger" data-dismiss="modal">Cancelar</button>
<a type="button" name="edit" id="'.$row["Id"].'" data-toggle="modal" href="#add_data_Modal" class="btn btn-primary edit_data">Editar</a>
</div>
</form>
</div>
</div>
';
}
$output.= '
</table>
</div>
</div>
';
Script:
<script>
function demoFromHTML() {
var pdf = new jsPDF('p', 'pt', 'letter');
source = $('#content')[0];
specialElementHandlers = {
'#bypassme': function (element, renderer) {
return true
}
};
margins = {
top: 80,
bottom: 60,
left: 40,
width: 522
};
pdf.fromHTML(
source,
margins.left,
margins.top, {
'width': margins.width,
'elementHandlers': specialElementHandlers
},
function (dispose) {
pdf.save('Test.pdf');
},
margins
);
}
</script>
Here I have the button to generate the pdf:
<button class="btn btn-info" onclick="javascript:demoFromHTML();">
<span class="glyphicon glyphicon-print"></span>
</button>
Generates the pdf, but the pdf is blank, does not receive the html data.
thanks for the help. I am using the solution you presented, but then as I call this example you put in the button to generate the pdf?
– Bruno
@Bruno I will already edit the code for the precautionary issue.
– Cristiano Gilberto João
just one more thing, on this line
const html_source = document.getElementById('content');
I can use the form id, right?– Bruno
Yes! You can use the form id if it is the element you want to print in PDF
– Cristiano Gilberto João
@Bruno Veja this answer Mount PDF via website maybe it can help you.
– Cristiano Gilberto João
implemented as said and the result of the pdf is this link, but if you put the div with id=content generates the blank pdf
– Bruno
Let’s go continue this discussion in chat.
– Cristiano Gilberto João
Have you found a solution to this situation ?
– Gato de Schrödinger