导出为PDF文件
html代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>pdf加水印</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<style>
* {
padding: 0;
margin: 0;
}
body {
font: 14px/24px "微软雅黑";
}
.wrap {
background: #fff;
width: 1100px;
padding: 50px;
margin: 0 auto;
}
.container {
border-top: 1px solid #797979;
padding-top: 36px;
}
.h2Title {
font-size: 18px;
line-height: 24px;
margin-bottom: 20px;
}
.table_list_box {
margin-bottom: 40px;
}
.table_box {
border: 1px solid #797979;
width: 100%;
margin-bottom: 10px;
}
.table_box td {
border: 1px solid #797979;
text-align: center;
padding: 5px;
line-height: 20px;
word-break: break-word;
width: 10%;
}
</style>
</head>
<body>
<span id="exportBtn">导出</span>
<div id="wrap" class="wrap">
<div class="container">
<div class="table_list_box">
<h2 class="h2Title">附:xx市交易明细表 </h2>
<table class="table_box" border="1" cellspacing="0" cellpadding="0">
<tr>
<td rowspan="11">出口企业01</td>
</tr>
<tr>
<th>NO.</th>
<th>采购商名称</th>
<th>产品</th>
<th>贸易次数</th>
<th>总尺柜</th>
<th>尺柜占比</th>
<th>重量(T)</th>
<th>重量比例</th>
<th>最近交易时间</th>
</tr>
<tr>
<td>1</td>
<td>TIMELINK</td>
<td>AIRLINK cc</td>
<td>12</td>
<td>16</td>
<td>65</td>
<td>32</td>
<td>5%</td>
<td>2017-02-22</td>
</tr>
<tr>
<td>合计</td>
<td>共8家</td>
<td></td>
<td>共:96</td>
<td>共:xxx</td>
<td>共:xxx%</td>
<td>共:xxx</td>
<td>共:xxx%</td>
<td>2017-02-22</td>
</tr>
</table>
</div>
</div>
<!--可以为原页面加入公章或水印-->
<img src="./screenshot.png" alt="" id="img" style="width: 100px;height: 100px;float: right;display: none;" />
</div>
<script src="js/jquery.min.js"></script>
<script src="js/html2canvas.js"></script>
<script src="js/jspdf.min.js"></script>
<script type="text/javascript">
$("#img").hide()
$(function() {
var display = document.querySelector("#img");
$(document).on('click', '#exportBtn', function() {
display.style.display = "block";
var pdf = new jsPDF('p', 'pt', 'a4');
pdf.internal.scaleFactor = 1; //可以调整缩放比例
var options = {
//pagesplit: true //分页
pagesplit: false //不分页
};
pdf.addHTML($('.wrap').get(0), 0, 0, options, function() {
pdf.save($('title').text() + '.pdf');
display.style.display = "none";
});
});
})
</script>
</body>
</html>
注意:引入正确的js文件路径。