保存样式'导出到pdf'html表
Keep styles of an 'exported to pdf' html table
在我的MVC项目我有以下html表:
<div id="tableToPrint">
<table border="0" id="tbl" cellspacing="25">
<tr class="te">
<th align="left">DATE</th>
<th align="left">METHOD</th>
<th align="left">DEPOSIT</th>
<th align="left">WITHDRAWAL</th>
</tr>
<!-- ko foreach: accountInfo -->
<tr>
<td valign="top"><span data-bind="text: moment(new Date(orderDate())).format('MM/DD/YYYY')"></span></td>
<td valign="top"><span data-bind="text: type"></span> </td>
<td class="deposit" valign="top"><span data-bind="text: $root.formatCurrency(deposit())" id="deposit"></span></td>
<td valign="top"><span data-bind="text: $root.formatCurrency(withdrawal())"></span> </td>
</tr>
<!-- /ko -->
<tr class="last">
<td valign="top"> </td>
<td valign="top"> </td>
<td valign="top"><span data-bind="text: $root.totalDeposit()"></span></td>
<td valign="top"><span data-bind="text: $root.totalWithdrawal()"></span></td>
</tr>
</table>
</div>
我有一个按钮'导出到PDF',工作正常,但失去了设计,它导出没有所有的样式。
这是使用jspdf库将表导出为pdf的javascript代码:
self.exportToPdf = function () {
var newPdf = new jsPDF();
var specialElementHandlers = {
'#tableToPrint': function (element, renderer) {
return true;
}
};
// newPdf.setFontSize(16);
var html = $("#tableToPrint").html();
var margins = {
top: 80,
bottom: 60,
left: 40,
width: 522
};
newPdf.fromHTML(
html, // 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
});
newPdf.save("YourTable.pdf");
}
是否有办法在导出的pdf中保持表的原始设计?或者至少通过javascript代码将表导出为pdf来设计它?
这就解决了我的问题:
self.exportToPdf = function () {
var pdf = new jsPDF('p', 'pt', 'letter');
source = $('#tableToPrint')[0];
specialElementHandlers = {
'#bypassme': function (element, renderer) {
return true
}
};
margins = {
top: 80,
bottom: 60,
left: 40,
width: 522
};
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('YourTable.pdf');
}, margins
);
}
相关文章:
- 如何使用javascript或html下载PDF格式的填写表单
- 在提交时打开thankyou.html+下载PDF
- 生成pdf或其他非html文件时的错误处理
- how to convert html <div> to pdf
- 如何在使用jsPDF将html转换为pdf的同时,在pdf中的某个点进行分页
- 如何将带有大量svg图表的html转换为pdf
- 将php页面的一个部分渲染为HTML和CSS后生成PDF,并考虑PDF分页符
- 如何使用javascript或jquery将整个html页面转换为pdf
- 如果iframe在src(pdf或text)中有非html文档,则iframe中的onload不起作用
- HTML表格导出为具有适当列宽和字体的pdf
- 具有可拖动元素的HTML到PDF
- c# mvc nreco HtmlToPdfConverter 问题将 html 文档转换为 pdf
- 来自HTML图像的jsPDF 会导致 pdf 为空
- 使用 php 将 pdf 文件转换为 html 文件
- HTML到PDF的转换仅在客户端使用JavaScript
- 从横向格式的HTML页面制作PDF
- 使用TableExport.js将HTML表格导出为PDF、WORD、PNG
- HTML和CSS转换为JavaScript中的PDF
- JQuery-HTML到PDF没有'无法在IE中工作(来自C#asmx Web服务)
- 保存样式'导出到pdf'html表