javascript - 将表格从 HTML 导出为 PDF
问题描述
我有一张表,我想将数据导出为 pdf。我正在尝试通过使用 jquery 来实现这一点。我已经安装了所有库文件。我的代码有什么问题或者我错过了任何库文件
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="description" content="" />
<meta name="classification" content="" />
<!-- BOOTSTRAP CORE STYLE -->
<link href="assets/css/bootstrap.css" rel="stylesheet" />
<script>
$(document).ready(function(e){
$("#pdf").click(function(e){
$("#tablepdf").tableExport({
type:'pdf',
escape:'false'
});
});
});
</script>
</head>
<body>
<h2>Export Data to pdf with PHP and MySQL</h2>
<button type="submit" id="pdf" class="btn btn-info">Export to pdf</button>
<table id="tablepdf" class="table table-striped table-bordered">
<tr>
<th>Name</th>
<th>Gender</th>
<th>Age</th>
<th>Designation</th>
<th>Address</th>
</tr>
<tr>
<th>Name</th>
<th>Gender</th>
<th>Age</th>
<th>Designation</th>
<th>Address</th>
</tr>
<tr>
<th>Name</th>
<th>Gender</th>
<th>Age</th>
<th>Designation</th>
<th>Address</th>
</tr>
<tr>
<th>Name</th>
<th>Gender</th>
<th>Age</th>
<th>Designation</th>
<th>Address</th>
</tr>
</table>
</div>
</body>
<!-- FOOTER SECTION END-->
<!-- JAVASCRIPT FILES PLACED AT THE BOTTOM TO REDUCE THE LOADING TIME -->
<!-- CORE JQUERY -->
<script src="assets/js/jquery-1.10.2.js"></script>
<script src="assets/js/tableExport.js"></script>
<script src="assets/js/jquery.base64.js"></script>
<!-- BOOTSTRAP SCRIPTS -->
<script src="assets/js/bootstrap.js"></script>
<!-- CUSTOM SCRIPTS -->
<script src="assets/js/custom.js"></script>
<!-- For PDF-->
<script src="assets/js/jspdf/jspdf.js"></script>
<script src="assets/js/jspdf/libs/sprintf.js"></script>
<script src="assets/js/jspdf/libs/base64.js"></script><!-- This templates was made by Colorlib (https://colorlib.com) -->
</html>
当我单击按钮时,它没有给出任何反应所需的库文件已经安装。
解决方案
我遇到了同样的问题,所以我只留下了 jquery 并使用了这个:
https://github.com/spipu/html2pdf
它使用起来非常简单,您可以将整个外观修改为 pdf 文件。
推荐阅读
- php - 如果刀片中的连接表中有 user_id 字段,如何获取用户名
- java - 压缩子目录是只压缩子目录的内容,而不是子目录
- laravel - laravel-5.8:在 laravel 中显示更改格式的日期
- python - 在 PyQt 应用程序中将 reactor.run() 放在哪里?
- javascript - Heroku Node.js 应用程序拒绝应用样式,因为它的 MIME 类型
- rust - Rust std::net::UdpSocket 没有名为 recv_from 的方法
- python - 在 python 中使用 mplot3d 绘制透明平面
- java - 如何在不删除配置单元表的情况下基于 DataFrame 从 SparkSQL 更改表,例如删除/添加列?
- text - 如何将文本转换为 MOA 实例?
- c# - 如何使用查询过滤SSRS中的数据?