【发布时间】:2016-02-25 03:02:13
【问题描述】:
我正在尝试使用 jsPDF 将 HTML 表格导出为 PDF,但我遇到了列重叠问题。我必须跳过一些列,但不知道该怎么做。
这是我的桌子:
<div class="wrapper wrapper-content">
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<a class="btn btn-primary btn-xs pull-right m-r-xs" ng-click="toPDF()">PDF çıktısı al</a>
<a class="btn btn-primary btn-xs pull-right m-r-xs" ng-click="toExcel()">Excel çıktısı al</a>
<div class="ibox-content" id="table">
<table id="archiveTable" class="table table-responsive table-hover">
<thead>
<tr>
<th id="bypassme" class="text-center noExl">Şüpheli</th>
<th width="20">No</th>
<th>Plaka</th>
<th>Ad</th>
<th>Plaka Noktası</th>
<th>Sahip Türü</th>
<th>Tarih</th>
</tr>
</thead>
<tbody>
<tr class="clickable" ng-repeat="data in archivedata" ng-click="showArchiveDetails(data)">
<td ng-class="{'text-danger': data.dangerous}" class="text-center noExl">
<span ng-if="data.dangerous" tooltip="Şüpheli"><i class="fa fa-exclamation-circle"></i></span>
</td>
<td>{{(shownCurrentPage-1)*resultsPerPage + $index + 1}}</td>
<td>{{data.plate}}</td>
<td>{{people[data.ownerType][data.ownerId].name}}</td>
<td>{{data.platePoints.pointName}}</td>
<td ng-switch="data.ownerType">
<span ng-switch-when="1">{{labels.resident}}</span>
<strong ng-switch-when="2">{{labels.guest}}</strong>
<span ng-switch-when="3">Tanınmayan</span>
<span ng-switch-when="4">Düzenli Ziyaretçi</span>
</td>
<td>{{data.lprDate | date:'dd/MM/yyyy HH:mm'}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
这里是 Javascript 代码:
$scope.toPDF = function(){
var from = $filter('date')($scope.archive.from,'dd.MM.yyyy HH.mm');
var to = $filter('date')($scope.archive.to,'dd.MM.yyyy HH.mm');
var filename = "Arşiv - " + from + " - " + to + ".pdf";
var pdf = new jsPDF('p', 'pt', 'letter');
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = $('#table')[0];
// we support special element handlers. Register them with jQuery-style
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors
// (class, of compound) at this time.
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
margins = {
top: 80,
bottom: 60,
left: 40,
width: 522
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.fromHTML(
source, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, { // y coord
'width': margins.width, // max width of content on PDF
'elementHandlers': specialElementHandlers
},
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(filename);
}, margins);
};
我希望在导出时跳过名为“Şüpheli”的列,因为没有可供打印的文本。
虽然对于此表,最好在该列中放置适当的文本而不是图标,但对于其他表中的某些列,我仍然需要此忽略功能。
谢谢。
【问题讨论】:
标签: javascript html jspdf