将本地主机 PHP 转换为 PDF
Converting Localhost PHP to PDF
我目前有一个主页设置 table 包括用于获取 table 行数据的数组查询,我已经测试了 PhpToPDF 和 TCPDF 但我 运行对于我不知道该怎么做的问题,我的数组限制了我发送数据的选项,但数组依赖于用户登录时,他们的登录用户名为查询提供了从 db 获取所需的信息标准。我也遇到过在本地主机上托管网页的问题。谁能演示如何在单击 Create PDF
时将 table 转换为 pdf 文档?预制免费解决方案
$query = "select * from orders where userid= ' $userid' order by orderid";
$result = mysqli_query($db,$query);
if ($result){
while ($rows = mysqli_fetch_array($result))
{
?>
<tr>
<td> <?php echo $rows[4]; ?> </td>
<td> <?php echo $rows[0]; ?> </td>
<td> <?php echo $rows[1]; ?> </td>
<td> <?php echo $rows[2]; ?> </td>
<td> <?php echo $rows[3]; ?> </td>
<td>
<a href ="deleteorderhomepage.php?receiptid=<?php echo $rows[3]?>&orderid=<?php echo $rows[0]?>">Delete </a>
</td>
</tr>
<?php
if(isset($_POST["create_pdf"])) { }
}
}
?
</table>
</br>
<input type="submit" name="create_pdf" value="Create PDF" />
</div>
</div>
</body>
</html>
通常使用这些库之一 http://www.tcpdf.org/:
这是一个来自 TCPDF pdf 库的例子 link export mysql database table contents on to a PDF file using php:
require('fpdf17/fpdf.php');
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',10);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('times','B',10);
$pdf->Cell(25,7,"Stud ID");
$pdf->Cell(30,7,"Student Name");
$pdf->Cell(40,7,"Address");
$pdf->Cell(30,7,"Class");
$pdf->Cell(30,7,"Phone No");
$pdf->Cell(30,7,"E-mail");
$pdf->Ln();
$pdf->Cell(450,7,"----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
$pdf->Ln();
include ('db.php');
$sql = "SELECT studid,name,address,class,phone,email FROM studinfo";
$result = mysql_query($sql);
while($rows=mysql_fetch_array($result))
{
$studid = $rows[0];
$name = $rows[1];
$address = $rows[2];
$class = $rows[3];
$phone = $rows[4];
$email = $rows[5];
$pdf->Cell(25,7,$studid);
$pdf->Cell(30,7,$name);
$pdf->Cell(40,7,$address);
$pdf->Cell(30,7,$class);
$pdf->Cell(30,7,$phone);
$pdf->Cell(30,7,$email);
$pdf->Ln();
}
$pdf->Output();
你这个非常简单的插件:Datatables
<html>
<head>
<title>Datatables Exmple by LahiruTM</title>
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>
<link href="https://cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.flash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js"></script>
<script>
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
{ extend:'copy', attr: { id: 'allan' } }, 'csv', 'excel', 'pdf', 'print'
]
} );
} );
</script>
</head>
<body>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>0,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>0,750</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>,000</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>Senior Javascript Developer</td>
<td>Edinburgh</td>
<td>22</td>
<td>2012/03/29</td>
<td>3,060</td>
</tr>
<tr>
<td>Airi Satou</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>33</td>
<td>2008/11/28</td>
<td>2,700</td>
</tr>
<tr>
<td>Brielle Williamson</td>
<td>Integration Specialist</td>
<td>New York</td>
<td>61</td>
<td>2012/12/02</td>
<td>2,000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
</body>
</html>
我目前有一个主页设置 table 包括用于获取 table 行数据的数组查询,我已经测试了 PhpToPDF 和 TCPDF 但我 运行对于我不知道该怎么做的问题,我的数组限制了我发送数据的选项,但数组依赖于用户登录时,他们的登录用户名为查询提供了从 db 获取所需的信息标准。我也遇到过在本地主机上托管网页的问题。谁能演示如何在单击 Create PDF
时将 table 转换为 pdf 文档?预制免费解决方案
$query = "select * from orders where userid= ' $userid' order by orderid";
$result = mysqli_query($db,$query);
if ($result){
while ($rows = mysqli_fetch_array($result))
{
?>
<tr>
<td> <?php echo $rows[4]; ?> </td>
<td> <?php echo $rows[0]; ?> </td>
<td> <?php echo $rows[1]; ?> </td>
<td> <?php echo $rows[2]; ?> </td>
<td> <?php echo $rows[3]; ?> </td>
<td>
<a href ="deleteorderhomepage.php?receiptid=<?php echo $rows[3]?>&orderid=<?php echo $rows[0]?>">Delete </a>
</td>
</tr>
<?php
if(isset($_POST["create_pdf"])) { }
}
}
?
</table>
</br>
<input type="submit" name="create_pdf" value="Create PDF" />
</div>
</div>
</body>
</html>
通常使用这些库之一 http://www.tcpdf.org/:
这是一个来自 TCPDF pdf 库的例子 link export mysql database table contents on to a PDF file using php:
require('fpdf17/fpdf.php');
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',10);
$pdf->Ln();
$pdf->Ln();
$pdf->SetFont('times','B',10);
$pdf->Cell(25,7,"Stud ID");
$pdf->Cell(30,7,"Student Name");
$pdf->Cell(40,7,"Address");
$pdf->Cell(30,7,"Class");
$pdf->Cell(30,7,"Phone No");
$pdf->Cell(30,7,"E-mail");
$pdf->Ln();
$pdf->Cell(450,7,"----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
$pdf->Ln();
include ('db.php');
$sql = "SELECT studid,name,address,class,phone,email FROM studinfo";
$result = mysql_query($sql);
while($rows=mysql_fetch_array($result))
{
$studid = $rows[0];
$name = $rows[1];
$address = $rows[2];
$class = $rows[3];
$phone = $rows[4];
$email = $rows[5];
$pdf->Cell(25,7,$studid);
$pdf->Cell(30,7,$name);
$pdf->Cell(40,7,$address);
$pdf->Cell(30,7,$class);
$pdf->Cell(30,7,$phone);
$pdf->Cell(30,7,$email);
$pdf->Ln();
}
$pdf->Output();
你这个非常简单的插件:Datatables
<html>
<head>
<title>Datatables Exmple by LahiruTM</title>
<link href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>
<link href="https://cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.flash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script>
<script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js"></script>
<script>
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons: [
{ extend:'copy', attr: { id: 'allan' } }, 'csv', 'excel', 'pdf', 'print'
]
} );
} );
</script>
</head>
<body>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>0,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>0,750</td>
</tr>
<tr>
<td>Ashton Cox</td>
<td>Junior Technical Author</td>
<td>San Francisco</td>
<td>66</td>
<td>2009/01/12</td>
<td>,000</td>
</tr>
<tr>
<td>Cedric Kelly</td>
<td>Senior Javascript Developer</td>
<td>Edinburgh</td>
<td>22</td>
<td>2012/03/29</td>
<td>3,060</td>
</tr>
<tr>
<td>Airi Satou</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>33</td>
<td>2008/11/28</td>
<td>2,700</td>
</tr>
<tr>
<td>Brielle Williamson</td>
<td>Integration Specialist</td>
<td>New York</td>
<td>61</td>
<td>2012/12/02</td>
<td>2,000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
</body>
</html>