【发布时间】:2016-06-22 03:34:02
【问题描述】:
我正在尝试使用 pdfmake http://pdfmake.org/ 将我的 html 表格转换为 pdf,但我无法了解如何使用
<!DOCTYPE html>
<html>
<?php $pdffile = md5(time()).'.pdf'; ?>
<script src="jquery-1.7.2.min.js" type="text/ecmascript"></script>
<script src="pdfmake.min.js" type="text/javascript"></script>
<script src="vfs_fonts.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(e) {
var table = document.getElementById('table').outerHTML;
var table = document.getElementById('table').innerHTML; // Same response with outerHTML
var table = document.getElementById('table').value; // nothing is happening here
docDefinition = {
content: table
}
pdfMake.createPdf(docDefinition).download('<?php print $pdffile; ?>');
});
</script>
<?php
$con = mysqli_connect('localhost','root','','db');
if($con){
echo 'connected'.'<br/>';
$query = "SELECT * FROM user";
$query_db = mysqli_query($con,$query);
if(mysqli_num_rows($query_db) > 0){
?>
<table cellpadding="0" cellspacing="0" border="1" id="table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<?php while($data = mysqli_fetch_array($query_db)): ?>
<tr>
<td><?php print $data['user_id']; ?></td>
<td><?php print $data['username']; ?></td>
<td><?php print $data['email']; ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php
}else echo 'not data';
}else echo 'error';
?>
</html>
从我发布的代码中,我在我的 pdf 文件中获得了 html 代码而不是 html 表格,抱歉,我不擅长 javascript?
【问题讨论】:
-
我们需要的信息远不止这些。您能否尝试重新解释您看到和期望的输出?目前,它没有多大意义。
-
devdonkey 创建 pdf 时获取的代码不是表格
标签: javascript php pdf pdfmake