【发布时间】:2014-08-14 01:35:25
【问题描述】:
我正在尝试使用 jsPDF 的 fromHTML 函数将 html 表格转换为 pdf。这在大多数情况下都有效,但是对于我的一个屏幕,表格被错误地添加了。 Here 是在屏幕上显示输入、输出以及从屏幕另一部分正确生成的输出的图像。
这是表格的 HTML:
<table class="table table-condensed">
<thead>
<tr>
<th></th>
<th>{{ report.leftHeader }}</th>
<th>{{ report.rightHeader }}</th>
<th>Difference</th>
</tr>
</thead>
<tbody id="tableBody">
<tr ng-repeat="metric in report.leftMetrics">
<td>{{ metric.label }}</td>
<td ng-switch="metric.leftEditable && !printerFriendly">
<input ng-switch-when="true" ng-model="metric.leftValue" ng-change="report.updateComputedValues(metric);" min="0" required />
<span ng-switch-default>{{ metric.leftValue | numberFormat : metric.dataType }}</span>
</td>
<td ng-switch="metric.rightEditable && !printerFriendly">
<input ng-switch-when="true" ng-model="metric.rightValue" ng-change="report.updateComputedValues(metric)" min="0" required />
<span ng-switch-default>{{ metric.rightValue | numberFormat : metric.dataType }}</span>
</td>
<td>{{ metric.rightValue - metric.leftValue | zeroDifference | numberFormat : metric.dataType }}</td>
</tr>
</tbody>
</table>
为了帮助那些不了解 angular 的人了解正在发生的事情,该表为 leftMetrics 数组中的每个值添加了一个正文行,并且在每一行中,如果它是可编辑的,则将显示一个输入框或一个跨度如果只读或打印为 pdf。 " | numberFormat..." 是一个角度过滤器,它只是将值的显示更改为货币、小数、整数等。
如您所见,跨度内没有换行符,但出于某种原因,jsPDF 正在添加它们。我尝试删除过滤器以确保它们不会添加中断,但这没有改变。我一直在查看函数的源代码,也看不到任何会增加中断的东西。有没有人以前见过这个问题,或者对我应该在哪里找到解决这个问题的方法有任何线索?
【问题讨论】:
标签: javascript html angularjs jspdf