当我单击按钮时,我正在尝试将div导出为pdf,但是遇到无法解决的javascript函数错误,有人可以帮助我吗?
JavaScript
<script language="javascript">
var cache_width = $('#renderPDF').width(); //Criado um cache do CSS
var a4 = [595.28, 841.89]; // Widht e Height de uma folha a4
$("#btnPrint").live("click", function () {
// Setar o width da div no formato a4
$("#renderPDF").width((a4[0] * 1.33333) - 80).css('max-width', 'none');
// Aqui ele cria a imagem e cria o pdf
html2canvas($('#renderPDF'), {
onrendered: function (canvas) {
var img = canvas.toDataURL("image/png", 1.0);
var doc = new jsPDF({ unit: 'px', format: 'a4' });
doc.addImage(img, 'JPEG', 20, 20);
doc.save('NOME-DO-PDF.pdf');
//Retorna ao CSS normal
$('#renderPDF').width(cache_width);
}
});
});
</script>
HTML
<div class="table-responsive panel" id="renderPDF">
<table class="table">
<tbody>
<tr>
<td class="text-success"><i class="fa fa-list-ol"></i> Cliente ID</td>
<td>@Model.ID_Cliente</td>
</tr>
<tr>
<td class="text-success"><i class="fa fa-user"></i> Nome</td>
<td>@Model.Nome</td>
</tr>
<tr>
<td class="text-success"><i class="fa fa-home"></i> Morada</td>
<td>@Model.Morada</td>
</tr>
</tbody>
</table>
</div>
答案 0 :(得分:0)
@IBAction func circleRadiusChanged(_ sender: UISlider) {
// Clear previous circle and create new one with updated radius
mapView.removeOverlays(mapView.overlays)
self.radius = circleSlider.value
drawCircle()
radiusTextView.text = "\(Int(radius)) KM"
}
func drawCircle() {
let circleRadius = CLLocationDistance(self.radius * 1000)
let circleRadiusx2 = CLLocationDistance(self.radius * 1000 * 2 + 300)
let circle = MKCircle(center: circleCenter!, radius: circleRadius)
mapView.add(circle)
// Set the correct zoom based on circle radius
let region = MKCoordinateRegionMakeWithDistance(circleCenter!, circleRadiusx2, circleRadiusx2);
mapView.setRegion(region, animated: true)
}
方法已过时,可能已在您的jQuery版本中删除。
尝试改用live
。
答案 1 :(得分:0)
您正在使用哪个版本的jquery? .live已从病房的1.9版中删除。
$(document).on("click", '#btnPrint', function () {
// Setar o width da div no formato a4
$("#renderPDF").width((a4[0] * 1.33333) - 80).css('max-width', 'none');
// Aqui ele cria a imagem e cria o pdf
html2canvas($('#renderPDF'), {
onrendered: function (canvas) {
var img = canvas.toDataURL("image/png", 1.0);
var doc = new jsPDF({ unit: 'px', format: 'a4' });
doc.addImage(img, 'JPEG', 20, 20);
doc.save('NOME-DO-PDF.pdf');
//Retorna ao CSS normal
$('#renderPDF').width(cache_width);
}
});
});