我想打印一个没有按钮显示的特定div。当我使用document.body时,pdf按钮显示在里面。但是当我使用document.getElementById(“customers”)时,我得到的是一个带黑线的pdf。我需要一些帮助,因为我搜索并尝试了许多解决方案,但似乎没有任何效果。 这是我的代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
</head>
<body>
<div id="customers"> <!-- div that contains my table -->
<table id="tab_customers" class="table table-striped">
<colgroup>
<col width="20%">
<col width="20%">
<col width="20%">
<col width="20%">
</colgroup>
<thead>
<tr>
<th>Country</th>
<th>Population</th>
<th>Date</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td>Chinna</td>
<td>1,363,480,000</td>
<td>March 24, 2014</td>
<td>19.1</td>
</tr>
<tr>
<td>India</td>
<td>1,241,900,000</td>
<td>March 24, 2014</td>
<td>17.4</td>
</tr>
</tbody>
</table>
</div>
<input type="button" value="save" onclick="javascript:saveAspdf()"/> <!-- call the js function -->
</body>
</html>
的javascript:
/* js function reffering to jspdf to save a pdf */
function saveAspdf() {
var pdf = new jsPDF('p','pt','a4');
pdf.addHTML(document.getElementById("customers"),function() {
pdf.save('newDoc.pdf');
});
}