如果电脑没有连接打印机,则会导出包含内容的pdf文件,打印页面内指定内容:
html页面:
<button type="button" οnclick="exportpdf();"> 打印</button>
<div id="test" class="row">
Hello world!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
</div>
javascript:
ffunction exportpdf(params){
$("#creatImageModal").modal("hide");
var head_str = "<html><head><title></title></head><body><div id='exp'>"; //先生成头部
var foot_str = "</div></body></html>"; //生成尾部
var older = document.body.innerHTML;
var new_str = document.getElementById('test').innerHTML; //获取指定打印区域
var old_str = document.body.innerHTML; //获得原本页面的代码
document.body.innerHTML = head_str + new_str + foot_str; //构建新网页
window.print();
document.body.innerHTML = older; //将网页还原
toolSearch();
return false;
}
ok了,拿走不谢~~~~~