Iam尝试从html转换为pdf转换。所以我在我的项目中使用jspdf插件
<script type="text/javascript" src="../../../../resources/jspdf/html2canvas.js"></script>
<script type="text/javascript" src="../../../../resources/jspdf/jspdf.js"></script>
<script type="text/javascript" src="../../../../resources/jspdf/jspdf.plugin.addimage.js"></script>
<script type="text/javascript" src="../../../../resources/jspdf/jspdf.plugin.cell.js"></script>
<script type="text/javascript" src="../../../../resources/jspdf/jspdf.plugin.from_html.js"></script>
<script type="text/javascript" src="../../../../resources/jspdf/jspdf.plugin.ie_below_9_shim.js"></script>
<script type="text/javascript" src="../../../../resources/jspdf/jspdf.plugin.javascript.js"></script>
<script type="text/javascript" src="../../../../resources/jspdf/jspdf.plugin.sillysvgrenderer.js"></script>
<script type="text/javascript" src="../../../../resources/jspdf/jspdf.plugin.split_text_to_size.js"></script>
<script type="text/javascript" src="../../../../resources/jspdf/jspdf.plugin.standard_fonts_metrics.js"></script>
<script type="text/javascript" src="../../../../resources/jspdf/jspdf.PLUGINTEMPLATE.js"></script>
<script type="text/javascript" src="../../../../resources/jspdf/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var specialElementHandlers = {
'#editor': function (element,renderer) {
return true;
}
};
$('#generatePdf').click(function () {
var doc = new jsPDF();
var source = $('#cisForm').html();
var specialElementHandlers = {
'#bypassme': function (element, renderer) {
return true;
}
};
/*doc.fromHTML(source, 0.5, 0.5, {
'width': 75,'elementHandlers': specialElementHandlers
});
*/
doc.addHTML($('body'), function () {
doc.save('Test.pdf');
});
doc.output("dataurlnewwindow");
});
});
</script>
在我尝试使用doc.fromHTML()之前。
我已经从canvas js更改为doc.addHTML(),因为不支持css。
但是现在我得到错误
Uncaught TypeError: doc.addHTML is not a function
这里有什么问题。它适用于css文件
答案 0 :(得分:0)
您需要先导入html2canvas文件!
>>> # Estimate the probability of getting 5 or more heads from 7 spins
>>> # of a biased coin that settles on heads 60% of the time.
>>> trial = lambda: choices('HT', cum_weights=(0.60, 1.00), k=7).count('H') >= 5
>>> sum(trial() for i in range(10000)) / 10000
0.4169