我已经包含以下文件:
<script type="text/javascript" src="libs/png_support/zlib.js"></script> <script type="text/javascript" src="libs/png_support/png.js"></script> <script type="text/javascript" src="jspdf.plugin.addimage.js"></script> <script type="text/javascript" src="jspdf.plugin.png_support.js"></script> <script type="text/javascript" src="jspdf/jspdf.plugin.standard_fonts_metrics.js"></script> <script type="text/javascript" src="jspdf/jspdf.plugin.split_text_to_size.js"></script> <script type="text/javascript" src="jspdf/jspdf.plugin.from_html.js"></script> <script type="text/javascript" src="jspdf.js"></script>
而我只是测试它是否可以通过html呈现图像:
var doc = new jsPDF(); var elementHandler = { '#ignorePDF': function (element,renderer) { return true; } }; var source = '<img src="/assets/common/image/BG.jpg"/>'; doc.fromHTML( source,15,{ 'width': 180,'elementHandlers': elementHandler }); doc.output("dataurlnewwindow");
它会在控制台上抛出此错误,其中说:
jsPDF Warning: rendering issues? provide a callback to fromHTML! (anonymous function)
我使用过PNG格式,因为它不起作用我也试过JPG格式,仍然没有运气!
我究竟做错了什么?
提前致谢.
解决方法
还有一个关于fromHTML()的论据
doc.fromHTML( source,{ 'width': 180,'elementHandlers': elementHandler },function(dispose) { // dispose: object with X,Y of the last line add to the PDF // this allow the insertion of new lines after html // pdf.save('Test.pdf'); if (navigator.msSaveBlob) { var string = doc.output('datauristring'); } else { var string = doc.output('bloburi'); } $('.previewIFRAME').attr('src',string); })