<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Base64/1.0.1/base64.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.min.js"></script>
<script>
$(document).ready(function (){
function getBase64Image(img) {
var canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
var dataURL = canvas.toDataURL("image/jpeg");
return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
}
var img = new Image();
img.onload = function(){
var dataURI = getBase64Image(img);
return dataURI;
}
img.src = "mifoto.jpg";
$('#cmd').click(function () {
var specialElementHandlers =
function (element,renderer) {
return true;
}
var doc = new jsPDF();
doc.fromHTML($('#content').html(), 15, 15, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.addImage(img.onload(), 'JPEG', 15, 40, 100, 100);
doc.output('datauri');
});
});
</script>
</head>
<body id="target" >
<div id="content">
<h3>Hola mundo</h3>
<p>Esto es otro texto para meter en el PDF</p>
</div>
<img src="http://www.midominio.com/pruebas/pdf/mifoto.jpg">
<div id="editor"></div>
<button id="cmd">generar el PDF</button>
</body>
</html>
JS: Crear PDF incluso con imágenes con jspdf
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario