I want to add 2 images to mine pdfwhen I click the create-pdf icon. The first image is a canvas that converts to an image and works correctly.
var canvas = document.getElementsByClassName("jade-schematic-diagram");
img = canvas[0].toDataURL("image/png");
img.id="pic2";
doc = new jsPDF({
unit:'px',
format:'a4'
});
doc.addImage(img, 'JPEG', 20, 20,400,150);
This section of my code received this error:
Error: incomplete or corrupt PNG file
var srcpath;
var element = $(".plot-waveforms");
var imgageData = new Image();
imgageData.id = "pic";
html2canvas(element, {
onrendered: function (canvas) {
srcpath = canvas.toDataURL("image/png");
}
});
imgageData.src=srcpath;
doc.addImage(imgageData , 'PNG', 20, 20,400,150);
I added these script to my html head tag.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.rawgit.com/niklasvh/html2canvas/0.5.0-alpha2/dist/html2canvas.min.js"></script>
<script type="text/javascript" src="//cdn.rawgit.com/MrRio/jsPDF/master/dist/jspdf.min.js"></script>
<script type="text/javascript" src="zlib.js"></script>
<script type="text/javascript" src="png.js"></script>
<script type="text/javascript" src="addimage.js"></script>
<script type="text/javascript" src="png_support.js"></script>
Please help me. I searched a lot, but found nothing.
source
share