将localhost php转换为pdf

ncecgwcz  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(338)

我目前有一个主页设置了一个表,包括获取表行数据的数组查询,我测试了phptopdf和tcpdf,但我遇到了一个问题,我不知道该做什么,我的数组限制了我发送数据访问的选项,但数组依赖于用户登录时,他们的登录用户名为查询提供从数据库获取所需的信息条件。我还谈到了网页在localhost上托管的问题。有人能演示一下如何将表格转换成pdf文档吗 Create 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>
k5ifujac

k5ifujac1#

您可以使用这个非常简单的插件: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>$320,800</td>
        </tr>
        <tr>
            <td>Garrett Winters</td>
            <td>Accountant</td>
            <td>Tokyo</td>
            <td>63</td>
            <td>2011/07/25</td>
            <td>$170,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>$86,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>$433,060</td>
        </tr>
        <tr>
            <td>Airi Satou</td>
            <td>Accountant</td>
            <td>Tokyo</td>
            <td>33</td>
            <td>2008/11/28</td>
            <td>$162,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>$372,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>
nzk0hqpo

nzk0hqpo2#

通常使用这些库中的一个http://www.tcpdf.org/:
fpdf公司
tcpdf格式
ezpdf格式
这是一个来自tcpdf库的示例,它使用php将mysql数据库表内容导出到pdf文件:

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();

相关问题