jsPDF 将html代码中的table导出为pdf文件怎么弄

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jsPDF 将html代码中的table导出为pdf文件怎么弄相关的知识,希望对你有一定的参考价值。

jsPDF 将html代码中的table导出为pdf文件怎么弄
Java代码 收藏代码
<html>
<head>
<title>Export html table to excel and csv using jquery</title>
<script src="/jquery-1.9.1.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
<script type="text/javascript" src="/jquery.base64.js"></script>

<script type="text/javascript" src=/tableExport.js"></script>

<script type="text/javascript" src="/jspdf/libs/sprintf.js">
</script>

<script type="text/javascript" src="http://localhost:8082/myphp/tableExport.jquery.plugin-master/jspdf/jspdf.js"></script>
<script type="text/javascript" src="/jspdf/base64.js"></script>

</head>
<body>
[align=right]
<br><br><br>
<button class="btn btn-success" onClick ="$('#customers').tableExport(type: 'excel', escape: 'false');">Excel Export</button>
<button class="btn btn-success" onClick ="$('#customers').tableExport(type: 'pdf', escape: 'false');">CSV Export</button>
<br><br>
[/align]
<table id="customers" class="table table-striped table-bordered" >
<thead>
<tr class='warning'>
<th>Country</th>
<th>Population</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr>
<td>Chinna</td>
<td>1,363,480,000</td>
<td>March 24, 2014</td>
</tr>
<tr>
<td>India</td>
<td>1,241,900,000</td>
<td>March 24, 2014</td>
</tr>
<tr>
<td>United States</td>
<td>317,746,000</td>
<td>March 24, 2014</td>
</tr>
<tr>
<td>Indonesia</td>
<td>249,866,000</td>
<td>July 1, 2013</td>
</tr>
<tr>
<td>Brazil</td>
<td>201,032,714</td>
<td>July 1, 2013</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
参考技术A jsPDF 将html代码中的table导出为pdf文件怎么弄
有如下方法:
1、如果你电脑上安装了office2007/2010,其中的word或EXCEL可以直接保存为PDF格式。
2、如果你电脑上安装安装的是office2003,可以下载安装adobe acrobat,acrobat可以在加载生成PDF的插件。
3、利用任意一款PDF打印机(如pdffactory pro),然后将word文件“打印”成PDF文件。

前端HTML页面转PDF(html2canvas+jspdf)

参考技术A

utils - htmlToPdf.js

main.js

1、如果在多个页面使用,给函数定义一个参数,参数为要导出页面部分的id。

将 \'#pdfDom\' 替换为参数即可
2、将导出文件的名称也作为参数传入函数

此种方式也可用于vue,尝试后可行,需要调节部分参数,但毕竟不太合适。
jQuery不需要调节。

https://github.com/zhangshaoliang/downLoadPDF

vue方式
jQuery方式

目前项目使用的是前端加后端方式,前端提供模板,echarts图表的话需要转为base64发送给后台。后台使用iText。目前存在的问题是后台不支持css3语法,只支持到css2,所以复杂的样式页面显示错乱,考虑个别页面使用纯前端实现。

网站导航

以上是关于jsPDF 将html代码中的table导出为pdf文件怎么弄的主要内容,如果未能解决你的问题,请参考以下文章

Pandas 使用 read_sql_table 的内存过多

pandas

JS实现前端将数据导出excel

使用JS将table表格导出为excel

maven导出项目依赖的jar包

jq怎么把html中的table内的内容导出到excel?